Skip to content

Commit

Permalink
refactor(data_structures): remove is_empty methods for non-empty st…
Browse files Browse the repository at this point in the history
…acks (#6219)

Remove `SparseStack::is_empty` method. It's pointless as the stack is never empty.

Add a dummy `NonEmptyStack::is_empty` method that always returns `false`. This is also pointless, but it overrides `slice::is_empty` which is otherwise accessible via `Deref`.
  • Loading branch information
overlookmotel committed Oct 1, 2024
1 parent 61805fd commit 825645f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 10 deletions.
6 changes: 1 addition & 5 deletions crates/oxc_data_structures/src/stack/non_empty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,15 +290,11 @@ impl<T> NonEmptyStack<T> {
///
/// Number of entries is always at least 1. Stack is never empty.
#[inline]
#[expect(clippy::len_without_is_empty)] // `is_empty` method is pointless. It's never empty.
pub fn len(&self) -> usize {
<Self as StackCommon<T>>::len(self)
}

#[inline]
pub fn is_empty(&self) -> bool {
self.len() == 0
}

/// Get capacity.
#[inline]
pub fn capacity(&self) -> usize {
Expand Down
6 changes: 1 addition & 5 deletions crates/oxc_data_structures/src/stack/sparse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,15 +187,11 @@ impl<T> SparseStack<T> {
///
/// Number of entries is always at least 1. Stack is never empty.
#[inline]
#[expect(clippy::len_without_is_empty)] // `is_empty` method is pointless. It's never empty.
pub fn len(&self) -> usize {
self.has_values.len()
}

#[inline]
pub fn is_empty(&self) -> bool {
self.has_values.len() == 0
}

/// Get capacity of stack for any entries (either `Some` or `None`).
///
/// Capacity is always at least 1. Stack is never empty.
Expand Down

0 comments on commit 825645f

Please sign in to comment.