From 05852a04edbc573f48eb3c31bdbdd22195de6da5 Mon Sep 17 00:00:00 2001 From: Dunqing <29533304+Dunqing@users.noreply.github.com> Date: Fri, 27 Sep 2024 11:18:42 +0000 Subject: [PATCH] perf(codegen): do not check whether there are annotation comments or not if we don't preserve annotation comments (#6107) --- crates/oxc_codegen/src/comment.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/crates/oxc_codegen/src/comment.rs b/crates/oxc_codegen/src/comment.rs index a288bbc0a..b4f48090c 100644 --- a/crates/oxc_codegen/src/comment.rs +++ b/crates/oxc_codegen/src/comment.rs @@ -31,6 +31,9 @@ impl<'a> Codegen<'a> { } pub fn has_annotation_comment(&self, start: u32) -> bool { + if !self.preserve_annotate_comments() { + return false; + } let Some(source_text) = self.source_text else { return false }; self.comments.get(&start).is_some_and(|comments| { comments.iter().any(|comment| Self::is_annotation_comment(comment, source_text)) @@ -38,6 +41,9 @@ impl<'a> Codegen<'a> { } pub fn has_non_annotation_comment(&self, start: u32) -> bool { + if !self.preserve_annotate_comments() { + return self.has_comment(start); + } let Some(source_text) = self.source_text else { return false }; self.comments.get(&start).is_some_and(|comments| { comments.iter().any(|comment| !Self::is_annotation_comment(comment, source_text))