Skip to content

Commit

Permalink
refactor(ast): StaticMemberExpression::get_first_object use loop in…
Browse files Browse the repository at this point in the history
…stead of recursion (#7065)

Follow-on after #6969. Pure refactor. Loops are generally cheaper than recursion.
  • Loading branch information
overlookmotel committed Nov 1, 2024
1 parent 4012e6b commit b0211a1
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions crates/oxc_ast/src/ast_impl/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,16 +512,23 @@ impl<'a> ComputedMemberExpression<'a> {
impl<'a> StaticMemberExpression<'a> {
#[allow(missing_docs)]
pub fn get_first_object(&self) -> &Expression<'a> {
match &self.object {
Expression::StaticMemberExpression(member) => member.get_first_object(),
Expression::ChainExpression(chain) => {
if let ChainElement::StaticMemberExpression(expr) = &chain.expression {
expr.get_first_object()
} else {
&self.object
let mut object = &self.object;
loop {
match object {
Expression::StaticMemberExpression(member) => {
object = &member.object;
continue;
}
Expression::ChainExpression(chain) => {
if let ChainElement::StaticMemberExpression(member) = &chain.expression {
object = &member.object;
continue;
}
}
_ => {}
}
_ => &self.object,

return object;
}
}
}
Expand Down

0 comments on commit b0211a1

Please sign in to comment.