Skip to content

Commit

Permalink
Merge pull request #3590 from rlane/memory-view
Browse files Browse the repository at this point in the history
Optimize getting byteLength in MemoryView::new
  • Loading branch information
syrusakbary authored Feb 18, 2023
2 parents 73d6c48 + b5f2888 commit 8696abd
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/api/src/js/externals/memory_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::mem::MaybeUninit;
use std::slice;
#[cfg(feature = "tracing")]
use tracing::warn;
use wasm_bindgen::JsCast;

use wasmer_types::{Bytes, Pages};

Expand Down Expand Up @@ -33,10 +34,11 @@ impl<'a> MemoryView<'a> {
pub(crate) fn new_raw(memory: &js_sys::WebAssembly::Memory) -> Self {
let buffer = memory.buffer();

let size = js_sys::Reflect::get(&buffer, &"byteLength".into())
.unwrap()
.as_f64()
.unwrap() as u64;
// This also works for SharedArrayBuffer.
let size = buffer
.unchecked_ref::<js_sys::ArrayBuffer>()
.byte_length()
.into();

let view = js_sys::Uint8Array::new(&buffer);

Expand Down

0 comments on commit 8696abd

Please sign in to comment.