Skip to content

Commit 0e8f5e9

Browse files
committed
Revert "Make use of NonNull"
This reverts commit 1a8a550. This didn't actually provide any size optimization benefits, and the code is slightly simpler without it.
1 parent 61b964a commit 0e8f5e9

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

lib.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ impl<'a, T: 'a + Array> Drop for Drain<'a, T> {
256256
#[cfg(feature = "union")]
257257
union SmallVecData<A: Array> {
258258
inline: MaybeUninit<A>,
259-
heap: (NonNull<A::Item>, usize),
259+
heap: (*mut A::Item, usize),
260260
}
261261

262262
#[cfg(feature = "union")]
@@ -279,24 +279,22 @@ impl<A: Array> SmallVecData<A> {
279279
}
280280
#[inline]
281281
unsafe fn heap(&self) -> (*mut A::Item, usize) {
282-
(self.heap.0.as_ptr(), self.heap.1)
282+
self.heap
283283
}
284284
#[inline]
285-
unsafe fn heap_mut(&mut self) -> (*mut A::Item, &mut usize) {
286-
(self.heap.0.as_ptr(), &mut self.heap.1)
285+
unsafe fn heap_mut(&mut self) -> &mut (*mut A::Item, usize) {
286+
&mut self.heap
287287
}
288288
#[inline]
289289
fn from_heap(ptr: *mut A::Item, len: usize) -> SmallVecData<A> {
290-
SmallVecData {
291-
heap: (NonNull::new(ptr).unwrap(), len),
292-
}
290+
SmallVecData { heap: (ptr, len) }
293291
}
294292
}
295293

296294
#[cfg(not(feature = "union"))]
297295
enum SmallVecData<A: Array> {
298296
Inline(MaybeUninit<A>),
299-
Heap((NonNull<A::Item>, usize)),
297+
Heap((*mut A::Item, usize)),
300298
}
301299

302300
#[cfg(not(feature = "union"))]
@@ -329,20 +327,20 @@ impl<A: Array> SmallVecData<A> {
329327
#[inline]
330328
unsafe fn heap(&self) -> (*mut A::Item, usize) {
331329
match self {
332-
SmallVecData::Heap(data) => (data.0.as_ptr(), data.1),
330+
SmallVecData::Heap(data) => *data,
333331
_ => debug_unreachable!(),
334332
}
335333
}
336334
#[inline]
337-
unsafe fn heap_mut(&mut self) -> (*mut A::Item, &mut usize) {
335+
unsafe fn heap_mut(&mut self) -> &mut (*mut A::Item, usize) {
338336
match self {
339-
SmallVecData::Heap(data) => (data.0.as_ptr(), &mut data.1),
337+
SmallVecData::Heap(data) => data,
340338
_ => debug_unreachable!(),
341339
}
342340
}
343341
#[inline]
344342
fn from_heap(ptr: *mut A::Item, len: usize) -> SmallVecData<A> {
345-
SmallVecData::Heap((NonNull::new(ptr).unwrap(), len))
343+
SmallVecData::Heap((ptr, len))
346344
}
347345
}
348346

@@ -569,7 +567,7 @@ impl<A: Array> SmallVec<A> {
569567
fn triple_mut(&mut self) -> (*mut A::Item, &mut usize, usize) {
570568
unsafe {
571569
if self.spilled() {
572-
let (ptr, len_ptr) = self.data.heap_mut();
570+
let &mut (ptr, ref mut len_ptr) = self.data.heap_mut();
573571
(ptr, len_ptr, self.capacity)
574572
} else {
575573
(self.data.inline_mut(), &mut self.capacity, A::size())

0 commit comments

Comments
 (0)