diff options
| author | bors <bors@rust-lang.org> | 2018-04-12 08:29:10 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2018-04-12 08:29:10 +0000 |
| commit | 9afed646451175e24964cc76688293cb87ed718c (patch) | |
| tree | ff518211ee157f47f822f7652c053251b34ccf2f /src/liballoc | |
| parent | 252a459d373f40512ed9137d59e4b6bea5d6aaee (diff) | |
| parent | b394165538bc52063f79a1820135cfefa19370e7 (diff) | |
| download | rust-9afed646451175e24964cc76688293cb87ed718c.tar.gz rust-9afed646451175e24964cc76688293cb87ed718c.zip | |
Auto merge of #49551 - scottmcm:deprecate-offset_to, r=KodrAus
Deprecate offset_to; switch core&alloc to using offset_from instead Bonus: might make code than uses `.len()` on slice iterators faster cc https://github.com/rust-lang/rust/issues/41079
Diffstat (limited to 'src/liballoc')
| -rw-r--r-- | src/liballoc/lib.rs | 2 | ||||
| -rw-r--r-- | src/liballoc/vec.rs | 7 |
2 files changed, 5 insertions, 4 deletions
diff --git a/src/liballoc/lib.rs b/src/liballoc/lib.rs index 69fc007ab7c..5ca39442342 100644 --- a/src/liballoc/lib.rs +++ b/src/liballoc/lib.rs @@ -99,11 +99,11 @@ #![feature(lang_items)] #![feature(needs_allocator)] #![feature(nonzero)] -#![feature(offset_to)] #![feature(optin_builtin_traits)] #![feature(pattern)] #![feature(pin)] #![feature(ptr_internals)] +#![feature(ptr_offset_from)] #![feature(rustc_attrs)] #![feature(slice_get_slice)] #![feature(slice_rsplit)] diff --git a/src/liballoc/vec.rs b/src/liballoc/vec.rs index 4b883b5bce7..0f74743ca49 100644 --- a/src/liballoc/vec.rs +++ b/src/liballoc/vec.rs @@ -2394,9 +2394,10 @@ impl<T> Iterator for IntoIter<T> { #[inline] fn size_hint(&self) -> (usize, Option<usize>) { - let exact = match self.ptr.offset_to(self.end) { - Some(x) => x as usize, - None => (self.end as usize).wrapping_sub(self.ptr as usize), + let exact = if mem::size_of::<T>() == 0 { + (self.end as usize).wrapping_sub(self.ptr as usize) + } else { + unsafe { self.end.offset_from(self.ptr) as usize } }; (exact, Some(exact)) } |
