Skip to content

Commit

Permalink
perf(transformer/class-properties): reduce size of `transform_call_ex…
Browse files Browse the repository at this point in the history
…pression_for_super_member_expr` (#7859)

Follow-on after #7831. Break up `transform_call_expression_for_super_member_expr` into multiple functions, to make `transform_call_expression_for_super_member_expr` as small as possible, to encourage inlining it.
  • Loading branch information
overlookmotel committed Dec 14, 2024
1 parent 9a30910 commit 38aafa2
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,10 @@ impl<'a, 'ctx, 'v> VisitMut<'a> for StaticInitializerVisitor<'a, 'ctx, 'v> {
Expression::PrivateFieldExpression(_) => {
self.class_properties.transform_private_field_expression(expr, self.ctx);
}
// `object.#prop()`
Expression::CallExpression(_) => {
self.class_properties.transform_super_call_expression(expr, self.ctx);
// `super.prop()` or `object.#prop()`
Expression::CallExpression(call_expr) => {
self.class_properties
.transform_call_expression_for_super_member_expr(call_expr, self.ctx);
self.class_properties.transform_call_expression(expr, self.ctx);
}
// `object.#prop = value`, `object.#prop += value`, `object.#prop ??= value` etc
Expand Down
41 changes: 31 additions & 10 deletions crates/oxc_transformer/src/es2022/class_properties/supers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,25 +71,46 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> {
/// `super.method()` -> `_superPropGet(_Class, "method", _Class, 2)([])`
/// `super.method(1)` -> `_superPropGet(_Class, "method", _Class, 2)([1])`
//
// `#[inline]` so that compiler sees that `expr` is an `Expression::CallExpression`.
// `#[inline]` so can bail out fast without a function call if `callee` is not a member expression
// with `super` as member expression object (fairly rare).
// Actual transform is broken out into separate functions.
#[inline]
pub(super) fn transform_super_call_expression(
pub(super) fn transform_call_expression_for_super_member_expr(
&mut self,
expr: &mut Expression<'a>,
call_expr: &mut CallExpression<'a>,
ctx: &mut TraverseCtx<'a>,
) {
let Expression::CallExpression(call) = expr else { unreachable!() };
let callee = &mut call.callee;
match callee {
match &call_expr.callee {
Expression::StaticMemberExpression(member) if member.object.is_super() => {
*callee = self.transform_static_member_expression_impl(member, true, ctx);
self.transform_call_expression_for_super_static_member_expr(call_expr, ctx);
}
Expression::ComputedMemberExpression(member) if member.object.is_super() => {
*callee = self.transform_computed_member_expression_impl(member, true, ctx);
self.transform_call_expression_for_super_computed_member_expr(call_expr, ctx);
}
_ => return,
_ => {}
};
Self::transform_super_call_expression_arguments(&mut call.arguments, ctx);
}

fn transform_call_expression_for_super_static_member_expr(
&mut self,
call_expr: &mut CallExpression<'a>,
ctx: &mut TraverseCtx<'a>,
) {
let callee = &mut call_expr.callee;
let Expression::StaticMemberExpression(member) = callee else { unreachable!() };
*callee = self.transform_static_member_expression_impl(member, true, ctx);
Self::transform_super_call_expression_arguments(&mut call_expr.arguments, ctx);
}

fn transform_call_expression_for_super_computed_member_expr(
&mut self,
call_expr: &mut CallExpression<'a>,
ctx: &mut TraverseCtx<'a>,
) {
let callee = &mut call_expr.callee;
let Expression::ComputedMemberExpression(member) = callee else { unreachable!() };
*callee = self.transform_computed_member_expression_impl(member, true, ctx);
Self::transform_super_call_expression_arguments(&mut call_expr.arguments, ctx);
}

/// [A, B, C] -> [[A, B, C]]
Expand Down

0 comments on commit 38aafa2

Please sign in to comment.