diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2015-02-18 14:31:21 -0800 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2015-02-18 14:31:21 -0800 |
| commit | fa30c4f147865bea8a8b4c652827330f7f011ebd (patch) | |
| tree | 28ada1feea39cb5f455b30ab44d0438600020909 /src | |
| parent | dfc5c0f1e8799f47f9033bdcc8a7cd8a217620a5 (diff) | |
| parent | 7412d1b2eff1c77241c54fa39508e7049d71ec7e (diff) | |
| download | rust-fa30c4f147865bea8a8b4c652827330f7f011ebd.tar.gz rust-fa30c4f147865bea8a8b4c652827330f7f011ebd.zip | |
rollup merge of #21886: dotdash/fast_slice_iter
The data pointer used in the slice is never null, using assume() to tell LLVM about it gets rid of various unneeded null checks when iterating over the slice. Since the snapshot compiler is still using an older LLVM version, omit the call in stage0, because compile times explode otherwise. Benchmarks from #18193 ```` running 5 tests test _range ... bench: 33329 ns/iter (+/- 417) test assembly ... bench: 33299 ns/iter (+/- 58) test enumerate ... bench: 33318 ns/iter (+/- 83) test iter ... bench: 33311 ns/iter (+/- 130) test position ... bench: 33300 ns/iter (+/- 47) test result: ok. 0 passed; 0 failed; 0 ignored; 5 measured ```` Fixes #18193
Diffstat (limited to 'src')
| -rw-r--r-- | src/libcollections/vec.rs | 7 | ||||
| -rw-r--r-- | src/libcore/ptr.rs | 4 |
2 files changed, 8 insertions, 3 deletions
diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index bde733644b5..25226afd8c9 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -56,6 +56,7 @@ use core::cmp::{Ordering}; use core::default::Default; use core::fmt; use core::hash::{self, Hash}; +use core::intrinsics::assume; use core::iter::{repeat, FromIterator, IntoIterator}; use core::marker::{self, ContravariantLifetime, InvariantType}; use core::mem; @@ -1587,8 +1588,12 @@ impl<T> AsSlice<T> for Vec<T> { #[stable(feature = "rust1", since = "1.0.0")] fn as_slice(&self) -> &[T] { unsafe { + let p = *self.ptr; + if cfg!(not(stage0)) { // NOTE remove cfg after next snapshot + assume(p != 0 as *mut T); + } mem::transmute(RawSlice { - data: *self.ptr, + data: p, len: self.len }) } diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index 072c60c7036..2779e67c743 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -303,7 +303,7 @@ impl<T> PtrExt for *const T { #[inline] #[stable(feature = "rust1", since = "1.0.0")] - fn is_null(self) -> bool { self as usize == 0 } + fn is_null(self) -> bool { self == 0 as *const T } #[inline] #[stable(feature = "rust1", since = "1.0.0")] @@ -330,7 +330,7 @@ impl<T> PtrExt for *mut T { #[inline] #[stable(feature = "rust1", since = "1.0.0")] - fn is_null(self) -> bool { self as usize == 0 } + fn is_null(self) -> bool { self == 0 as *mut T } #[inline] #[stable(feature = "rust1", since = "1.0.0")] |
