Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize getting byteLength in MemoryView::new #3590

Merged
merged 1 commit into from
Feb 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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