Use new `Copy`-specialized clone impl for a couple of things.
Also go back to regular assert in `push`, because while the other way was not slower, it did generate *more* code, consisting largely of the unwrap branch (which would only rarely be triggered, meaning it's not really worth the added bloat.)
@@ -310,7 +310,8 @@ impl<T, const N: usize> StaticVec<T, { N }> {
/// full; that is, if `self.len() == self.capacity()`.
#[inline(always)]
pub fn push(&mut self, value: T) {
- self.try_push(value).unwrap()
+ assert!(self.length < N, "Insufficient remaining capacity!");
+ unsafe { self.push_unchecked(value) }
}
///Removes the value at the last position of the StaticVec and returns it in `Some` if
@@ -506,16 +507,10 @@ impl<T, const N: usize> StaticVec<T, { N }> {
#[inline]
pub fn sorted(&self) -> Self
where T: Copy + Ord {
- unsafe {
- let mut res = Self::new();
- res.length = self.length;
- self
- .as_ptr()
- .copy_to_nonoverlapping(res.as_mut_ptr(), self.length);
+ let mut res = self.clone();
res.sort();
res
}
- }
///Returns a separate, unstable-sorted StaticVec of the contents of the
///StaticVec's inhabited area without modifying the original data.
@@ -524,16 +519,10 @@ impl<T, const N: usize> StaticVec<T, { N }> {
#[inline]
pub fn sorted_unstable(&self) -> Self
where T: Copy + Ord {
- unsafe {
- let mut res = Self::new();
- res.length = self.length;
- self
- .as_ptr()
- .copy_to_nonoverlapping(res.as_mut_ptr(), self.length);
+ let mut res = self.clone();
res.sort_unstable();
res
}
- }
///Returns a separate, reversed StaticVec of the contents of the StaticVec's
///inhabited area without modifying the original data.
