Skip to content

Commit

Permalink
refactor(minifier): use NonEmptyStack for function stack (#8661)
Browse files Browse the repository at this point in the history
  • Loading branch information
Boshen authored and IWANABETHATGUY committed Jan 23, 2025
1 parent ba201a6 commit ad3ef33
Show file tree
Hide file tree
Showing 6 changed files with 2,434 additions and 67 deletions.
19 changes: 19 additions & 0 deletions crates/oxc_allocator/src/clone_in.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ pub trait CloneIn<'new_alloc>: Sized {
/// Clone `self` into the given `allocator`. `allocator` may be the same one
/// that `self` is already in.
fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned;

/// Almost same as `clone_in`, but for some special type, it will also clone the semantic ids.
/// Please use this method only if you make sure the semantic info is synced with the ast.
#[inline]
fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
self.clone_in(allocator)
}
}

impl<'alloc, T, C> CloneIn<'alloc> for Option<T>
Expand All @@ -42,6 +49,10 @@ where
fn clone_in(&self, allocator: &'alloc Allocator) -> Self::Cloned {
self.as_ref().map(|it| it.clone_in(allocator))
}

fn clone_in_with_semantic_ids(&self, allocator: &'alloc Allocator) -> Self::Cloned {
self.as_ref().map(|it| it.clone_in_with_semantic_ids(allocator))
}
}

impl<'new_alloc, T, C> CloneIn<'new_alloc> for Box<'_, T>
Expand All @@ -53,6 +64,10 @@ where
fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
Box::new_in(self.as_ref().clone_in(allocator), allocator)
}

fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
Box::new_in(self.as_ref().clone_in_with_semantic_ids(allocator), allocator)
}
}

impl<'new_alloc, T, C> CloneIn<'new_alloc> for Vec<'_, T>
Expand All @@ -64,6 +79,10 @@ where
fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
Vec::from_iter_in(self.iter().map(|it| it.clone_in(allocator)), allocator)
}

fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
Vec::from_iter_in(self.iter().map(|it| it.clone_in_with_semantic_ids(allocator)), allocator)
}
}

impl<'alloc, T: Copy> CloneIn<'alloc> for Cell<T> {
Expand Down
Loading

0 comments on commit ad3ef33

Please sign in to comment.