Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(index): remove Idx bounds-checks from first + last methods #5726

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
9 changes: 4 additions & 5 deletions crates/oxc_index/src/idxslice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,26 +409,25 @@ impl<I: Idx, T> IndexSlice<I, [T]> {
/// Return the the last element, if we are not empty.
#[inline(always)]
pub fn last(&self) -> Option<&T> {
self.len().checked_sub(1).and_then(|i| self.get(I::from_usize(i)))
self.raw.last()
}

/// Return the the last element, if we are not empty.
#[inline]
pub fn last_mut(&mut self) -> Option<&mut T> {
let i = self.len().checked_sub(1)?;
self.get_mut(I::from_usize(i))
self.raw.last_mut()
}

/// Return the the first element, if we are not empty.
#[inline]
pub fn first(&self) -> Option<&T> {
self.get(I::from_usize(0))
self.raw.first()
}

/// Return the the first element, if we are not empty.
#[inline]
pub fn first_mut(&mut self) -> Option<&mut T> {
self.get_mut(I::from_usize(0))
self.raw.first_mut()
}

/// Copies elements from one part of the slice to another part of itself,
Expand Down