Skip to content

Commit

Permalink
perf(transformer/class-properties): inline visitor methods (#7485)
Browse files Browse the repository at this point in the history
Inline visitor methods in class properties transform.
  • Loading branch information
overlookmotel committed Nov 26, 2024
1 parent 24189f2 commit 5ca6eea
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions crates/oxc_transformer/src/es2022/class_properties/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,8 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> {
}

/// Pop from private props stack.
// `#[inline]` because this is function is so small
#[inline]
pub(super) fn transform_class_on_exit(&mut self, class: &Class) {
// Ignore TS class declarations
// TODO: Is this correct?
Expand Down
8 changes: 8 additions & 0 deletions crates/oxc_transformer/src/es2022/class_properties/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,8 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> {
}

impl<'a, 'ctx> Traverse<'a> for ClassProperties<'a, 'ctx> {
// `#[inline]` because this is a hot path
#[inline]
fn enter_expression(&mut self, expr: &mut Expression<'a>, ctx: &mut TraverseCtx<'a>) {
// Note: `delete this.#prop` is an early syntax error, so no need to handle transforming it
match expr {
Expand Down Expand Up @@ -306,6 +308,8 @@ impl<'a, 'ctx> Traverse<'a> for ClassProperties<'a, 'ctx> {
}
}

// `#[inline]` because this is a hot path
#[inline]
fn enter_assignment_target(
&mut self,
target: &mut AssignmentTarget<'a>,
Expand All @@ -314,6 +318,8 @@ impl<'a, 'ctx> Traverse<'a> for ClassProperties<'a, 'ctx> {
self.transform_assignment_target(target, ctx);
}

// `#[inline]` because this is a hot path
#[inline]
fn enter_statement(&mut self, stmt: &mut Statement<'a>, ctx: &mut TraverseCtx<'a>) {
match stmt {
// `class C {}`
Expand All @@ -340,6 +346,8 @@ impl<'a, 'ctx> Traverse<'a> for ClassProperties<'a, 'ctx> {
}
}

// `#[inline]` because `transform_class_on_exit` is so small
#[inline]
fn exit_class(&mut self, class: &mut Class<'a>, _ctx: &mut TraverseCtx<'a>) {
self.transform_class_on_exit(class);
}
Expand Down

0 comments on commit 5ca6eea

Please sign in to comment.