Skip to content

Commit 4c6d19d

Browse files
authored
perf(allocator): use capacity hint (#4584)
1 parent 1aea15c commit 4c6d19d

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

crates/oxc_allocator/src/arena.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,9 @@ impl<'alloc, T> Vec<'alloc, T> {
124124

125125
#[inline]
126126
pub fn from_iter_in<I: IntoIterator<Item = T>>(iter: I, allocator: &'alloc Allocator) -> Self {
127-
let mut vec = vec::Vec::new_in(&**allocator);
127+
let iter = iter.into_iter();
128+
let capacity = iter.size_hint().1.unwrap_or(0);
129+
let mut vec = vec::Vec::with_capacity_in(capacity, &**allocator);
128130
vec.extend(iter);
129131
Self(vec)
130132
}

0 commit comments

Comments
 (0)