From c84e892380d321983e18234803e39ae1c4e33f98 Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Mon, 18 Nov 2024 02:35:46 +0000 Subject: [PATCH] perf(ast): `AstBuilder::vec1` use `Vec::from_array_in` (#7334) `AstBuilder::vec1` can use `Vec::from_array_in` rather than creating a `Vec` and then pushing to it. This should optimize better. --- crates/oxc_ast/src/ast_builder_impl.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/crates/oxc_ast/src/ast_builder_impl.rs b/crates/oxc_ast/src/ast_builder_impl.rs index 80937d833..80aeb1087 100644 --- a/crates/oxc_ast/src/ast_builder_impl.rs +++ b/crates/oxc_ast/src/ast_builder_impl.rs @@ -56,9 +56,7 @@ impl<'a> AstBuilder<'a> { /// Create a new arena-allocated [`Vec`] initialized with a single element. #[inline] pub fn vec1(self, value: T) -> Vec<'a, T> { - let mut vec = self.vec_with_capacity(1); - vec.push(value); - vec + self.vec_from_array([value]) } /// Collect an iterator into a new arena-allocated [`Vec`].