diff options
author | Divy Srivastava <dj.srivastava23@gmail.com> | 2022-11-11 06:37:18 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-11 20:07:18 +0530 |
commit | 38f0b41e7d16db24c1ba7c7cc7b536f4d7e169e9 (patch) | |
tree | c8688f12f5808bd78f03c9c3ad2d078e974aa185 /ops/lib.rs | |
parent | 5b9620df7ac655449abd2cce5292bd4669b1f211 (diff) |
perf(web): optimize single pass utf8 decoding (#16593)
- [x] Avoid copying buffers.
https://encoding.spec.whatwg.org/#dom-textdecoder-decode
> Implementations are strongly encouraged to use an implementation
strategy that avoids this copy. When doing so they will have to make
sure that changes to input do not affect future calls to
[decode()](https://encoding.spec.whatwg.org/#dom-textdecoder-decode).
- [x] Special op to avoid string label deserialization and parsing.
(Ideally we should map labels to integers in JS)
- [x] Avoid webidl `Object.assign` when options is undefined.
Diffstat (limited to 'ops/lib.rs')
-rw-r--r-- | ops/lib.rs | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/ops/lib.rs b/ops/lib.rs index 298327af2..d295ec9bd 100644 --- a/ops/lib.rs +++ b/ops/lib.rs @@ -449,13 +449,16 @@ fn codegen_u8_slice(core: &TokenStream2, idx: usize) -> TokenStream2 { let value = args.get(#idx as i32); match #core::v8::Local::<#core::v8::ArrayBuffer>::try_from(value) { Ok(b) => { + // Handles detached buffers. + let byte_length = b.byte_length(); let store = b.data() as *mut u8; // SAFETY: rust guarantees that lifetime of slice is no longer than the call. - unsafe { ::std::slice::from_raw_parts_mut(store, b.byte_length()) } + unsafe { ::std::slice::from_raw_parts_mut(store, byte_length) } }, Err(_) => { if let Ok(view) = #core::v8::Local::<#core::v8::ArrayBufferView>::try_from(value) { - let (offset, len) = (view.byte_offset(), view.byte_length()); + let len = view.byte_length(); + let offset = view.byte_offset(); let buffer = match view.buffer(scope) { Some(v) => v, None => { |