Skip to content

Commit 9e9881b

Browse files
committed
cleanup
1 parent 31e7990 commit 9e9881b

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

library/alloc/src/raw_vec.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -168,15 +168,9 @@ impl<T, A: Allocator> RawVec<T, A> {
168168

169169
#[cfg(not(no_global_oom_handling))]
170170
fn allocate_in(capacity: usize, init: AllocInit, alloc: A) -> Self {
171-
if mem::size_of::<T>() == 0 {
171+
// Don't allocate here because `Drop` will not deallocate when `capacity` is 0.
172+
if mem::size_of::<T>() == 0 || capacity == 0 {
172173
Self::new_in(alloc)
173-
} else if capacity == 0 {
174-
// Don't allocate here because `Drop` will not deallocate when `capacity` is 0.
175-
Self {
176-
ptr: unsafe { Unique::new_unchecked(NonNull::dangling().as_ptr()) },
177-
cap: capacity,
178-
alloc,
179-
}
180174
} else {
181175
// We avoid `unwrap_or_else` here because it bloats the amount of
182176
// LLVM IR generated.

0 commit comments

Comments
 (0)