From ad870aa08aa658b68143592d463d7160b06947c9 Mon Sep 17 00:00:00 2001 From: Luca BRUNO Date: Wed, 31 Jul 2024 12:07:40 +0200 Subject: [PATCH] perf(allocator): use capacity hint --- 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 aa2ec32ef8a32..81459678c9e10 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) }