提交 e1e34e92 编写于 作者: K Kevin Ballard

Reintroduce non-null assumptions in core::slice iterators

The previous assumptions were not valid for slices of zero-sized
elements.
上级 52efe55d
...@@ -665,10 +665,14 @@ impl<'a, T> Iterator for $name<'a, T> { ...@@ -665,10 +665,14 @@ impl<'a, T> Iterator for $name<'a, T> {
#[inline] #[inline]
fn next(&mut self) -> Option<$elem> { fn next(&mut self) -> Option<$elem> {
// could be implemented with slices, but this avoids bounds checks // could be implemented with slices, but this avoids bounds checks
unsafe { if self.ptr == self.end {
if self.ptr == self.end { None
None } else {
} else { unsafe {
if mem::size_of::<T>() != 0 {
::intrinsics::assume(!self.ptr.is_null());
::intrinsics::assume(!self.end.is_null());
}
let old = self.ptr; let old = self.ptr;
self.ptr = slice_offset!(self.ptr, 1); self.ptr = slice_offset!(self.ptr, 1);
Some(slice_ref!(old)) Some(slice_ref!(old))
...@@ -706,11 +710,15 @@ impl<'a, T> DoubleEndedIterator for $name<'a, T> { ...@@ -706,11 +710,15 @@ impl<'a, T> DoubleEndedIterator for $name<'a, T> {
#[inline] #[inline]
fn next_back(&mut self) -> Option<$elem> { fn next_back(&mut self) -> Option<$elem> {
// could be implemented with slices, but this avoids bounds checks // could be implemented with slices, but this avoids bounds checks
unsafe { if self.end == self.ptr {
if self.end == self.ptr { None
None } else {
} else { unsafe {
self.end = slice_offset!(self.end, -1); self.end = slice_offset!(self.end, -1);
if mem::size_of::<T>() != 0 {
::intrinsics::assume(!self.ptr.is_null());
::intrinsics::assume(!self.end.is_null());
}
Some(slice_ref!(self.end)) Some(slice_ref!(self.end))
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册