diff --git a/lib.rs b/lib.rs index d2fbbc6..4e21bf4 100644 --- a/lib.rs +++ b/lib.rs @@ -256,7 +256,7 @@ impl<'a, T: 'a + Array> Drop for Drain<'a, T> { #[cfg(feature = "union")] union SmallVecData { inline: MaybeUninit, - heap: (NonNull, usize), + heap: (*mut A::Item, usize), } #[cfg(feature = "union")] @@ -279,24 +279,22 @@ impl SmallVecData { } #[inline] unsafe fn heap(&self) -> (*mut A::Item, usize) { - (self.heap.0.as_ptr(), self.heap.1) + self.heap } #[inline] - unsafe fn heap_mut(&mut self) -> (*mut A::Item, &mut usize) { - (self.heap.0.as_ptr(), &mut self.heap.1) + unsafe fn heap_mut(&mut self) -> &mut (*mut A::Item, usize) { + &mut self.heap } #[inline] fn from_heap(ptr: *mut A::Item, len: usize) -> SmallVecData { - SmallVecData { - heap: (NonNull::new(ptr).unwrap(), len), - } + SmallVecData { heap: (ptr, len) } } } #[cfg(not(feature = "union"))] enum SmallVecData { Inline(MaybeUninit), - Heap((NonNull, usize)), + Heap((*mut A::Item, usize)), } #[cfg(not(feature = "union"))] @@ -329,20 +327,20 @@ impl SmallVecData { #[inline] unsafe fn heap(&self) -> (*mut A::Item, usize) { match self { - SmallVecData::Heap(data) => (data.0.as_ptr(), data.1), + SmallVecData::Heap(data) => *data, _ => debug_unreachable!(), } } #[inline] - unsafe fn heap_mut(&mut self) -> (*mut A::Item, &mut usize) { + unsafe fn heap_mut(&mut self) -> &mut (*mut A::Item, usize) { match self { - SmallVecData::Heap(data) => (data.0.as_ptr(), &mut data.1), + SmallVecData::Heap(data) => data, _ => debug_unreachable!(), } } #[inline] fn from_heap(ptr: *mut A::Item, len: usize) -> SmallVecData { - SmallVecData::Heap((NonNull::new(ptr).unwrap(), len)) + SmallVecData::Heap((ptr, len)) } } @@ -569,7 +567,7 @@ impl SmallVec { fn triple_mut(&mut self) -> (*mut A::Item, &mut usize, usize) { unsafe { if self.spilled() { - let (ptr, len_ptr) = self.data.heap_mut(); + let &mut (ptr, ref mut len_ptr) = self.data.heap_mut(); (ptr, len_ptr, self.capacity) } else { (self.data.inline_mut(), &mut self.capacity, A::size()) @@ -641,7 +639,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 +653,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 +759,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,9 +807,9 @@ 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); + ptr::copy(ptr.add(1), ptr, len - index - 1); item } } @@ -827,8 +825,8 @@ impl SmallVec { let len = *len_ptr; assert!(index <= len); *len_ptr = len + 1; - ptr = ptr.offset(index as isize); - ptr::copy(ptr, ptr.offset(1), len - index); + ptr = ptr.add(index); + ptr::copy(ptr, ptr.add(1), len - index); ptr::write(ptr, element); } } @@ -849,23 +847,23 @@ 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::copy(cur, cur.offset(1), old_len - index); + ptr = self.as_mut_ptr().add(index); + cur = ptr.add(num_added); + ptr::copy(cur, cur.add(1), old_len - index); } ptr::write(cur, element); num_added += 1; @@ -873,8 +871,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,11 +955,11 @@ 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); + let p_w = p_wm1.add(1); mem::swap(&mut *p_r, &mut *p_w); } w += 1; @@ -1039,8 +1037,8 @@ impl SmallVec { /// // writing into the old `SmallVec`'s inline storage on the /// // stack. /// assert!(spilled); - /// for i in 0..len as isize { - /// ptr::write(p.offset(i), 4 + i); + /// for i in 0..len { + /// ptr::write(p.add(i), 4 + i); /// } /// /// // Put everything back together into a SmallVec with a different @@ -1103,8 +1101,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()); } @@ -1156,8 +1154,8 @@ where let (ptr, len_ptr, _) = v.triple_mut(); let mut local_len = SetLenOnDrop::new(len_ptr); - for i in 0..n as isize { - ::core::ptr::write(ptr.offset(i), elem.clone()); + for i in 0..n { + ::core::ptr::write(ptr.add(i), elem.clone()); local_len.increment_len(1); } } @@ -1318,7 +1316,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 +1382,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 +1461,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 {} @@ -1528,9 +1522,9 @@ impl Iterator for IntoIter { None } else { unsafe { - let current = self.current as isize; + let current = self.current; self.current += 1; - Some(ptr::read(self.data.as_ptr().offset(current))) + Some(ptr::read(self.data.as_ptr().add(current))) } } } @@ -1550,7 +1544,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 +1607,7 @@ impl<'a> SetLenOnDrop<'a> { fn new(len: &'a mut usize) -> Self { SetLenOnDrop { local_len: *len, - len: len, + len, } } @@ -1649,7 +1643,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)]