some SmallVec methods use assertions that rely on a helper function marked as #[cold] and never inlined. this is to improve cache locality
take all the helper functions like that, rename them, and put it in an assertions.rs module
example in SmallVec::remove:
#[inline]
pub fn remove(&mut self, index: usize) -> T {
#[cold]
#[inline(never)]
#[track_caller]
fn assert_failed(index: usize, len: usize) -> ! {
panic!("removal index (is {index}) should be < len (is {len})");
}
let len = self.len();
if index >= len {
assert_failed(index, len);
}
let new_len = len - 1;
unsafe {
// SAFETY: new_len < len
self.set_len(new_len);
let ptr = self.as_mut_ptr();
let ith = ptr.add(index);
// This item is initialized since index < len
let ith_item = ith.read();
copy(ith.add(1), ith, new_len - index);
ith_item
}
}
some
SmallVecmethods use assertions that rely on a helper function marked as#[cold]and never inlined. this is to improve cache localitytake all the helper functions like that, rename them, and put it in an
assertions.rsmoduleexample in
SmallVec::remove: