Auto merge of #73951 - pickfire:liballoc-intoiter, r=Mark-Simulacrum
Liballoc intoiter refactor
This commit is contained in:
commit
12c10e34a4
@ -2882,25 +2882,21 @@ impl<T> Iterator for IntoIter<T> {
|
||||
|
||||
#[inline]
|
||||
fn next(&mut self) -> Option<T> {
|
||||
unsafe {
|
||||
if self.ptr as *const _ == self.end {
|
||||
None
|
||||
} else {
|
||||
if mem::size_of::<T>() == 0 {
|
||||
} else if mem::size_of::<T>() == 0 {
|
||||
// purposefully don't use 'ptr.offset' because for
|
||||
// vectors with 0-size elements this would return the
|
||||
// same pointer.
|
||||
self.ptr = arith_offset(self.ptr as *const i8, 1) as *mut T;
|
||||
self.ptr = unsafe { arith_offset(self.ptr as *const i8, 1) as *mut T };
|
||||
|
||||
// Make up a value of this ZST.
|
||||
Some(mem::zeroed())
|
||||
Some(unsafe { mem::zeroed() })
|
||||
} else {
|
||||
let old = self.ptr;
|
||||
self.ptr = self.ptr.offset(1);
|
||||
self.ptr = unsafe { self.ptr.offset(1) };
|
||||
|
||||
Some(ptr::read(old))
|
||||
}
|
||||
}
|
||||
Some(unsafe { ptr::read(old) })
|
||||
}
|
||||
}
|
||||
|
||||
@ -2935,22 +2931,18 @@ unsafe fn get_unchecked(&mut self, i: usize) -> Self::Item
|
||||
impl<T> DoubleEndedIterator for IntoIter<T> {
|
||||
#[inline]
|
||||
fn next_back(&mut self) -> Option<T> {
|
||||
unsafe {
|
||||
if self.end == self.ptr {
|
||||
None
|
||||
} else {
|
||||
if mem::size_of::<T>() == 0 {
|
||||
} else if mem::size_of::<T>() == 0 {
|
||||
// See above for why 'ptr.offset' isn't used
|
||||
self.end = arith_offset(self.end as *const i8, -1) as *mut T;
|
||||
self.end = unsafe { arith_offset(self.end as *const i8, -1) as *mut T };
|
||||
|
||||
// Make up a value of this ZST.
|
||||
Some(mem::zeroed())
|
||||
Some(unsafe { mem::zeroed() })
|
||||
} else {
|
||||
self.end = self.end.offset(-1);
|
||||
self.end = unsafe { self.end.offset(-1) };
|
||||
|
||||
Some(ptr::read(self.end))
|
||||
}
|
||||
}
|
||||
Some(unsafe { ptr::read(self.end) })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user