Skip to content

Commit

Permalink
refactor(data_structures)!: rename Stack::last_unchecked_mut method (
Browse files Browse the repository at this point in the history
…#8911)

Rename `Stack::last_mut_unchecked` to `Stack::last_unchecked_mut`. This matches `std`'s naming convention e.g. `get_unchecked_mut` on slices.
  • Loading branch information
overlookmotel committed Feb 5, 2025
1 parent 0a74cf5 commit bec8fee
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions crates/oxc_data_structures/src/stack/sparse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ impl<T> SparseStack<T> {
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() };
let value = unsafe { self.values.last_unchecked_mut() };
Some(value)
} else {
None
Expand Down Expand Up @@ -236,7 +236,7 @@ impl<T> SparseStack<T> {
// This invariant is maintained in `push`, `pop`, `take_last`, and `last_or_init`.
// Here either last `self.has_values` was already `true`, or it's just been set to `true`
// and a value pushed to `self.values` above.
unsafe { self.values.last_mut_unchecked() }
unsafe { self.values.last_unchecked_mut() }
}

/// Get number of entries on the stack.
Expand Down
4 changes: 2 additions & 2 deletions crates/oxc_data_structures/src/stack/standard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ impl<T> Stack<T> {
#[expect(clippy::if_not_else)]
if !self.is_empty() {
// SAFETY: Stack is not empty
Some(unsafe { self.last_mut_unchecked() })
Some(unsafe { self.last_unchecked_mut() })
} else {
None
}
Expand All @@ -236,7 +236,7 @@ impl<T> Stack<T> {
///
/// * Stack must not be empty.
#[inline]
pub unsafe fn last_mut_unchecked(&mut self) -> &mut T {
pub unsafe fn last_unchecked_mut(&mut self) -> &mut T {
debug_assert!(self.end > self.start);
debug_assert!(self.cursor > self.start);
debug_assert!(self.cursor <= self.end);
Expand Down

0 comments on commit bec8fee

Please sign in to comment.