Skip to content

Eliminate more excessive null-checks from slice iterators #22669

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 28, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/libcollections/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,8 +433,10 @@ impl<T> Vec<T> {
#[stable(feature = "rust1", since = "1.0.0")]
pub fn as_mut_slice(&mut self) -> &mut [T] {
unsafe {
let ptr = *self.ptr;
assume(!ptr.is_null());
mem::transmute(RawSlice {
data: *self.ptr,
data: ptr,
len: self.len,
})
}
Expand All @@ -458,6 +460,7 @@ impl<T> Vec<T> {
pub fn into_iter(self) -> IntoIter<T> {
unsafe {
let ptr = *self.ptr;
assume(!ptr.is_null());
let cap = self.cap;
let begin = ptr as *const T;
let end = if mem::size_of::<T>() == 0 {
Expand Down
3 changes: 3 additions & 0 deletions src/libcore/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ use cmp::{Ordering, PartialEq, PartialOrd, Eq, Ord};
use cmp::Ordering::{Less, Equal, Greater};
use cmp;
use default::Default;
use intrinsics::assume;
use iter::*;
use ops::{FnMut, self, Index};
use ops::RangeFull;
Expand Down Expand Up @@ -137,6 +138,7 @@ impl<T> SliceExt for [T] {
fn iter<'a>(&'a self) -> Iter<'a, T> {
unsafe {
let p = self.as_ptr();
assume(!p.is_null());
if mem::size_of::<T>() == 0 {
Iter {ptr: p,
end: (p as usize + self.len()) as *const T,
Expand Down Expand Up @@ -276,6 +278,7 @@ impl<T> SliceExt for [T] {
fn iter_mut<'a>(&'a mut self) -> IterMut<'a, T> {
unsafe {
let p = self.as_mut_ptr();
assume(!p.is_null());
if mem::size_of::<T>() == 0 {
IterMut {ptr: p,
end: (p as usize + self.len()) as *mut T,
Expand Down