Skip to content
Snippets Groups Projects
Commit 8c2216c8 authored by Koute's avatar Koute Committed by GitHub
Browse files

Remove unnecessary allocations when crossing WASM FFI boundary (#10191)

parent 6b9d1176
No related merge requests found
...@@ -318,9 +318,8 @@ macro_rules! impl_traits_for_arrays { ...@@ -318,9 +318,8 @@ macro_rules! impl_traits_for_arrays {
type SelfInstance = [u8; $n]; type SelfInstance = [u8; $n];
fn from_ffi_value(context: &mut dyn FunctionContext, arg: u32) -> Result<[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]; let mut res = [0u8; $n];
res.copy_from_slice(&data); context.read_memory_into(Pointer::new(arg), &mut res)?;
Ok(res) Ok(res)
} }
} }
...@@ -514,10 +513,8 @@ macro_rules! for_u128_i128 { ...@@ -514,10 +513,8 @@ macro_rules! for_u128_i128 {
type SelfInstance = $type; type SelfInstance = $type;
fn from_ffi_value(context: &mut dyn FunctionContext, arg: u32) -> Result<$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>()]; 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)) Ok(<$type>::from_le_bytes(res))
} }
} }
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment