Skip to content

Commit 1b3c6ba

Browse files
committed
make the code for nth closer to what it used to be
1 parent 60b0636 commit 1b3c6ba

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/libcore/slice/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2382,11 +2382,12 @@ macro_rules! iterator {
23822382
impl<'a, T> ExactSizeIterator for $name<'a, T> {
23832383
#[inline(always)]
23842384
fn len(&self) -> usize {
2385+
let diff = (self.end as usize).wrapping_sub(self.ptr as usize);
23852386
if mem::size_of::<T>() == 0 {
2386-
// end is really ptr+len
2387-
(self.end as usize).wrapping_sub(self.ptr as usize)
2387+
// end is really ptr+len, so we are already done
2388+
diff
23882389
} else {
2389-
unsafe { self.end.offset_from(self.ptr) as usize }
2390+
diff / mem::size_of::<T>()
23902391
}
23912392
}
23922393

0 commit comments

Comments
 (0)