Skip to content

Commit

Permalink
perf(codegen): do not check for comments if turned off (#8598)
Browse files Browse the repository at this point in the history
  • Loading branch information
Boshen committed Jan 19, 2025
1 parent 8cce69a commit d966e0a
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions crates/oxc_codegen/src/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1447,10 +1447,12 @@ impl GenExpr for CallExpression<'_> {
type_parameters.print(p, ctx);
}
p.print_ascii_byte(b'(');
let print_comments = p.options.print_comments();
let has_comment_before_right_paren =
self.span.end > 0 && p.has_comment(self.span.end - 1);
let has_comment = has_comment_before_right_paren
|| self.arguments.iter().any(|item| p.has_comment(item.span().start));
print_comments && self.span.end > 0 && p.has_comment(self.span.end - 1);
let has_comment = print_comments
&& (has_comment_before_right_paren
|| self.arguments.iter().any(|item| p.has_comment(item.span().start)));
if has_comment {
p.indent();
p.print_list_with_comments(&self.arguments, ctx);
Expand Down Expand Up @@ -2075,10 +2077,17 @@ impl GenExpr for SequenceExpression<'_> {
impl GenExpr for ImportExpression<'_> {
fn gen_expr(&self, p: &mut Codegen, precedence: Precedence, ctx: Context) {
let wrap = precedence >= Precedence::New || ctx.intersects(Context::FORBID_CALL);
let has_comment_before_right_paren = self.span.end > 0 && p.has_comment(self.span.end - 1);
let has_comment = has_comment_before_right_paren
|| p.has_comment(self.source.span().start)
|| self.arguments.first().is_some_and(|argument| p.has_comment(argument.span().start));

let print_comments = p.options.print_comments();
let has_comment_before_right_paren =
print_comments && self.span.end > 0 && p.has_comment(self.span.end - 1);
let has_comment = print_comments
&& (has_comment_before_right_paren
|| p.has_comment(self.source.span().start)
|| self
.arguments
.first()
.is_some_and(|argument| p.has_comment(argument.span().start)));

p.wrap(wrap, |p| {
p.print_space_before_identifier();
Expand Down

0 comments on commit d966e0a

Please sign in to comment.