Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions crates/oxc_data_structures/src/stack/sparse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,21 @@ impl<T> SparseStack<T> {
}
}

/// Get value of last entry on the stack.
#[inline]
pub fn last_mut(&mut self) -> Option<&mut T> {
let has_value = *self.has_values.last();
if has_value {
debug_assert!(!self.values.is_empty());
// SAFETY: Last `self.has_values` is only `true` if there's a corresponding value in `self.values`.
// This invariant is maintained in `push`, `pop`, `take_last`, `last_or_init`, and `last_mut_or_init`.
let value = unsafe { self.values.last_mut_unchecked() };
Some(value)
} else {
None
}
}

/// Take value from last entry on the stack, leaving last entry empty.
#[inline]
pub fn take_last(&mut self) -> Option<T> {
Expand Down