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 3da0334 commit 147a5d5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
5 changes: 4 additions & 1 deletion crates/oxc_data_structures/src/stack/non_empty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,12 @@ impl<T> NonEmptyStack<T> {
<Self as StackCommon<T>>::len(self)
}

/// Get if stack is empty. Always returns `false`.
#[inline]
pub fn is_empty(&self) -> bool {
self.len() == 0
// This method is pointless, as the stack is never empty. But provide it to override
// the default method from `slice::is_empty` which is inherited via `Deref`
false
}

/// Get capacity.
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 147a5d5

Please sign in to comment.