From a43e9512f3f9df3bf7756f44f5411b0475826867 Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Thu, 5 Sep 2024 01:24:59 +0000 Subject: [PATCH] refactor(ast): use loop instead of recursion (#5447) Use loop instead of recursive function call. Loops are usually cheaper. --- crates/oxc_ast/src/ast_impl/js.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/crates/oxc_ast/src/ast_impl/js.rs b/crates/oxc_ast/src/ast_impl/js.rs index 6c6b71909b0a7..0af117dda4424 100644 --- a/crates/oxc_ast/src/ast_impl/js.rs +++ b/crates/oxc_ast/src/ast_impl/js.rs @@ -174,10 +174,11 @@ impl<'a> Expression<'a> { /// Remove nested parentheses from this expression. pub fn without_parenthesized(&self) -> &Self { - match self { - Expression::ParenthesizedExpression(expr) => expr.expression.without_parenthesized(), - _ => self, + let mut expr = self; + while let Expression::ParenthesizedExpression(paran_expr) = expr { + expr = ¶n_expr.expression; } + expr } pub fn is_specific_id(&self, name: &str) -> bool {