From 5db9b3002c7c916ba50cccc7d40805e1b9eea328 Mon Sep 17 00:00:00 2001 From: DonIsaac <22823424+DonIsaac@users.noreply.github.com> Date: Tue, 1 Oct 2024 00:07:29 +0000 Subject: [PATCH] perf(allocator): use lower bound of size hint when creating Vecs from an iterator (#6194) --- crates/oxc_allocator/src/vec.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/oxc_allocator/src/vec.rs b/crates/oxc_allocator/src/vec.rs index d3d226121edb7..551faaf3f1613 100644 --- a/crates/oxc_allocator/src/vec.rs +++ b/crates/oxc_allocator/src/vec.rs @@ -95,7 +95,8 @@ impl<'alloc, T> Vec<'alloc, T> { #[inline] pub fn from_iter_in>(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)