1
Fork 0

Shrink some slice iterator MIR

This commit is contained in:
Scott McMurray 2024-06-17 01:49:09 -07:00
parent 4236da52af
commit eac6b2910a

View file

@ -103,7 +103,8 @@ macro_rules! iterator {
// so this new pointer is inside `self` and thus guaranteed to be non-null. // so this new pointer is inside `self` and thus guaranteed to be non-null.
unsafe { unsafe {
if_zst!(mut self, if_zst!(mut self,
len => *len = len.unchecked_sub(offset), // Using the intrinsic directly avoids emitting a UbCheck
len => *len = crate::intrinsics::unchecked_sub(*len, offset),
_end => self.ptr = self.ptr.add(offset), _end => self.ptr = self.ptr.add(offset),
); );
} }
@ -119,7 +120,8 @@ macro_rules! iterator {
// SAFETY: By our precondition, `offset` can be at most the // SAFETY: By our precondition, `offset` can be at most the
// current length, so the subtraction can never overflow. // current length, so the subtraction can never overflow.
len => unsafe { len => unsafe {
*len = len.unchecked_sub(offset); // Using the intrinsic directly avoids emitting a UbCheck
*len = crate::intrinsics::unchecked_sub(*len, offset);
self.ptr self.ptr
}, },
// SAFETY: the caller guarantees that `offset` doesn't exceed `self.len()`, // SAFETY: the caller guarantees that `offset` doesn't exceed `self.len()`,