Skip to content

Commit 059a3d8

Browse files
committed
Shrink some slice iterator MIR
1 parent 701f211 commit 059a3d8

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

library/core/src/ptr/non_null.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1793,7 +1793,7 @@ impl<T: ?Sized> PartialEq for NonNull<T> {
17931793
#[inline]
17941794
#[allow(ambiguous_wide_pointer_comparisons)]
17951795
fn eq(&self, other: &Self) -> bool {
1796-
self.as_ptr() == other.as_ptr()
1796+
self.pointer == other.pointer
17971797
}
17981798
}
17991799

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ macro_rules! iterator {
103103
// so this new pointer is inside `self` and thus guaranteed to be non-null.
104104
unsafe {
105105
if_zst!(mut self,
106-
len => *len = len.unchecked_sub(offset),
106+
// Using the intrinsic directly avoids emitting a UbCheck
107+
len => *len = crate::intrinsics::unchecked_sub(*len, offset),
107108
_end => self.ptr = self.ptr.add(offset),
108109
);
109110
}
@@ -119,7 +120,8 @@ macro_rules! iterator {
119120
// SAFETY: By our precondition, `offset` can be at most the
120121
// current length, so the subtraction can never overflow.
121122
len => unsafe {
122-
*len = len.unchecked_sub(offset);
123+
// Using the intrinsic directly avoids emitting a UbCheck
124+
*len = crate::intrinsics::unchecked_sub(*len, offset);
123125
self.ptr
124126
},
125127
// SAFETY: the caller guarantees that `offset` doesn't exceed `self.len()`,

0 commit comments

Comments
 (0)