Skip to content
Open
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
72 changes: 18 additions & 54 deletions benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,37 +29,21 @@ trait Vector<T>: for<'valid> From<&'valid [T]> + Extend<T> + FromIterator<T> {
}

impl<T: Copy> Vector<T> for Vec<T> {
fn new() -> Self {
Self::with_capacity(VEC_SIZE)
}
fn new() -> Self { Self::with_capacity(VEC_SIZE) }

fn push(&mut self, val: T) {
self.push(val)
}
fn push(&mut self, val: T) { self.push(val) }

fn pop(&mut self) -> Option<T> {
self.pop()
}
fn pop(&mut self) -> Option<T> { self.pop() }

fn remove(&mut self, p: usize) -> T {
self.remove(p)
}
fn remove(&mut self, p: usize) -> T { self.remove(p) }

fn insert(&mut self, n: usize, val: T) {
self.insert(n, val)
}
fn insert(&mut self, n: usize, val: T) { self.insert(n, val) }

fn from_elem(val: T, n: usize) -> Self {
vec![val; n]
}
fn from_elem(val: T, n: usize) -> Self { vec![val; n] }

fn from_elems(val: &[T]) -> Self {
val.to_owned()
}
fn from_elems(val: &[T]) -> Self { val.to_owned() }

fn extend_from_slice(&mut self, other: &[T]) {
Vec::extend_from_slice(self, other)
}
fn extend_from_slice(&mut self, other: &[T]) { Vec::extend_from_slice(self, other) }

fn retain_mut<F>(&mut self, f: F)
where F: FnMut(&mut T) -> bool {
Expand All @@ -68,37 +52,21 @@ impl<T: Copy> Vector<T> for Vec<T> {
}

impl<T: Copy> Vector<T> for SmallVec<T, VEC_SIZE> {
fn new() -> Self {
Self::new()
}
fn new() -> Self { Self::new() }

fn push(&mut self, val: T) {
self.push(val)
}
fn push(&mut self, val: T) { self.push(val) }

fn pop(&mut self) -> Option<T> {
self.pop()
}
fn pop(&mut self) -> Option<T> { self.pop() }

fn remove(&mut self, p: usize) -> T {
self.remove(p)
}
fn remove(&mut self, p: usize) -> T { self.remove(p) }

fn insert(&mut self, n: usize, val: T) {
self.insert(n, val)
}
fn insert(&mut self, n: usize, val: T) { self.insert(n, val) }

fn from_elem(val: T, n: usize) -> Self {
smallvec::from_elem(val, n)
}
fn from_elem(val: T, n: usize) -> Self { smallvec::from_elem(val, n) }

fn from_elems(val: &[T]) -> Self {
SmallVec::from(val)
}
fn from_elems(val: &[T]) -> Self { SmallVec::from(val) }

fn extend_from_slice(&mut self, other: &[T]) {
SmallVec::extend(self, other)
}
fn extend_from_slice(&mut self, other: &[T]) { SmallVec::extend(self, other) }

fn retain_mut<F>(&mut self, f: F)
where F: FnMut(&mut T) -> bool {
Expand Down Expand Up @@ -188,9 +156,7 @@ make_benches! {

fn gen_push<V: Vector<u64>>(n: u64, b: &mut Bencher) {
#[inline(never)]
fn push_noinline<V: Vector<u64>>(vec: &mut V, x: u64) {
vec.push(black_box(x));
}
fn push_noinline<V: Vector<u64>>(vec: &mut V, x: u64) { vec.push(black_box(x)); }

b.iter(|| {
let n = black_box(n);
Expand Down Expand Up @@ -242,9 +208,7 @@ fn gen_insert<V: Vector<u64>>(n: u64, b: &mut Bencher) {

fn gen_remove<V: Vector<u64>>(n: usize, b: &mut Bencher) {
#[inline(never)]
fn remove_noinline<V: Vector<u64>>(vec: &mut V, p: usize) -> u64 {
vec.remove(black_box(p))
}
fn remove_noinline<V: Vector<u64>>(vec: &mut V, p: usize) -> u64 { vec.remove(black_box(p)) }

b.iter_with_setup(
|| V::from_elem(0, black_box(n)),
Expand Down
3 changes: 2 additions & 1 deletion rustfmt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ struct_lit_single_line = false
style_edition = "2024"
trailing_comma = "Never"
use_try_shorthand = true
where_single_line = true
where_single_line = true
fn_single_line = true
4 changes: 1 addition & 3 deletions src/allocator/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ pub struct Proxy<'valid, Heap: Allocator>(pub &'valid Heap);

impl<'valid, Heap: Allocator> Allocator for Proxy<'valid, Heap> {
#[inline]
fn allocate(&self, layout: Layout) -> Option<NonNull<[u8]>> {
self.0.allocate(layout)
}
fn allocate(&self, layout: Layout) -> Option<NonNull<[u8]>> { self.0.allocate(layout) }

#[inline]
unsafe fn deallocate(&self, pointer: NonNull<u8>, layout: Layout) {
Expand Down
4 changes: 1 addition & 3 deletions src/borsh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ impl<Item: BorshDeserialize, const INLINE: usize> BorshDeserialize
impl<Item: BorshSchema, const INLINE: usize, Heap: Allocator> BorshSchema
for SmallVec<Item, INLINE, Heap>
{
fn declaration() -> Declaration {
format!("Vec<{}>", Item::declaration())
}
fn declaration() -> Declaration { format!("Vec<{}>", Item::declaration()) }

fn add_definitions_recursively(definitions: &mut Map<Declaration, Definition>) {
let declaration = Self::declaration();
Expand Down
16 changes: 4 additions & 12 deletions src/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,27 +48,21 @@ impl<Item: Clone, const INLINE: usize> From<&[Item]> for SmallVec<Item, INLINE,

impl<Item: Clone, const INLINE: usize> From<&mut [Item]> for SmallVec<Item, INLINE, Global> {
#[inline]
fn from(slice: &mut [Item]) -> Self {
Self::from(slice as &[Item])
}
fn from(slice: &mut [Item]) -> Self { Self::from(slice as &[Item]) }
}

impl<Item: Clone, const M: usize, const INLINE: usize> From<&[Item; M]>
for SmallVec<Item, INLINE, Global>
{
#[inline]
fn from(slice: &[Item; M]) -> Self {
Self::from(slice as &[Item])
}
fn from(slice: &[Item; M]) -> Self { Self::from(slice as &[Item]) }
}

impl<Item: Clone, const M: usize, const INLINE: usize> From<&mut [Item; M]>
for SmallVec<Item, INLINE, Global>
{
#[inline]
fn from(slice: &mut [Item; M]) -> Self {
Self::from(slice as &[Item])
}
fn from(slice: &mut [Item; M]) -> Self { Self::from(slice as &[Item]) }
}

impl<Item, const INLINE: usize, const M: usize> From<[Item; M]> for SmallVec<Item, INLINE, Global> {
Expand Down Expand Up @@ -207,7 +201,5 @@ impl<Item, const INLINE: usize, Heap: Allocator> From<SmallVec<Item, INLINE, Hea
}

impl<T, const N: usize> From<<Box<[T], Global> as Like>::Type> for SmallVec<T, N> {
fn from(boxed: <Box<[T], Global> as Like>::Type) -> Self {
boxed.into_vec().into()
}
fn from(boxed: <Box<[T], Global> as Like>::Type) -> Self { boxed.into_vec().into() }
}
4 changes: 1 addition & 3 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ pub enum SmallVecError {
}

impl Display for SmallVecError {
fn fmt(&self, f: &mut Formatter<'_>) -> Format {
write!(f, "Allocation error: {self:?}")
}
fn fmt(&self, f: &mut Formatter<'_>) -> Format { write!(f, "Allocation error: {self:?}") }
}

impl Error for SmallVecError {}
Expand Down
16 changes: 4 additions & 12 deletions src/iterators/drain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,7 @@ impl<'valid, Item: 'valid, const INLINE: usize, Heap: Allocator> Iterator
}

#[inline]
fn size_hint(&self) -> (usize, Option<usize>) {
self.iter.size_hint()
}
fn size_hint(&self) -> (usize, Option<usize>) { self.iter.size_hint() }
}

impl<'valid, Item: 'valid, const INLINE: usize, Heap: Allocator> DoubleEndedIterator
Expand All @@ -86,9 +84,7 @@ impl<Item, const INLINE: usize, Heap: Allocator> ExactSizeIterator
for Drain<'_, Item, INLINE, Heap>
{
#[inline]
fn len(&self) -> usize {
self.iter.len()
}
fn len(&self) -> usize { self.iter.len() }
}

impl<Item, const INLINE: usize, Heap: Allocator> FusedIterator for Drain<'_, Item, INLINE, Heap> {}
Expand Down Expand Up @@ -182,9 +178,7 @@ impl<'valid, Item, const INLINE: usize, Heap: Allocator> AsRef<[Item]>
for Drain<'valid, Item, INLINE, Heap>
{
#[inline]
fn as_ref(&self) -> &[Item] {
self.iter.as_slice()
}
fn as_ref(&self) -> &[Item] { self.iter.as_slice() }
}

impl<Item, const INLINE: usize, Heap: Allocator> Drain<'_, Item, INLINE, Heap> {
Expand All @@ -193,9 +187,7 @@ impl<Item, const INLINE: usize, Heap: Allocator> Drain<'_, Item, INLINE, Heap> {
note = "use `<Drain<'_, Item, INLINE, Heap> as AsRef<[Item]>>::as_ref` instead"
)]
#[must_use]
pub fn as_slice(&self) -> &[Item] {
self.as_ref()
}
pub fn as_slice(&self) -> &[Item] { self.as_ref() }

/// The range from `self.vec.length` to `self.tail_start` contains elements
/// that have been moved out.
Expand Down
4 changes: 1 addition & 3 deletions src/iterators/extractif.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,7 @@ where F: FnMut(&mut Item) -> bool
}
}

fn size_hint(&self) -> (usize, Option<usize>) {
(0, Some(self.end - self.idx))
}
fn size_hint(&self) -> (usize, Option<usize>) { (0, Some(self.end - self.idx)) }
}

impl<Item, F, const INLINE: usize, Heap: Allocator> Drop for ExtractIf<'_, Item, INLINE, F, Heap>
Expand Down
12 changes: 3 additions & 9 deletions src/iterators/intoiter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,23 +98,17 @@ impl<Item, const INLINE: usize, Heap: Allocator> IntoIter<Item, INLINE, Heap> {
note = "use `<IntoIter<Item, INLINE, Heap> as AsRef<[Item]>>::as_ref` instead"
)]
#[inline]
pub fn as_slice(&self) -> &[Item] {
self.as_ref()
}
pub fn as_slice(&self) -> &[Item] { self.as_ref() }

#[deprecated(
since = "2.0.0-beta.3",
note = "use `<IntoIter<Item, INLINE, Heap> as AsMut<[Item]>>::as_mut` instead"
)]
#[inline]
pub fn as_mut_slice(&mut self) -> &mut [Item] {
self.as_mut()
}
pub fn as_mut_slice(&mut self) -> &mut [Item] { self.as_mut() }

#[cfg(feature = "specialization")]
pub(crate) fn mark_consumed(&mut self) {
self.begin = self.end.len();
}
pub(crate) fn mark_consumed(&mut self) { self.begin = self.end.len(); }
}

impl<Item, const INLINE: usize, Heap: Allocator> Iterator for IntoIter<Item, INLINE, Heap> {
Expand Down
16 changes: 4 additions & 12 deletions src/iterators/rayon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,11 @@ impl<Item> DoubleEndedIterator for SliceDrain<'_, Item> {
}

impl<Item> ExactSizeIterator for SliceDrain<'_, Item> {
fn len(&self) -> usize {
self.0.len()
}
fn len(&self) -> usize { self.0.len() }
}

impl<Item> Drop for SliceDrain<'_, Item> {
fn drop(&mut self) {
unsafe { drop_in_place(take(&mut self.0).into_slice()) };
}
fn drop(&mut self) { unsafe { drop_in_place(take(&mut self.0).into_slice()) }; }
}

struct DrainProducer<'valid, Item>(&'valid mut [Item]);
Expand All @@ -60,9 +56,7 @@ impl<'valid, Item: Send> Producer for DrainProducer<'valid, Item> {
type IntoIter = SliceDrain<'valid, Item>;
type Item = Item;

fn into_iter(mut self) -> SliceDrain<'valid, Item> {
SliceDrain(take(&mut self.0).iter_mut())
}
fn into_iter(mut self) -> SliceDrain<'valid, Item> { SliceDrain(take(&mut self.0).iter_mut()) }

fn split_at(mut self, index: usize) -> (Self, Self) {
let (left, right) = take(&mut self.0).split_at_mut(index);
Expand All @@ -72,9 +66,7 @@ impl<'valid, Item: Send> Producer for DrainProducer<'valid, Item> {
}

impl<Item> Drop for DrainProducer<'_, Item> {
fn drop(&mut self) {
unsafe { drop_in_place(self.0) };
}
fn drop(&mut self) { unsafe { drop_in_place(self.0) }; }
}

impl<Item: Send, const INLINE: usize, Heap: Allocator + Send> ParallelIterator
Expand Down
12 changes: 3 additions & 9 deletions src/iterators/splice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,15 @@ where
impl<I: Iterator, const INLINE: usize, Heap: Allocator> Iterator for Splice<'_, I, INLINE, Heap> {
type Item = I::Item;

fn next(&mut self) -> Option<Self::Item> {
self.drain.next()
}
fn next(&mut self) -> Option<Self::Item> { self.drain.next() }

fn size_hint(&self) -> (usize, Option<usize>) {
self.drain.size_hint()
}
fn size_hint(&self) -> (usize, Option<usize>) { self.drain.size_hint() }
}

impl<I: Iterator, const INLINE: usize, Heap: Allocator> DoubleEndedIterator
for Splice<'_, I, INLINE, Heap>
{
fn next_back(&mut self) -> Option<Self::Item> {
self.drain.next_back()
}
fn next_back(&mut self) -> Option<Self::Item> { self.drain.next_back() }
}

impl<I: Iterator, const INLINE: usize, Heap: Allocator> ExactSizeIterator
Expand Down
Loading
Loading