perf(allocator): use capacity hint (#4584)

This commit is contained in:
Luca Bruno 2024-08-01 00:41:27 +02:00 committed by GitHub
parent 1aea15c1ab
commit 4c6d19d440
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -124,7 +124,9 @@ impl<'alloc, T> Vec<'alloc, T> {
#[inline]
pub fn from_iter_in<I: IntoIterator<Item = T>>(iter: I, allocator: &'alloc Allocator) -> Self {
let mut vec = vec::Vec::new_in(&**allocator);
let iter = iter.into_iter();
let capacity = iter.size_hint().1.unwrap_or(0);
let mut vec = vec::Vec::with_capacity_in(capacity, &**allocator);
vec.extend(iter);
Self(vec)
}