Skip to content

Commit

Permalink
perf(minifier): only substitute typed array constructor once (#8649)
Browse files Browse the repository at this point in the history
  • Loading branch information
Boshen committed Jan 22, 2025
1 parent 40316af commit 00dc63f
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions crates/oxc_minifier/src/peephole/substitute_alternate_syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,6 @@ impl<'a, 'b> PeepholeOptimizations {
self.try_compress_normal_assignment_to_combined_assignment(e, ctx);
self.try_compress_normal_assignment_to_combined_logical_assignment(e, ctx);
}
Expression::NewExpression(e) => {
self.try_compress_typed_array_constructor(e, ctx);
}
_ => {}
}

Expand Down Expand Up @@ -165,6 +162,10 @@ impl<'a, 'b> PeepholeOptimizations {
return;
}

if let Expression::NewExpression(e) = expr {
self.try_compress_typed_array_constructor(e, ctx);
}

if let Some(folded_expr) = match expr {
Expression::Identifier(ident) => self.try_compress_undefined(ident, ctx),
Expression::BooleanLiteral(_) => self.try_compress_boolean(expr, ctx),
Expand Down Expand Up @@ -1219,17 +1220,16 @@ impl<'a, 'b> PeepholeOptimizations {
e: &mut NewExpression<'a>,
ctx: Ctx<'a, 'b>,
) {
debug_assert!(!self.in_fixed_loop);
let Expression::Identifier(ident) = &e.callee else { return };
let name = ident.name.as_str();
if !Self::is_typed_array_name(name) || !ctx.is_global_reference(ident) {
return;
}

if e.arguments.len() == 1
&& e.arguments[0].as_expression().is_some_and(Expression::is_number_0)
{
e.arguments.clear();
self.mark_current_function_as_changed();
}
}

Expand Down

0 comments on commit 00dc63f

Please sign in to comment.