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
11 changes: 7 additions & 4 deletions src/borsh.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use {
super::{
Allocator,
Global,
SmallVec
SmallVec,
allocator::{
Allocator,
global::Global
}
},
alloc::{
collections::BTreeMap as Map,
Expand All @@ -15,6 +17,7 @@ use {
io::{
Error,
ErrorKind,
Read,
Result as Serial,
Write
},
Expand Down Expand Up @@ -42,7 +45,7 @@ impl<Item: BorshSerialize, const INLINE: usize, Heap: Allocator> BorshSerialize
impl<Item: BorshDeserialize, const INLINE: usize> BorshDeserialize
for SmallVec<Item, INLINE, Global>
{
fn deserialize_reader<R: borsh::io::Read>(reader: &mut R) -> Serial<Self> {
fn deserialize_reader<R: Read>(reader: &mut R) -> Serial<Self> {
let length = u64::deserialize_reader(reader)?;
repeat_with(|| Item::deserialize_reader(reader))
.take(length.try_into().map_err(|_| Error::new(
Expand Down
13 changes: 7 additions & 6 deletions src/comparisons.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use {
crate::{
Allocator,
SmallVec
super::{
SmallVec,
allocator::Allocator
},
alloc::{
borrow::Cow,
collections::VecDeque,
vec::Vec
}
},
core::cmp::Ordering
};

macro_rules! __impl_slice_eq1 {
Expand Down Expand Up @@ -62,7 +63,7 @@ impl<Item, const INLINE: usize, Heap: Allocator> PartialOrd for SmallVec<Item, I
where Item: PartialOrd
{
#[inline]
fn partial_cmp(&self, other: &SmallVec<Item, INLINE, Heap>) -> Option<core::cmp::Ordering> {
fn partial_cmp(&self, other: &SmallVec<Item, INLINE, Heap>) -> Option<Ordering> {
self.as_ref().partial_cmp(other.as_ref())
}
}
Expand All @@ -71,7 +72,7 @@ impl<Item, const INLINE: usize, Heap: Allocator> Ord for SmallVec<Item, INLINE,
where Item: Ord
{
#[inline]
fn cmp(&self, other: &SmallVec<Item, INLINE, Heap>) -> core::cmp::Ordering {
fn cmp(&self, other: &SmallVec<Item, INLINE, Heap>) -> Ordering {
self.as_ref().cmp(other.as_ref())
}
}
16 changes: 10 additions & 6 deletions src/conversions.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
#[cfg(feature = "specialization")]
use super::specialization::SpecFromSlice;
use {
crate::{
Allocator,
Box,
Global,
super::{
SmallVec,
Vec
allocator::{
Allocator,
boxed::Box,
global::Global,
vec::Vec
}
},
core::{
mem::ManuallyDrop,
Expand All @@ -24,7 +28,7 @@ impl<Item: Clone, const INLINE: usize> From<&[Item]> for SmallVec<Item, INLINE,
unsafe {
#[cfg(feature = "specialization")]
{
<Self as crate::specialization::SpecFromSlice<Item>>::spec_from(slice)
<Self as SpecFromSlice<Item>>::spec_from(slice)
}

#[cfg(not(feature = "specialization"))]
Expand Down
58 changes: 36 additions & 22 deletions src/iterators/drain.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,27 @@
use crate::{
Allocator,
Global,
SmallVec,
SmallVecError
use {
super::super::{
SmallVec,
allocator::{
Allocator,
global::Global
},
errors::SmallVecError
},
core::{
fmt::{
Debug,
Formatter,
Result as Format
},
iter::FusedIterator,
mem::take,
ptr::{
NonNull,
copy,
slice_from_raw_parts_mut
},
slice::Iter
}
};

/// An iterator that removes the items from a `SmallVec` and yields them by
Expand All @@ -21,8 +40,8 @@ pub struct Drain<'valid, Item: 'valid, const INLINE: usize, Heap: Allocator = Gl
// even though vec has length < tail_start
pub(crate) tail_start: usize,
pub(crate) tail_len: usize,
pub(crate) iter: core::slice::Iter<'valid, Item>,
pub(crate) vec: core::ptr::NonNull<SmallVec<Item, INLINE, Heap>>
pub(crate) iter: Iter<'valid, Item>,
pub(crate) vec: NonNull<SmallVec<Item, INLINE, Heap>>
}

impl<'valid, Item: 'valid, const INLINE: usize, Heap: Allocator> Iterator
Expand All @@ -36,7 +55,7 @@ impl<'valid, Item: 'valid, const INLINE: usize, Heap: Allocator> Iterator
// items, and we can take ownership of them.
self.iter
.next()
.map(|reference| unsafe { core::ptr::read(reference) })
.map(|reference| unsafe { (&raw const *reference).read() })
}

#[inline]
Expand All @@ -53,7 +72,7 @@ impl<'valid, Item: 'valid, const INLINE: usize, Heap: Allocator> DoubleEndedIter
// SAFETY: see above
self.iter
.next_back()
.map(|reference| unsafe { core::ptr::read(reference) })
.map(|reference| unsafe { (&raw const *reference).read() })
}
}

Expand All @@ -66,10 +85,7 @@ impl<Item, const INLINE: usize, Heap: Allocator> ExactSizeIterator
}
}

impl<Item, const INLINE: usize, Heap: Allocator> core::iter::FusedIterator
for Drain<'_, Item, INLINE, Heap>
{
}
impl<Item, const INLINE: usize, Heap: Allocator> FusedIterator for Drain<'_, Item, INLINE, Heap> {}

impl<'valid, Item: 'valid, const INLINE: usize, Heap: Allocator> Drop
for Drain<'valid, Item, INLINE, Heap>
Expand All @@ -94,15 +110,15 @@ impl<'valid, Item: 'valid, const INLINE: usize, Heap: Allocator> Drop
let ptr = source_vec.as_mut_ptr();
let source = ptr.add(tail);
let destination = ptr.add(start);
core::ptr::copy(source, destination, self.0.tail_len);
copy(source, destination, self.0.tail_len);
}
source_vec.length.add(self.0.tail_len);
}
}
}
}

let iter = core::mem::take(&mut self.iter);
let iter = take(&mut self.iter);
let drop_len = iter.len();

let mut vec = self.vec;
Expand Down Expand Up @@ -150,8 +166,8 @@ impl<'valid, Item: 'valid, const INLINE: usize, Heap: Allocator> Drop
// is >= 1.87. let drop_offset =
// drop_ptr.offset_from_unsigned(vec_ptr);
let drop_offset = drop_ptr.offset_from(vec_ptr) as usize;
let to_drop = core::ptr::slice_from_raw_parts_mut(vec_ptr.add(drop_offset), drop_len);
core::ptr::drop_in_place(to_drop);
let to_drop = slice_from_raw_parts_mut(vec_ptr.add(drop_offset), drop_len);
to_drop.drop_in_place();
}
}
}
Expand Down Expand Up @@ -215,7 +231,7 @@ impl<Item, const INLINE: usize, Heap: Allocator> Drain<'_, Item, INLINE, Heap> {
let new_tail_start = self.tail_start + additional;
unsafe {
let ptr = vec.as_mut_ptr();
core::ptr::copy(
copy(
ptr.add(self.tail_start),
ptr.add(new_tail_start),
self.tail_len
Expand All @@ -225,10 +241,8 @@ impl<Item, const INLINE: usize, Heap: Allocator> Drain<'_, Item, INLINE, Heap> {
}
}

impl<Item: core::fmt::Debug, const INLINE: usize, Heap: Allocator> core::fmt::Debug
for Drain<'_, Item, INLINE, Heap>
{
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
impl<Item: Debug, const INLINE: usize, Heap: Allocator> Debug for Drain<'_, Item, INLINE, Heap> {
fn fmt(&self, f: &mut Formatter<'_>) -> Format {
f.debug_tuple("Drain").field(&self.iter.as_slice()).finish()
}
}
31 changes: 21 additions & 10 deletions src/iterators/extractif.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
use crate::{
Allocator,
Global,
SmallVec
use {
super::super::{
SmallVec,
allocator::{
Allocator,
global::Global
}
},
core::{
fmt::{
Debug,
Formatter,
Result as Format
},
ptr::copy_nonoverlapping
}
};

/// An iterator which uses a closure to determine if an element should be
Expand All @@ -27,13 +39,12 @@ where F: FnMut(&mut Item) -> bool
pub(crate) pred: F
}

impl<Item, const INLINE: usize, Heap: Allocator, F> core::fmt::Debug
for ExtractIf<'_, Item, INLINE, F, Heap>
impl<Item, const INLINE: usize, Heap: Allocator, F> Debug for ExtractIf<'_, Item, INLINE, F, Heap>
where
F: FnMut(&mut Item) -> bool,
Item: core::fmt::Debug
Item: Debug
{
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
fn fmt(&self, f: &mut Formatter<'_>) -> Format {
f.debug_tuple("ExtractIf")
.field(&self.vec.as_ref())
.finish()
Expand All @@ -60,10 +71,10 @@ where F: FnMut(&mut Item) -> bool
self.idx += 1;
if drained {
self.del += 1;
return Some(core::ptr::read(cur));
return Some(cur.read());
} else if self.del > 0 {
// SAFETY: `self.del <= i` therefore `i - self.del` is valid
core::ptr::copy_nonoverlapping(cur, cur.sub(self.del), 1);
copy_nonoverlapping(cur, cur.sub(self.del), 1);
}
}
None
Expand Down
43 changes: 27 additions & 16 deletions src/iterators/intoiter.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,34 @@
use {
crate::{
Allocator,
super::super::{
DropDealloc,
Global,
LocatedLength,
RawSmallVec,
SmallVec
SmallVec,
allocator::{
Allocator,
global::Global
},
locatedlength::LocatedLength,
rawsmallvec::RawSmallVec
},
core::{
fmt::Debug,
fmt::{
Debug,
Formatter,
Result as Format
},
iter::FusedIterator,
mem::{
ManuallyDrop,
align_of,
size_of
},
ptr::NonNull
ptr::{
NonNull,
slice_from_raw_parts_mut
},
slice::{
from_raw_parts,
from_raw_parts_mut
}
}
};

Expand Down Expand Up @@ -56,7 +70,7 @@ impl<Item, const INLINE: usize, Heap: Allocator> AsRef<[Item]> for IntoIter<Item
// valid, and so is the construction of the slice
unsafe {
let ptr = self.raw.as_ptr(on_heap);
core::slice::from_raw_parts(ptr.add(self.begin), end - self.begin)
from_raw_parts(ptr.add(self.begin), end - self.begin)
}
}
}
Expand All @@ -68,7 +82,7 @@ impl<Item, const INLINE: usize, Heap: Allocator> AsMut<[Item]> for IntoIter<Item
// SAFETY: see above
unsafe {
let ptr = self.raw.as_mut_ptr(on_heap);
core::slice::from_raw_parts_mut(ptr.add(self.begin), end - self.begin)
from_raw_parts_mut(ptr.add(self.begin), end - self.begin)
}
}
}
Expand Down Expand Up @@ -148,10 +162,7 @@ impl<Item, const INLINE: usize, Heap: Allocator> ExactSizeIterator
for IntoIter<Item, INLINE, Heap>
{
}
impl<Item, const INLINE: usize, Heap: Allocator> core::iter::FusedIterator
for IntoIter<Item, INLINE, Heap>
{
}
impl<Item, const INLINE: usize, Heap: Allocator> FusedIterator for IntoIter<Item, INLINE, Heap> {}

impl<Item, const INLINE: usize, Heap: Allocator> Drop for IntoIter<Item, INLINE, Heap> {
fn drop(&mut self) {
Expand All @@ -171,7 +182,7 @@ impl<Item, const INLINE: usize, Heap: Allocator> Drop for IntoIter<Item, INLINE,
} else {
None
};
core::ptr::slice_from_raw_parts_mut(ptr.add(begin), end - begin).drop_in_place();
slice_from_raw_parts_mut(ptr.add(begin), end - begin).drop_in_place();
}
}
}
Expand Down Expand Up @@ -215,7 +226,7 @@ impl<Item, const INLINE: usize, Heap: Allocator> IntoIterator for SmallVec<Item,
}

impl<Item: Debug, const INLINE: usize, Heap: Allocator> Debug for IntoIter<Item, INLINE, Heap> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
fn fmt(&self, f: &mut Formatter<'_>) -> Format {
f.debug_tuple("IntoIter").field(&self.as_ref()).finish()
}
}
Loading
Loading