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/vec.rs | |
| 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/vec.rs')
| -rw-r--r-- | src/liballoc/vec.rs | 7 |
1 files changed, 4 insertions, 3 deletions
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)) } |
