from_little_endian use slice instead of vec.
This commit is contained in:
parent
69b9a7753c
commit
65a339847a
|
@ -544,7 +544,7 @@ impl<'a, E: Externals> Interpreter<'a, E> {
|
||||||
.memory_by_index(DEFAULT_MEMORY_INDEX)
|
.memory_by_index(DEFAULT_MEMORY_INDEX)
|
||||||
.expect("Due to validation memory should exists");
|
.expect("Due to validation memory should exists");
|
||||||
let b = m.get(address, mem::size_of::<T>())?;
|
let b = m.get(address, mem::size_of::<T>())?;
|
||||||
let n = T::from_little_endian(b)?;
|
let n = T::from_little_endian(&b)?;
|
||||||
context.value_stack_mut().push(n.into())?;
|
context.value_stack_mut().push(n.into())?;
|
||||||
Ok(InstructionOutcome::RunNextInstruction)
|
Ok(InstructionOutcome::RunNextInstruction)
|
||||||
}
|
}
|
||||||
|
@ -561,7 +561,7 @@ impl<'a, E: Externals> Interpreter<'a, E> {
|
||||||
.memory_by_index(DEFAULT_MEMORY_INDEX)
|
.memory_by_index(DEFAULT_MEMORY_INDEX)
|
||||||
.expect("Due to validation memory should exists");
|
.expect("Due to validation memory should exists");
|
||||||
let b = m.get(address, mem::size_of::<T>())?;
|
let b = m.get(address, mem::size_of::<T>())?;
|
||||||
let v = T::from_little_endian(b)?;
|
let v = T::from_little_endian(&b)?;
|
||||||
let stack_value: U = v.extend_into();
|
let stack_value: U = v.extend_into();
|
||||||
context
|
context
|
||||||
.value_stack_mut()
|
.value_stack_mut()
|
||||||
|
|
20
src/value.rs
20
src/value.rs
|
@ -53,7 +53,7 @@ pub trait LittleEndianConvert where Self: Sized {
|
||||||
/// Convert to little endian buffer.
|
/// Convert to little endian buffer.
|
||||||
fn into_little_endian(self) -> Vec<u8>;
|
fn into_little_endian(self) -> Vec<u8>;
|
||||||
/// Convert from little endian buffer.
|
/// Convert from little endian buffer.
|
||||||
fn from_little_endian(buffer: Vec<u8>) -> Result<Self, Error>;
|
fn from_little_endian(buffer: &[u8]) -> Result<Self, Error>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Arithmetic operations.
|
/// Arithmetic operations.
|
||||||
|
@ -376,7 +376,7 @@ impl LittleEndianConvert for i8 {
|
||||||
vec![self as u8]
|
vec![self as u8]
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_little_endian(buffer: Vec<u8>) -> Result<Self, Error> {
|
fn from_little_endian(buffer: &[u8]) -> Result<Self, Error> {
|
||||||
buffer.get(0)
|
buffer.get(0)
|
||||||
.map(|v| *v as i8)
|
.map(|v| *v as i8)
|
||||||
.ok_or_else(|| Error::Value("invalid little endian buffer".into()))
|
.ok_or_else(|| Error::Value("invalid little endian buffer".into()))
|
||||||
|
@ -388,7 +388,7 @@ impl LittleEndianConvert for u8 {
|
||||||
vec![self]
|
vec![self]
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_little_endian(buffer: Vec<u8>) -> Result<Self, Error> {
|
fn from_little_endian(buffer: &[u8]) -> Result<Self, Error> {
|
||||||
buffer.get(0)
|
buffer.get(0)
|
||||||
.cloned()
|
.cloned()
|
||||||
.ok_or_else(|| Error::Value("invalid little endian buffer".into()))
|
.ok_or_else(|| Error::Value("invalid little endian buffer".into()))
|
||||||
|
@ -403,7 +403,7 @@ impl LittleEndianConvert for i16 {
|
||||||
vec
|
vec
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_little_endian(buffer: Vec<u8>) -> Result<Self, Error> {
|
fn from_little_endian(buffer: &[u8]) -> Result<Self, Error> {
|
||||||
io::Cursor::new(buffer).read_i16::<LittleEndian>()
|
io::Cursor::new(buffer).read_i16::<LittleEndian>()
|
||||||
.map_err(|e| Error::Value(e.to_string()))
|
.map_err(|e| Error::Value(e.to_string()))
|
||||||
}
|
}
|
||||||
|
@ -417,7 +417,7 @@ impl LittleEndianConvert for u16 {
|
||||||
vec
|
vec
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_little_endian(buffer: Vec<u8>) -> Result<Self, Error> {
|
fn from_little_endian(buffer: &[u8]) -> Result<Self, Error> {
|
||||||
io::Cursor::new(buffer).read_u16::<LittleEndian>()
|
io::Cursor::new(buffer).read_u16::<LittleEndian>()
|
||||||
.map_err(|e| Error::Value(e.to_string()))
|
.map_err(|e| Error::Value(e.to_string()))
|
||||||
}
|
}
|
||||||
|
@ -431,7 +431,7 @@ impl LittleEndianConvert for i32 {
|
||||||
vec
|
vec
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_little_endian(buffer: Vec<u8>) -> Result<Self, Error> {
|
fn from_little_endian(buffer: &[u8]) -> Result<Self, Error> {
|
||||||
io::Cursor::new(buffer).read_i32::<LittleEndian>()
|
io::Cursor::new(buffer).read_i32::<LittleEndian>()
|
||||||
.map_err(|e| Error::Value(e.to_string()))
|
.map_err(|e| Error::Value(e.to_string()))
|
||||||
}
|
}
|
||||||
|
@ -445,7 +445,7 @@ impl LittleEndianConvert for u32 {
|
||||||
vec
|
vec
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_little_endian(buffer: Vec<u8>) -> Result<Self, Error> {
|
fn from_little_endian(buffer: &[u8]) -> Result<Self, Error> {
|
||||||
io::Cursor::new(buffer).read_u32::<LittleEndian>()
|
io::Cursor::new(buffer).read_u32::<LittleEndian>()
|
||||||
.map_err(|e| Error::Value(e.to_string()))
|
.map_err(|e| Error::Value(e.to_string()))
|
||||||
}
|
}
|
||||||
|
@ -459,7 +459,7 @@ impl LittleEndianConvert for i64 {
|
||||||
vec
|
vec
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_little_endian(buffer: Vec<u8>) -> Result<Self, Error> {
|
fn from_little_endian(buffer: &[u8]) -> Result<Self, Error> {
|
||||||
io::Cursor::new(buffer).read_i64::<LittleEndian>()
|
io::Cursor::new(buffer).read_i64::<LittleEndian>()
|
||||||
.map_err(|e| Error::Value(e.to_string()))
|
.map_err(|e| Error::Value(e.to_string()))
|
||||||
}
|
}
|
||||||
|
@ -473,7 +473,7 @@ impl LittleEndianConvert for f32 {
|
||||||
vec
|
vec
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_little_endian(buffer: Vec<u8>) -> Result<Self, Error> {
|
fn from_little_endian(buffer: &[u8]) -> Result<Self, Error> {
|
||||||
io::Cursor::new(buffer).read_u32::<LittleEndian>()
|
io::Cursor::new(buffer).read_u32::<LittleEndian>()
|
||||||
.map(f32_from_bits)
|
.map(f32_from_bits)
|
||||||
.map_err(|e| Error::Value(e.to_string()))
|
.map_err(|e| Error::Value(e.to_string()))
|
||||||
|
@ -488,7 +488,7 @@ impl LittleEndianConvert for f64 {
|
||||||
vec
|
vec
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_little_endian(buffer: Vec<u8>) -> Result<Self, Error> {
|
fn from_little_endian(buffer: &[u8]) -> Result<Self, Error> {
|
||||||
io::Cursor::new(buffer).read_u64::<LittleEndian>()
|
io::Cursor::new(buffer).read_u64::<LittleEndian>()
|
||||||
.map(f64_from_bits)
|
.map(f64_from_bits)
|
||||||
.map_err(|e| Error::Value(e.to_string()))
|
.map_err(|e| Error::Value(e.to_string()))
|
||||||
|
|
Loading…
Reference in New Issue