Skip to content

Commit

Permalink
perf(allocator): use lower bound of size hint when creating Vecs from…
Browse files Browse the repository at this point in the history
… an iterator (#6194)
  • Loading branch information
DonIsaac committed Oct 1, 2024
1 parent 70d4c56 commit 5db9b30
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion crates/oxc_allocator/src/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ impl<'alloc, T> Vec<'alloc, T> {
#[inline]
pub fn from_iter_in<I: IntoIterator<Item = T>>(iter: I, allocator: &'alloc Allocator) -> Self {
let iter = iter.into_iter();
let capacity = iter.size_hint().1.unwrap_or(0);
let hint = iter.size_hint();
let capacity = hint.1.unwrap_or(hint.0);
let mut vec = vec::Vec::with_capacity_in(capacity, &**allocator);
vec.extend(iter);
Self(vec)
Expand Down

0 comments on commit 5db9b30

Please sign in to comment.