Skip to content

Commit

Permalink
Call reserve() in DeserializeSeed example
Browse files Browse the repository at this point in the history
This suggests calling `reserve()` in example code so that people who ~blindly copy it get faster code.
  • Loading branch information
Kixunil committed Jun 30, 2022
1 parent 845b900 commit 41ffa6d
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions serde/src/de/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,11 @@ impl<T> DeserializeOwned for T where T: for<'de> Deserialize<'de> {}
/// where
/// A: SeqAccess<'de>,
/// {
/// // Decrease the number of reallocations if there are many elements
/// if let Some(size_hint) = seq.size_hint() {
/// self.0.reserve(size_hint);
/// }
///
/// // Visit each element in the inner array and push it onto
/// // the existing vector.
/// while let Some(elem) = seq.next_element()? {
Expand Down

0 comments on commit 41ffa6d

Please sign in to comment.