mirror of
https://github.com/denoland/deno.git
synced 2025-01-09 07:39:15 -05:00
perf(serde_v8): remove Mutex from ZeroCopyBuf (#15888)
This commit is contained in:
parent
b4e618315a
commit
51ba4764d1
1 changed files with 7 additions and 14 deletions
|
@ -3,7 +3,6 @@
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
use std::ops::DerefMut;
|
use std::ops::DerefMut;
|
||||||
use std::sync::Mutex;
|
|
||||||
|
|
||||||
use super::transl8::FromV8;
|
use super::transl8::FromV8;
|
||||||
use super::transl8::ToV8;
|
use super::transl8::ToV8;
|
||||||
|
@ -14,7 +13,7 @@ use crate::magic::transl8::impl_magic;
|
||||||
// allowing us to use a single type for familiarity
|
// allowing us to use a single type for familiarity
|
||||||
pub enum ZeroCopyBuf {
|
pub enum ZeroCopyBuf {
|
||||||
FromV8(V8Slice),
|
FromV8(V8Slice),
|
||||||
ToV8(Mutex<Option<Box<[u8]>>>),
|
ToV8(Option<Box<[u8]>>),
|
||||||
// Variant of the ZeroCopyBuf than is never exposed to the JS.
|
// Variant of the ZeroCopyBuf than is never exposed to the JS.
|
||||||
// Generally used to pass Vec<u8> backed buffers to resource methods.
|
// Generally used to pass Vec<u8> backed buffers to resource methods.
|
||||||
Temp(Vec<u8>),
|
Temp(Vec<u8>),
|
||||||
|
@ -30,7 +29,7 @@ impl Debug for ZeroCopyBuf {
|
||||||
|
|
||||||
impl ZeroCopyBuf {
|
impl ZeroCopyBuf {
|
||||||
pub fn empty() -> Self {
|
pub fn empty() -> Self {
|
||||||
ZeroCopyBuf::ToV8(Mutex::new(Some(vec![0_u8; 0].into_boxed_slice())))
|
ZeroCopyBuf::ToV8(Some(vec![0_u8; 0].into_boxed_slice()))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_temp(vec: Vec<u8>) -> Self {
|
pub fn new_temp(vec: Vec<u8>) -> Self {
|
||||||
|
@ -91,7 +90,7 @@ impl DerefMut for ZeroCopyBuf {
|
||||||
|
|
||||||
impl From<Box<[u8]>> for ZeroCopyBuf {
|
impl From<Box<[u8]>> for ZeroCopyBuf {
|
||||||
fn from(buf: Box<[u8]>) -> Self {
|
fn from(buf: Box<[u8]>) -> Self {
|
||||||
ZeroCopyBuf::ToV8(Mutex::new(Some(buf)))
|
ZeroCopyBuf::ToV8(Some(buf))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,9 +111,7 @@ impl ToV8 for ZeroCopyBuf {
|
||||||
value.into()
|
value.into()
|
||||||
}
|
}
|
||||||
Self::Temp(_) => unreachable!(),
|
Self::Temp(_) => unreachable!(),
|
||||||
Self::ToV8(x) => {
|
Self::ToV8(ref mut x) => x.take().expect("ZeroCopyBuf was empty"),
|
||||||
x.get_mut().unwrap().take().expect("ZeroCopyBuf was empty")
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if buf.is_empty() {
|
if buf.is_empty() {
|
||||||
|
@ -151,13 +148,9 @@ impl From<ZeroCopyBuf> for bytes::Bytes {
|
||||||
fn from(zbuf: ZeroCopyBuf) -> bytes::Bytes {
|
fn from(zbuf: ZeroCopyBuf) -> bytes::Bytes {
|
||||||
match zbuf {
|
match zbuf {
|
||||||
ZeroCopyBuf::FromV8(v) => v.into(),
|
ZeroCopyBuf::FromV8(v) => v.into(),
|
||||||
// WARNING(AaronO): potential footgun, but will disappear in future ZeroCopyBuf refactor
|
ZeroCopyBuf::ToV8(mut v) => {
|
||||||
ZeroCopyBuf::ToV8(v) => v
|
v.take().expect("ZeroCopyBuf was empty").into()
|
||||||
.lock()
|
}
|
||||||
.unwrap()
|
|
||||||
.take()
|
|
||||||
.expect("ZeroCopyBuf was empty")
|
|
||||||
.into(),
|
|
||||||
ZeroCopyBuf::Temp(v) => v.into(),
|
ZeroCopyBuf::Temp(v) => v.into(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue