Skip to content

Make the slice iterator optimise better. #21448

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

Closed
wants to merge 1 commit into from
Closed
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
10 changes: 10 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;
use iter::*;
use marker::Copy;
use num::Int;
Expand Down Expand Up @@ -690,6 +691,13 @@ macro_rules! iterator {
let old = self.ptr;
self.ptr = self.ptr.offset(1);

// LLVM doesn't properly recognise that
// the `&` is never null without this, and
// so doesn't see that the Option we
// create here is always Some, due to the
// null-pointer optimisation.
intrinsics::assume(!old.is_null());

Some(transmute(old))
}
}
Expand Down Expand Up @@ -723,6 +731,8 @@ macro_rules! iterator {
} else {
self.end = self.end.offset(-1);

// see above
intrinsics::assume(!self.end.is_null());
Some(transmute(self.end))
}
}
Expand Down