diff --git a/Cargo.lock b/Cargo.lock index 6936b3758b690..da3aa1db22b79 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2120,6 +2120,7 @@ dependencies = [ "oxc_ast_visit", "oxc_codegen", "oxc_compat", + "oxc_data_structures", "oxc_ecmascript", "oxc_mangler", "oxc_parser", diff --git a/crates/oxc_minifier/Cargo.toml b/crates/oxc_minifier/Cargo.toml index 45174e55a0527..92f72aab0ff51 100644 --- a/crates/oxc_minifier/Cargo.toml +++ b/crates/oxc_minifier/Cargo.toml @@ -26,6 +26,7 @@ oxc_ast = { workspace = true } oxc_ast_visit = { workspace = true } oxc_codegen = { workspace = true } oxc_compat = { workspace = true } +oxc_data_structures = { workspace = true, features = ["stack"] } oxc_ecmascript = { workspace = true } oxc_mangler = { workspace = true } oxc_parser = { workspace = true } diff --git a/crates/oxc_minifier/src/peephole/mod.rs b/crates/oxc_minifier/src/peephole/mod.rs index a259a4a9f4ad6..840afd4f24d8e 100644 --- a/crates/oxc_minifier/src/peephole/mod.rs +++ b/crates/oxc_minifier/src/peephole/mod.rs @@ -124,7 +124,7 @@ impl<'a> Traverse<'a, MinifierState<'a>> for PeepholeOptimizations { ctx.scoping_mut().delete_reference(*reference_id_to_remove); } } - debug_assert!(ctx.state.class_symbols_stack.is_empty()); + debug_assert!(ctx.state.class_symbols_stack.is_exhausted()); } fn exit_statements(&mut self, stmts: &mut Vec<'a, Statement<'a>>, ctx: &mut TraverseCtx<'a>) { diff --git a/crates/oxc_minifier/src/state.rs b/crates/oxc_minifier/src/state.rs index 96775837fc146..8ef2db04609aa 100644 --- a/crates/oxc_minifier/src/state.rs +++ b/crates/oxc_minifier/src/state.rs @@ -1,6 +1,7 @@ use oxc_ecmascript::constant_evaluation::ConstantValue; use rustc_hash::{FxHashMap, FxHashSet}; +use oxc_data_structures::stack::NonEmptyStack; use oxc_span::{Atom, SourceType}; use oxc_syntax::symbol::SymbolId; @@ -37,17 +38,17 @@ impl MinifierState<'_> { /// Stack to track class symbol information pub struct ClassSymbolsStack<'a> { - stack: Vec>>, + stack: NonEmptyStack>>, } impl<'a> ClassSymbolsStack<'a> { pub fn new() -> Self { - Self { stack: Vec::new() } + Self { stack: NonEmptyStack::new(FxHashSet::default()) } } - /// Check if the stack is empty - pub fn is_empty(&self) -> bool { - self.stack.is_empty() + /// Check if the stack is exhausted + pub fn is_exhausted(&self) -> bool { + self.stack.is_exhausted() } /// Enter a new class scope @@ -62,13 +63,11 @@ impl<'a> ClassSymbolsStack<'a> { /// Add a private member to the current class scope pub fn push_private_member_to_current_class(&mut self, name: Atom<'a>) { - if let Some(current_class) = self.stack.last_mut() { - current_class.insert(name); - } + self.stack.last_mut().insert(name); } /// Check if a private member is used in the current class scope pub fn is_private_member_used_in_current_class(&self, name: &Atom<'a>) -> bool { - self.stack.last().is_some_and(|current_class| current_class.contains(name)) + self.stack.last().contains(name) } } diff --git a/tasks/track_memory_allocations/allocs_minifier.snap b/tasks/track_memory_allocations/allocs_minifier.snap index e143e19ded382..eb2118aee7b6c 100644 --- a/tasks/track_memory_allocations/allocs_minifier.snap +++ b/tasks/track_memory_allocations/allocs_minifier.snap @@ -4,11 +4,11 @@ checker.ts | 2.92 MB || 84074 | 14190 | cal.com.tsx | 1.06 MB || 40526 | 3033 || 37074 | 4733 | 1.654 MB -RadixUIAdoptionSection.jsx | 2.52 kB || 82 | 8 || 30 | 6 | 992 B +RadixUIAdoptionSection.jsx | 2.52 kB || 83 | 8 || 30 | 6 | 992 B pdf.mjs | 567.30 kB || 19823 | 2900 || 47400 | 7781 | 1.624 MB -antd.js | 6.69 MB || 99854 | 13518 || 331725 | 70117 | 17.407 MB +antd.js | 6.69 MB || 99855 | 13518 || 331725 | 70117 | 17.407 MB -binder.ts | 193.08 kB || 4768 | 974 || 7059 | 834 | 201.192 kB +binder.ts | 193.08 kB || 4769 | 974 || 7059 | 834 | 201.192 kB