Skip to content

Commit b15e137

Browse files
author
lch361
committedDec 24, 2023
Removed redundant bounds checking at Split's next and next_mut methods
1 parent e87ccb8 commit b15e137

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed
 

‎library/core/src/slice/iter.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -458,8 +458,8 @@ where
458458
match self.v.iter().position(|x| (self.pred)(x)) {
459459
None => self.finish(),
460460
Some(idx) => {
461-
let ret = Some(&self.v[..idx]);
462-
self.v = &self.v[idx + 1..];
461+
let ret = Some(unsafe { self.v.get_unchecked(..idx) });
462+
self.v = unsafe { self.v.get_unchecked(idx + 1..) };
463463
ret
464464
}
465465
}
@@ -491,8 +491,8 @@ where
491491
match self.v.iter().rposition(|x| (self.pred)(x)) {
492492
None => self.finish(),
493493
Some(idx) => {
494-
let ret = Some(&self.v[idx + 1..]);
495-
self.v = &self.v[..idx];
494+
let ret = Some(unsafe { self.v.get_unchecked(idx + 1..) });
495+
self.v = unsafe { self.v.get_unchecked(..idx) };
496496
ret
497497
}
498498
}

0 commit comments

Comments
 (0)
Please sign in to comment.