Deprecate offset_to; switch core&alloc to using offset_from instead

Bonus: might make code than uses `.len()` on slice iterators faster
This commit is contained in:
Scott McMurray
2018-03-31 22:35:37 -07:00
parent 80785a547d
commit b394165538
4 changed files with 19 additions and 13 deletions

View File

@@ -103,13 +103,13 @@
#![feature(lang_items)]
#![feature(needs_allocator)]
#![feature(nonzero)]
#![feature(offset_to)]
#![feature(optin_builtin_traits)]
#![feature(pattern)]
#![feature(pin)]
#![feature(placement_in_syntax)]
#![feature(placement_new_protocol)]
#![feature(ptr_internals)]
#![feature(ptr_offset_from)]
#![feature(rustc_attrs)]
#![feature(slice_get_slice)]
#![feature(slice_rsplit)]

View File

@@ -2338,9 +2338,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))
}