Skip to content

Commit

Permalink
perf(transformer/arrow-functions): move arguments transform checks to…
Browse files Browse the repository at this point in the history
… aid inlining
  • Loading branch information
overlookmotel committed Nov 17, 2024
1 parent f54762c commit 5e6cbe1
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions crates/oxc_transformer/src/common/arrow_function_converter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,15 +373,27 @@ impl<'a> Traverse<'a> for ArrowFunctionConverter<'a> {
ident: &mut IdentifierReference<'a>,
ctx: &mut TraverseCtx<'a>,
) {
self.transform_identifier_reference_for_arguments(ident, ctx);
// Do this check here rather than in `transform_identifier_reference_for_arguments`
// so that the fast path for "no transform required" doesn't require a function call.
// Probably this small function will be inlined.
let arguments_needs_transform = *self.arguments_needs_transform_stack.last();
if arguments_needs_transform {
self.transform_identifier_reference_for_arguments(ident, ctx);
}
}

fn enter_binding_identifier(
&mut self,
ident: &mut BindingIdentifier<'a>,
ctx: &mut TraverseCtx<'a>,
) {
self.transform_binding_identifier_for_arguments(ident, ctx);
// Do this check here rather than in `transform_binding_identifier_for_arguments`
// so that the fast path for "no transform required" doesn't require a function call.
// Probably this small function will be inlined.
let arguments_needs_transform = *self.arguments_needs_transform_stack.last();
if arguments_needs_transform {
self.transform_binding_identifier_for_arguments(ident, ctx);
}
}
}

Expand Down Expand Up @@ -907,8 +919,7 @@ impl<'a> ArrowFunctionConverter<'a> {
ident: &mut IdentifierReference<'a>,
ctx: &mut TraverseCtx<'a>,
) {
let arguments_needs_transform = *self.arguments_needs_transform_stack.last();
if !arguments_needs_transform || &ident.name != "arguments" {
if &ident.name != "arguments" {
return;
}

Expand Down Expand Up @@ -952,11 +963,9 @@ impl<'a> ArrowFunctionConverter<'a> {
ident: &mut BindingIdentifier<'a>,
ctx: &mut TraverseCtx<'a>,
) {
let arguments_needs_transform = *self.arguments_needs_transform_stack.last();
if !arguments_needs_transform
|| ctx.current_scope_flags().is_strict_mode() // `arguments` is not allowed to be defined in strict mode
|| &ident.name != "arguments"
{
// `arguments` is not allowed to be defined in strict mode.
// Check if strict mode first to avoid the more expensive string comparison check if possible.
if ctx.current_scope_flags().is_strict_mode() || &ident.name != "arguments" {
return;
}

Expand Down

0 comments on commit 5e6cbe1

Please sign in to comment.