diff --git a/lib.rs b/lib.rs index d2fbbc6..87172d2 100644 --- a/lib.rs +++ b/lib.rs @@ -641,7 +641,7 @@ impl SmallVec { } let (ptr, len_ptr, _) = self.triple_mut(); *len_ptr = len + 1; - ptr::write(ptr.offset(len as isize), value); + ptr::write(ptr.add(len), value); } } @@ -655,7 +655,7 @@ impl SmallVec { } let last_index = *len_ptr - 1; *len_ptr = last_index; - Some(ptr::read(ptr.offset(last_index as isize))) + Some(ptr::read(ptr.add(last_index))) } } @@ -761,7 +761,7 @@ impl SmallVec { while len < *len_ptr { let last_index = *len_ptr - 1; *len_ptr = last_index; - ptr::drop_in_place(ptr.offset(last_index as isize)); + ptr::drop_in_place(ptr.add(last_index)); } } } @@ -809,7 +809,7 @@ impl SmallVec { let len = *len_ptr; assert!(index < len); *len_ptr = len - 1; - ptr = ptr.offset(index as isize); + ptr = ptr.add(index); let item = ptr::read(ptr); ptr::copy(ptr.offset(1), ptr, len - index - 1); item @@ -827,7 +827,7 @@ impl SmallVec { let len = *len_ptr; assert!(index <= len); *len_ptr = len + 1; - ptr = ptr.offset(index as isize); + ptr = ptr.add(index); ptr::copy(ptr, ptr.offset(1), len - index); ptr::write(ptr, element); } @@ -849,22 +849,22 @@ impl SmallVec { unsafe { let old_len = self.len(); assert!(index <= old_len); - let mut ptr = self.as_mut_ptr().offset(index as isize); + let mut ptr = self.as_mut_ptr().add(index); // Move the trailing elements. - ptr::copy(ptr, ptr.offset(lower_size_bound as isize), old_len - index); + ptr::copy(ptr, ptr.add(lower_size_bound), old_len - index); // In case the iterator panics, don't double-drop the items we just copied above. self.set_len(index); let mut num_added = 0; for element in iter { - let mut cur = ptr.offset(num_added as isize); + let mut cur = ptr.add(num_added); if num_added >= lower_size_bound { // Iterator provided more elements than the hint. Move trailing items again. self.reserve(1); - ptr = self.as_mut_ptr().offset(index as isize); - cur = ptr.offset(num_added as isize); + ptr = self.as_mut_ptr().add(index); + cur = ptr.add(num_added); ptr::copy(cur, cur.offset(1), old_len - index); } ptr::write(cur, element); @@ -873,8 +873,8 @@ impl SmallVec { if num_added < lower_size_bound { // Iterator provided fewer elements than the hint ptr::copy( - ptr.offset(lower_size_bound as isize), - ptr.offset(num_added as isize), + ptr.add(lower_size_bound), + ptr.add(num_added), old_len - index, ); } @@ -957,8 +957,8 @@ impl SmallVec { unsafe { for r in 1..len { - let p_r = ptr.offset(r as isize); - let p_wm1 = ptr.offset((w - 1) as isize); + let p_r = ptr.add(r); + let p_wm1 = ptr.add(w - 1); if !same_bucket(&mut *p_r, &mut *p_wm1) { if r != w { let p_w = p_wm1.offset(1); @@ -1103,8 +1103,8 @@ where unsafe { let slice_ptr = slice.as_ptr(); - let ptr = self.as_mut_ptr().offset(index as isize); - ptr::copy(ptr, ptr.offset(slice.len() as isize), len - index); + let ptr = self.as_mut_ptr().add(index); + ptr::copy(ptr, ptr.add(slice.len()), len - index); ptr::copy_nonoverlapping(slice_ptr, ptr, slice.len()); self.set_len(len + slice.len()); } @@ -1318,7 +1318,7 @@ where #[cfg(not(feature = "specialization"))] #[inline] fn from(slice: &'a [A::Item]) -> SmallVec { - slice.into_iter().cloned().collect() + slice.iter().cloned().collect() } #[cfg(feature = "specialization")] @@ -1384,7 +1384,7 @@ impl Extend for SmallVec { let mut len = SetLenOnDrop::new(len_ptr); while len.get() < cap { if let Some(out) = iter.next() { - ptr::write(ptr.offset(len.get() as isize), out); + ptr::write(ptr.add(len.get()), out); len.increment_len(1); } else { return; @@ -1463,10 +1463,6 @@ where fn eq(&self, other: &SmallVec) -> bool { self[..] == other[..] } - #[inline] - fn ne(&self, other: &SmallVec) -> bool { - self[..] != other[..] - } } impl Eq for SmallVec where A::Item: Eq {} @@ -1550,7 +1546,7 @@ impl DoubleEndedIterator for IntoIter { } else { unsafe { self.end -= 1; - Some(ptr::read(self.data.as_ptr().offset(self.end as isize))) + Some(ptr::read(self.data.as_ptr().add(self.end))) } } } @@ -1613,7 +1609,7 @@ impl<'a> SetLenOnDrop<'a> { fn new(len: &'a mut usize) -> Self { SetLenOnDrop { local_len: *len, - len: len, + len, } } @@ -1649,7 +1645,7 @@ macro_rules! impl_array( impl_array!( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 20, 24, 32, 36, 0x40, 0x60, 0x80, 0x100, 0x200, 0x400, 0x600, 0x800, 0x1000, 0x2000, 0x4000, 0x6000, 0x8000, 0x10000, 0x20000, - 0x40000, 0x60000, 0x80000, 0x100000 + 0x40000, 0x60000, 0x80000, 0x10_0000 ); #[cfg(test)]