From f87cf895c2062cb5d71e97cd3221d101c825c8af Mon Sep 17 00:00:00 2001 From: Devyn Cairns Date: Wed, 10 Jul 2024 19:13:35 -0700 Subject: [PATCH] Set the capacity of the Vec used in `gather_captures()` to the number of captures expected (#13339) # Description Just more efficient allocation during `Stack::gather_captures()` so that we don't have to grow the `Vec` needlessly. # User-Facing Changes Slightly better performance. --- crates/nu-protocol/src/engine/stack.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/nu-protocol/src/engine/stack.rs b/crates/nu-protocol/src/engine/stack.rs index 9315744dfb..e963227ca8 100644 --- a/crates/nu-protocol/src/engine/stack.rs +++ b/crates/nu-protocol/src/engine/stack.rs @@ -277,7 +277,7 @@ impl Stack { } pub fn gather_captures(&self, engine_state: &EngineState, captures: &[VarId]) -> Stack { - let mut vars = vec![]; + let mut vars = Vec::with_capacity(captures.len()); let fake_span = Span::new(0, 0);