Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ impl<Item, const INLINE: usize> SmallVec<Item, INLINE, Global> {
// Although we create a new buffer, since S and INLINE are known at
// compile time, even with `-C opt-level=1`, it gets optimized
// as best as it could be. (Checked with <godbolt.org>)
let mut buf: MaybeUninit<[Item; INLINE]> = MaybeUninit::uninit();
let mut buf: [MaybeUninit<Item>; INLINE] = [const { MaybeUninit::uninit() }; INLINE];

// SAFETY: buf and elements do not overlap, are aligned and have space
// for at least S elements since S <= INLINE.
Expand All @@ -156,7 +156,7 @@ impl<Item, const INLINE: usize> SmallVec<Item, INLINE, Global> {
// SAFETY: all the members in 0..S are initialized
Self {
length: LocatedLength::new(S, false),
raw: RawSmallVec::new_inline(buf),
raw: RawSmallVec::inline(buf),
allocator: Global
}
}
Expand All @@ -167,7 +167,7 @@ impl<Item, const INLINE: usize> SmallVec<Item, INLINE, Global> {
// SAFETY: all the members in 0..length are initialized
let mut vec = Self {
length: LocatedLength::new(length, false),
raw: RawSmallVec::new_inline(MaybeUninit::new(buf)),
raw: RawSmallVec::inline(buf.map(MaybeUninit::new)),
allocator: Global
};
// Deallocate the remaining elements so no memory is leaked.
Expand Down Expand Up @@ -201,9 +201,9 @@ impl<Item, const INLINE: usize> SmallVec<Item, INLINE, Global> {
/// };
///
/// let buf = [1, 2, 3, 4, 5, 0, 0, 0];
/// let small_vec = unsafe { SmallVec::from_buf_and_len_unchecked(MaybeUninit::new(buf), 5) };
/// let sv = unsafe { SmallVec::from_buf_and_len_unchecked(buf.map(MaybeUninit::new), 5) };
///
/// assert_eq!(&*small_vec, &[1, 2, 3, 4, 5]);
/// assert_eq!(&*sv, &[1, 2, 3, 4, 5]);
/// ```
///
/// # Safety
Expand All @@ -212,13 +212,13 @@ impl<Item, const INLINE: usize> SmallVec<Item, INLINE, Global> {
/// initialized
#[inline]
pub const unsafe fn from_buf_and_len_unchecked(
buf: MaybeUninit<[Item; INLINE]>,
buf: [MaybeUninit<Item>; INLINE],
length: usize
) -> Self {
debug_assert!(length <= INLINE);
Self {
length: LocatedLength::new(length, false),
raw: RawSmallVec::new_inline(buf),
raw: RawSmallVec::inline(buf),
allocator: Global
}
}
Expand Down Expand Up @@ -264,7 +264,7 @@ impl<Item, const INLINE: usize> SmallVec<Item, INLINE, Global> {

Self {
length: LocatedLength::new(length, true),
raw: RawSmallVec::new_heap(ptr, cap),
raw: RawSmallVec::heap(ptr, cap),
allocator: Global
}
}
Expand Down Expand Up @@ -350,7 +350,7 @@ impl<Item, const INLINE: usize> SmallVec<Item, INLINE, Global> {

SmallVec {
length: LocatedLength::new(length, true),
raw: RawSmallVec::new_heap(ptr, capacity),
raw: RawSmallVec::heap(ptr, capacity),
allocator: Global
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/rawsmallvec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use {

#[repr(C)]
pub union RawSmallVec<Item, const INLINE: usize> {
pub inline: ManuallyDrop<MaybeUninit<[Item; INLINE]>>,
pub inline: ManuallyDrop<[MaybeUninit<Item>; INLINE]>,
pub heap: (NonNull<Item>, usize)
}

Expand All @@ -29,18 +29,18 @@ impl<Item, const INLINE: usize> RawSmallVec<Item, INLINE> {

#[inline]
pub const fn new() -> Self {
Self::new_inline(MaybeUninit::uninit())
Self::inline([const { MaybeUninit::uninit() }; INLINE])
}

#[inline]
pub const fn new_inline(inline: MaybeUninit<[Item; INLINE]>) -> Self {
pub const fn inline(inline: [MaybeUninit<Item>; INLINE]) -> Self {
Self {
inline: ManuallyDrop::new(inline)
}
}

#[inline]
pub const fn new_heap(ptr: NonNull<Item>, capacity: usize) -> Self {
pub const fn heap(ptr: NonNull<Item>, capacity: usize) -> Self {
Self {
heap: (ptr, capacity)
}
Expand Down
Loading