mirror of
https://github.com/aphrody-labs/oxc.git
synced 2026-10-14 22:29:17 +00:00
perf(minifier): use ident hashes in label comparison (#26887)
use `Ident` hashes when trying to fold simple labels
This commit is contained in:
1 parent
b0ebab9418
commit
57610b3f13
1 file changed
+4
-4
@@ -257,9 +257,9 @@ impl<'a> PeepholeOptimizations {
|
||||
/// ```
|
||||
pub fn try_fold_labeled(stmt: &mut Statement<'a>, ctx: &mut TraverseCtx<'a>) {
|
||||
let Statement::LabeledStatement(s) = stmt else { return };
|
||||
let id = s.label.name.as_str();
|
||||
let id = s.label.name;
|
||||
|
||||
if ctx.options().drop_labels.contains(id) {
|
||||
if ctx.options().drop_labels.contains(id.as_str()) {
|
||||
let new_stmt = Statement::new_empty_statement(s.span, ctx);
|
||||
ctx.replace_statement(stmt, new_stmt);
|
||||
return;
|
||||
@@ -269,8 +269,8 @@ impl<'a> PeepholeOptimizations {
|
||||
// Check if we need to remove the whole block.
|
||||
match &mut s.body {
|
||||
Statement::BreakStatement(break_stmt)
|
||||
if break_stmt.label.as_ref().is_some_and(|l| l.name.as_str() == id) => {}
|
||||
Statement::BlockStatement(block) if block.body.first().is_some_and(|first| matches!(first, Statement::BreakStatement(break_stmt) if break_stmt.label.as_ref().is_some_and(|l| l.name.as_str() == id))) => {}
|
||||
if break_stmt.label.as_ref().is_some_and(|l| l.name == id) => {}
|
||||
Statement::BlockStatement(block) if block.body.first().is_some_and(|first| matches!(first, Statement::BreakStatement(break_stmt) if break_stmt.label.as_ref().is_some_and(|l| l.name == id))) => {}
|
||||
Statement::EmptyStatement(_) => {
|
||||
let new_stmt = Statement::new_empty_statement(s.span, ctx);
|
||||
ctx.replace_statement(stmt, new_stmt);
|
||||
|
||||
Reference in new issue
Block a user