Skip to content

Commit

Permalink
Shrink some slice iterator MIR
Browse files Browse the repository at this point in the history
  • Loading branch information
scottmcm committed Jun 17, 2024
1 parent 553e7c4 commit b7fac5b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion library/core/src/ptr/non_null.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1793,7 +1793,7 @@ impl<T: ?Sized> PartialEq for NonNull<T> {
#[inline]
#[allow(ambiguous_wide_pointer_comparisons)]
fn eq(&self, other: &Self) -> bool {
self.as_ptr() == other.as_ptr()
self.pointer == other.pointer
}
}

Expand Down
6 changes: 4 additions & 2 deletions library/core/src/slice/iter/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ macro_rules! iterator {
// so this new pointer is inside `self` and thus guaranteed to be non-null.
unsafe {
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),
);
}
Expand All @@ -119,7 +120,8 @@ macro_rules! iterator {
// SAFETY: By our precondition, `offset` can be at most the
// current length, so the subtraction can never overflow.
len => unsafe {
*len = len.unchecked_sub(offset);
// Using the intrinsic directly avoids emitting a UbCheck
*len = crate::intrinsics::unchecked_sub(*len, offset);
self.ptr
},
// SAFETY: the caller guarantees that `offset` doesn't exceed `self.len()`,
Expand Down

0 comments on commit b7fac5b

Please sign in to comment.