Skip to content

Commit c87181e

Browse files
committed
Change to copy function in read_region (#730)
On behalf of @slave5vw
1 parent 9400c62 commit c87181e

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

packages/vm/src/memory.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::ptr;
12
use wasmer::{Array, ValueType, WasmPtr};
23

34
use crate::conversion::to_u32;
@@ -39,12 +40,11 @@ pub fn read_region(memory: &wasmer::Memory, ptr: u32, max_length: usize) -> VmRe
3940

4041
match WasmPtr::<u8, Array>::new(region.offset).deref(memory, 0, region.length) {
4142
Some(cells) => {
42-
// In case you want to do some premature optimization, this shows how to cast a `&'mut [Cell<u8>]` to `&mut [u8]`:
43-
// https://github.com/wasmerio/wasmer/blob/0.13.1/lib/wasi/src/syscalls/mod.rs#L79-L81
43+
let raw_cells = cells as *const [_] as *const u8;
4444
let len = region.length as usize;
4545
let mut result = vec![0u8; len];
46-
for i in 0..len {
47-
result[i] = cells[i].get();
46+
unsafe{
47+
ptr::copy(raw_cells, result.as_mut_ptr(), len);
4848
}
4949
Ok(result)
5050
}

0 commit comments

Comments
 (0)