Skip to content

Commit

Permalink
Remove unnecessary allocations when crossing WASM FFI boundary (parit…
Browse files Browse the repository at this point in the history
  • Loading branch information
koute authored and ark0f committed Feb 27, 2023
1 parent 332cf2d commit a7b754a
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions primitives/runtime-interface/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,8 @@ macro_rules! impl_traits_for_arrays {
type SelfInstance = [u8; $n];

fn from_ffi_value(context: &mut dyn FunctionContext, arg: u32) -> Result<[u8; $n]> {
let data = context.read_memory(Pointer::new(arg), $n)?;
let mut res = [0u8; $n];
res.copy_from_slice(&data);
context.read_memory_into(Pointer::new(arg), &mut res)?;
Ok(res)
}
}
Expand Down Expand Up @@ -514,10 +513,8 @@ macro_rules! for_u128_i128 {
type SelfInstance = $type;

fn from_ffi_value(context: &mut dyn FunctionContext, arg: u32) -> Result<$type> {
let data =
context.read_memory(Pointer::new(arg), mem::size_of::<$type>() as u32)?;
let mut res = [0u8; mem::size_of::<$type>()];
res.copy_from_slice(&data);
context.read_memory_into(Pointer::new(arg), &mut res)?;
Ok(<$type>::from_le_bytes(res))
}
}
Expand Down

0 comments on commit a7b754a

Please sign in to comment.