From 4c6d19d440461ff6cf14435ef7646ef47170805e Mon Sep 17 00:00:00 2001 From: Luca Bruno Date: Thu, 1 Aug 2024 00:41:27 +0200 Subject: [PATCH] perf(allocator): use capacity hint (#4584) --- crates/oxc_allocator/src/arena.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/oxc_allocator/src/arena.rs b/crates/oxc_allocator/src/arena.rs index aa2ec32ef..81459678c 100644 --- a/crates/oxc_allocator/src/arena.rs +++ b/crates/oxc_allocator/src/arena.rs @@ -124,7 +124,9 @@ impl<'alloc, T> Vec<'alloc, T> { #[inline] pub fn from_iter_in>(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) }