Skip to content

Commit

Permalink
Revert "Make use of NonNull"
Browse files Browse the repository at this point in the history
This reverts commit 1a8a550.

This didn't actually provide any size optimization benefits, and the
code is slightly simpler without it.
  • Loading branch information
mbrubeck committed Oct 31, 2019
1 parent 61b964a commit 0e8f5e9
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions lib.rs
Expand Up @@ -256,7 +256,7 @@ impl<'a, T: 'a + Array> Drop for Drain<'a, T> {
#[cfg(feature = "union")]
union SmallVecData<A: Array> {
inline: MaybeUninit<A>,
heap: (NonNull<A::Item>, usize),
heap: (*mut A::Item, usize),
}

#[cfg(feature = "union")]
Expand All @@ -279,24 +279,22 @@ impl<A: Array> SmallVecData<A> {
}
#[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<A> {
SmallVecData {
heap: (NonNull::new(ptr).unwrap(), len),
}
SmallVecData { heap: (ptr, len) }
}
}

#[cfg(not(feature = "union"))]
enum SmallVecData<A: Array> {
Inline(MaybeUninit<A>),
Heap((NonNull<A::Item>, usize)),
Heap((*mut A::Item, usize)),
}

#[cfg(not(feature = "union"))]
Expand Down Expand Up @@ -329,20 +327,20 @@ impl<A: Array> SmallVecData<A> {
#[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<A> {
SmallVecData::Heap((NonNull::new(ptr).unwrap(), len))
SmallVecData::Heap((ptr, len))
}
}

Expand Down Expand Up @@ -569,7 +567,7 @@ impl<A: Array> SmallVec<A> {
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())
Expand Down

0 comments on commit 0e8f5e9

Please sign in to comment.