mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-04-24 23:57:57 +00:00
Also clamp the collection impls
This commit is contained in:
@@ -30,6 +30,8 @@ use std::collections::{
|
||||
#[cfg(feature = "collections")]
|
||||
use collections::borrow::ToOwned;
|
||||
|
||||
#[cfg(any(feature = "std", feature = "collections"))]
|
||||
use core::cmp;
|
||||
use core::fmt;
|
||||
#[cfg(feature = "std")]
|
||||
use core::hash::{Hash, BuildHasher};
|
||||
@@ -467,7 +469,7 @@ seq_impl!(
|
||||
BinaryHeapVisitor<T: Deserialize + Ord>,
|
||||
visitor,
|
||||
BinaryHeap::new(),
|
||||
BinaryHeap::with_capacity(visitor.size_hint().0),
|
||||
BinaryHeap::with_capacity(cmp::min(visitor.size_hint().0, 4096)),
|
||||
BinaryHeap::push);
|
||||
|
||||
#[cfg(any(feature = "std", feature = "collections"))]
|
||||
@@ -495,7 +497,7 @@ seq_impl!(
|
||||
S: BuildHasher + Default>,
|
||||
visitor,
|
||||
HashSet::with_hasher(S::default()),
|
||||
HashSet::with_capacity_and_hasher(visitor.size_hint().0, S::default()),
|
||||
HashSet::with_capacity_and_hasher(cmp::min(visitor.size_hint().0, 4096), S::default()),
|
||||
HashSet::insert);
|
||||
|
||||
#[cfg(any(feature = "std", feature = "collections"))]
|
||||
@@ -504,7 +506,7 @@ seq_impl!(
|
||||
VecVisitor<T: Deserialize>,
|
||||
visitor,
|
||||
Vec::new(),
|
||||
Vec::with_capacity(visitor.size_hint().0),
|
||||
Vec::with_capacity(cmp::min(visitor.size_hint().0, 4096)),
|
||||
Vec::push);
|
||||
|
||||
#[cfg(any(feature = "std", feature = "collections"))]
|
||||
@@ -513,7 +515,7 @@ seq_impl!(
|
||||
VecDequeVisitor<T: Deserialize>,
|
||||
visitor,
|
||||
VecDeque::new(),
|
||||
VecDeque::with_capacity(visitor.size_hint().0),
|
||||
VecDeque::with_capacity(cmp::min(visitor.size_hint().0, 4096)),
|
||||
VecDeque::push_back);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
@@ -791,7 +793,7 @@ map_impl!(
|
||||
S: BuildHasher + Default>,
|
||||
visitor,
|
||||
HashMap::with_hasher(S::default()),
|
||||
HashMap::with_capacity_and_hasher(visitor.size_hint().0, S::default()));
|
||||
HashMap::with_capacity_and_hasher(cmp::min(visitor.size_hint().0, 4096), S::default()));
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
Reference in New Issue
Block a user