From 7fe2a2f68191d7a0964145c3c5401c80b1943b9d Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Sat, 6 Jul 2024 09:56:41 +0000 Subject: [PATCH] perf(parser): do not copy comments (#4067) Follow-on from #4045. `.from_iter()` copies the `Vec` of comments into another `Vec` before converting to a boxed slice. This copy is unnecessary - just convert direct. --- crates/oxc_parser/src/lexer/trivia_builder.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/crates/oxc_parser/src/lexer/trivia_builder.rs b/crates/oxc_parser/src/lexer/trivia_builder.rs index 696cb23e24da..ea66aaa2c35a 100644 --- a/crates/oxc_parser/src/lexer/trivia_builder.rs +++ b/crates/oxc_parser/src/lexer/trivia_builder.rs @@ -1,4 +1,4 @@ -use oxc_ast::{Comment, CommentKind, SortedComments, Trivias}; +use oxc_ast::{Comment, CommentKind, Trivias}; use oxc_span::Span; #[derive(Debug, Default)] @@ -12,8 +12,7 @@ pub struct TriviaBuilder { impl TriviaBuilder { pub fn build(self) -> Trivias { - let comments = SortedComments::from_iter(self.comments); - Trivias::new(comments, self.irregular_whitespaces) + Trivias::new(self.comments.into_boxed_slice(), self.irregular_whitespaces) } pub fn add_single_line_comment(&mut self, start: u32, end: u32) {