0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-03-03 09:31:22 -05:00

perf(serde_v8): preallocate vector when serializing arrays (#9955)

This commit is contained in:
Aaron O'Mullan 2021-04-04 15:04:35 +02:00 committed by GitHub
parent e33e46e13b
commit 5f2a83f563
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -103,13 +103,12 @@ pub struct ArraySerializer<'a, 'b, 'c> {
}
impl<'a, 'b, 'c> ArraySerializer<'a, 'b, 'c> {
pub fn new(scope: ScopePtr<'a, 'b, 'c>) -> Self {
// let serializer = Serializer::new(scope);
Self {
scope,
// serializer,
pending: vec![],
}
pub fn new(scope: ScopePtr<'a, 'b, 'c>, len: Option<usize>) -> Self {
let pending = match len {
Some(len) => Vec::with_capacity(len),
None => vec![],
};
Self { scope, pending }
}
}
@ -421,8 +420,8 @@ impl<'a, 'b, 'c> ser::Serializer for Serializer<'a, 'b, 'c> {
}
/// Serialises any Rust iterable into a JS Array
fn serialize_seq(self, _len: Option<usize>) -> Result<Self::SerializeSeq> {
Ok(ArraySerializer::new(self.scope))
fn serialize_seq(self, len: Option<usize>) -> Result<Self::SerializeSeq> {
Ok(ArraySerializer::new(self.scope, len))
}
fn serialize_tuple(self, len: usize) -> Result<Self::SerializeTuple> {