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:
parent
e33e46e13b
commit
5f2a83f563
1 changed files with 8 additions and 9 deletions
|
@ -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> {
|
||||
|
|
Loading…
Add table
Reference in a new issue