From 3c76d2f8d1721b7ad9564aaf77146c97b2b5e40e Mon Sep 17 00:00:00 2001 From: overlookmotel Date: Thu, 12 Sep 2024 10:55:35 +0100 Subject: [PATCH] perf(index): remove `Idx` bounds-checks from `first` + `last` methods --- crates/oxc_index/src/idxslice.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/crates/oxc_index/src/idxslice.rs b/crates/oxc_index/src/idxslice.rs index a4b4bdabd060c..4472f1b996318 100644 --- a/crates/oxc_index/src/idxslice.rs +++ b/crates/oxc_index/src/idxslice.rs @@ -409,26 +409,25 @@ impl IndexSlice { /// 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.last_mut() } /// Copies elements from one part of the slice to another part of itself,