Skip to content

Commit

Permalink
refactor(data_structures): NonEmptyStack::len hint that len is ne…
Browse files Browse the repository at this point in the history
…ver 0 (#6220)

Tiny optimization. Make sure compiler knows that `NonEmptyStack::len` can never return 0.
  • Loading branch information
overlookmotel committed Oct 1, 2024
1 parent 147a5d5 commit cc57541
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion crates/oxc_data_structures/src/stack/non_empty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ impl<T> StackCommon<T> for NonEmptyStack<T> {
// When stack has 1 entry, `start - cursor == 0`, so add 1 to get number of entries.
// SAFETY: Capacity cannot exceed `Self::MAX_CAPACITY`, which is `<= isize::MAX`,
// and offset can't exceed capacity, so `+ 1` cannot wrap around.
offset + 1
// `checked_add(1).unwrap_unchecked()` instead of just `+ 1` to hint to compiler
// that return value can never be zero.
unsafe { offset.checked_add(1).unwrap_unchecked() }
}
}

Expand Down

0 comments on commit cc57541

Please sign in to comment.