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
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
toolchain: nightly
nightly: true
- name: MSRV
toolchain: "1.83.0"
toolchain: "1.86.0"
- name: no_std
toolchain: stable
target: thumbv7m-none-eabi
Expand Down
136 changes: 66 additions & 70 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[package]
name = "smallvec"
version = "2.0.0-alpha.12"
edition = "2021"
rust-version = "1.83"
edition = "2024"
rust-version = "1.86"
authors = ["The Servo Project Developers"]
license = "MIT OR Apache-2.0"
repository = "https://github.com/servo/rust-smallvec"
Expand All @@ -28,7 +28,7 @@ malloc_size_of = { version = "0.1", optional = true, default-features = false }

[dev-dependencies]
serde_test = "1.0"
criterion = "0.4"
criterion = "0.8"

[[test]]
name = "arbitrary"
Expand Down
30 changes: 17 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,15 +253,15 @@ impl<T, const N: usize> RawSmallVec<T, N> {
/// The vector must be on the heap
#[inline]
const unsafe fn as_ptr_heap(&self) -> *const T {
self.heap.0.as_ptr()
return unsafe { self.heap.0.as_ptr() };
}

/// # Safety
///
/// The vector must be on the heap
#[inline]
const unsafe fn as_mut_ptr_heap(&mut self) -> *mut T {
self.heap.0.as_ptr()
return unsafe { self.heap.0.as_ptr() };
}

/// # Safety
Expand All @@ -283,7 +283,7 @@ impl<T, const N: usize> RawSmallVec<T, N> {

let was_on_heap = len.on_heap();
let ptr = if was_on_heap {
self.as_mut_ptr_heap()
unsafe { self.as_mut_ptr_heap() }
} else {
self.as_mut_ptr_inline()
};
Expand All @@ -297,27 +297,29 @@ impl<T, const N: usize> RawSmallVec<T, N> {

let new_ptr = if !was_on_heap {
// get a fresh allocation
let new_ptr = alloc(new_layout) as *mut T; // `new_layout` has nonzero size.
let new_ptr = unsafe { alloc(new_layout) } as *mut T; // `new_layout` has nonzero size.
let new_ptr = NonNull::new(new_ptr).ok_or(CollectionAllocErr::AllocErr {
layout: new_layout
})?;
copy_nonoverlapping(ptr, new_ptr.as_ptr(), len);
unsafe { copy_nonoverlapping(ptr, new_ptr.as_ptr(), len) };
new_ptr
} else {
// use realloc

// this can't overflow since we already constructed an equivalent
// layout during the previous allocation
let old_layout =
Layout::from_size_align_unchecked(self.heap.1 * size_of::<T>(), align_of::<T>());
let old_layout = unsafe {
Layout::from_size_align_unchecked(self.heap.1 * size_of::<T>(), align_of::<T>())
};

// SAFETY: ptr was allocated with this allocator
// old_layout is the same as the layout used to allocate the
// previous memory block new_layout.size() is greater
// than zero does not overflow when rounded up to
// alignment. since it was constructed
// with Layout::array
let new_ptr = realloc(ptr as *mut u8, old_layout, new_layout.size()) as *mut T;
let new_ptr =
unsafe { realloc(ptr as *mut u8, old_layout, new_layout.size()) } as *mut T;
NonNull::new(new_ptr).ok_or(CollectionAllocErr::AllocErr {
layout: new_layout
})?
Expand Down Expand Up @@ -561,8 +563,10 @@ impl<T, const N: usize> Drain<'_, T, N> {

for place in range_slice {
if let Some(new_item) = replace_with.next() {
unsafe { core::ptr::write(place, new_item) };
vec.set_len(vec.len() + 1);
unsafe {
core::ptr::write(place, new_item);
vec.set_len(vec.len() + 1);
}
} else {
return false;
}
Expand All @@ -578,9 +582,9 @@ impl<T, const N: usize> Drain<'_, T, N> {

// Test
let old_len = vec.len();
vec.set_len(len);
unsafe { vec.set_len(len) }
vec.reserve(additional);
vec.set_len(old_len);
unsafe { vec.set_len(old_len) };

let new_tail_start = self.tail_start + additional;
unsafe {
Expand Down Expand Up @@ -3162,7 +3166,7 @@ unsafe impl<const N: usize> BufMut for SmallVec<u8, N> {
}

// Addition will not overflow since the sum is at most the capacity.
self.set_len(len + cnt);
unsafe { self.set_len(len + cnt) };
}

#[inline]
Expand Down
Loading