mirror of
https://github.com/denoland/deno.git
synced 2024-11-25 15:29:32 -05:00
perf(serde_v8): serde_v8::StringOrBuffer
return JS ArrayBuffer instead of Uint8Array (#16360)
Towards #16315
This commit is contained in:
parent
d3736f12b5
commit
bfc1fb8d68
2 changed files with 19 additions and 2 deletions
|
@ -440,7 +440,7 @@
|
|||
if (this.binaryType === "blob") {
|
||||
data = new Blob([value]);
|
||||
} else {
|
||||
data = value.buffer;
|
||||
data = value;
|
||||
}
|
||||
|
||||
const event = new MessageEvent("message", {
|
||||
|
|
|
@ -29,7 +29,24 @@ impl ToV8 for StringOrBuffer {
|
|||
scope: &mut v8::HandleScope<'a>,
|
||||
) -> Result<v8::Local<'a, v8::Value>, crate::Error> {
|
||||
match self {
|
||||
Self::Buffer(buf) => crate::to_v8(scope, buf),
|
||||
Self::Buffer(buf) => {
|
||||
let buf: Box<[u8]> = match buf {
|
||||
ZeroCopyBuf::FromV8(buf) => {
|
||||
let value: &[u8] = buf;
|
||||
value.into()
|
||||
}
|
||||
ZeroCopyBuf::Temp(_) => unreachable!(),
|
||||
ZeroCopyBuf::ToV8(ref mut x) => {
|
||||
x.take().expect("ZeroCopyBuf was empty")
|
||||
}
|
||||
};
|
||||
let backing_store =
|
||||
v8::ArrayBuffer::new_backing_store_from_boxed_slice(buf);
|
||||
Ok(
|
||||
v8::ArrayBuffer::with_backing_store(scope, &backing_store.into())
|
||||
.into(),
|
||||
)
|
||||
}
|
||||
Self::String(s) => crate::to_v8(scope, s),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue