Skip to content

Commit

Permalink
refactor(transformer): pre-allocate more stack space
Browse files Browse the repository at this point in the history
  • Loading branch information
overlookmotel committed Sep 26, 2024
1 parent e1a6472 commit f2a5883
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion crates/oxc_transformer/src/es2015/arrow_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ pub struct ArrowFunctions<'a> {
impl<'a> ArrowFunctions<'a> {
pub fn new(options: ArrowFunctionsOptions) -> Self {
// `SparseStack` is created with 1 empty entry, for `Program`
Self { _options: options, this_var_stack: SparseStack::new() }
Self { _options: options, this_var_stack: SparseStack::with_capacity(16, 0) }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ struct Exploded<'a> {

impl<'a> ExponentiationOperator<'a> {
pub fn new() -> Self {
Self { var_declarations: SparseStack::new() }
Self { var_declarations: SparseStack::with_capacity(16, 0) }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub struct NullishCoalescingOperator<'a> {

impl<'a> NullishCoalescingOperator<'a> {
pub fn new() -> Self {
Self { var_declarations: SparseStack::new() }
Self { var_declarations: SparseStack::with_capacity(16, 0) }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub struct LogicalAssignmentOperators<'a> {

impl<'a> LogicalAssignmentOperators<'a> {
pub fn new() -> Self {
Self { var_declarations: SparseStack::new() }
Self { var_declarations: SparseStack::with_capacity(16, 0) }
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_transformer/src/helpers/stack/sparse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ impl<T> SparseStack<T> {
///
/// # Panics
/// Panics if `T` is a zero-sized type.
#[expect(dead_code)]
pub fn new() -> Self {
// `has_values` starts with a single empty entry, which will never be popped off.
// This means `take_last`, `last_or_init`, and `last_mut_or_init` can all be infallible,
Expand All @@ -70,7 +71,6 @@ impl<T> SparseStack<T> {
/// * `total_capacity` must not exceed `Self::MAX_TOTAL_CAPACITY`.
/// * `filled_capacity` must not exceed `Self::MAX_FILLED_CAPACITY`.
#[inline]
#[expect(dead_code)]
pub fn with_capacity(total_capacity: usize, filled_capacity: usize) -> Self {
Self {
has_values: NonEmptyStack::with_capacity(total_capacity, false),
Expand Down

0 comments on commit f2a5883

Please sign in to comment.