diff options
author | Divy Srivastava <dj.srivastava23@gmail.com> | 2022-03-27 13:10:54 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-27 13:10:54 +0530 |
commit | b18216a0d4d26a6dc982801638aa61511f629a14 (patch) | |
tree | e50f870e1025c3b41e7c397ef2247632fd4ff0cf /core | |
parent | 37b0ec454cb45f10fbcb14273c663cb55b40d209 (diff) |
perf: micro-optimize core.encode (#14120)
Diffstat (limited to 'core')
-rw-r--r-- | core/bindings.rs | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/core/bindings.rs b/core/bindings.rs index 91087799a..c4555459c 100644 --- a/core/bindings.rs +++ b/core/bindings.rs @@ -864,9 +864,13 @@ fn encode( } }; let text_str = text.to_rust_string_lossy(scope); - let zbuf: ZeroCopyBuf = text_str.into_bytes().into(); - - rv.set(to_v8(scope, zbuf).unwrap()) + let bytes: Box<[u8]> = text_str.into_bytes().into_boxed_slice(); + let len = bytes.len(); + let backing_store = + v8::ArrayBuffer::new_backing_store_from_boxed_slice(bytes).make_shared(); + let buffer = v8::ArrayBuffer::with_backing_store(scope, &backing_store); + let u8array = v8::Uint8Array::new(scope, buffer, 0, len).unwrap(); + rv.set(u8array.into()) } fn decode( |