remove SmallVec

This commit is contained in:
Riccardo Casatta 2024-05-10 11:33:29 +02:00
parent e4b707ba83
commit deeb160b86
No known key found for this signature in database
GPG Key ID: FD986A969E450397
1 changed files with 5 additions and 36 deletions

View File

@ -31,7 +31,7 @@ pub mod error;
#[cfg(not(feature = "std"))]
pub use alloc::{string::String, vec::Vec};
use core::{fmt, iter, slice, str};
use core::{fmt, str};
#[cfg(feature = "std")]
pub use std::{string::String, vec::Vec};
@ -118,7 +118,9 @@ pub fn decode_check(data: &str) -> Result<Vec<u8>, Error> {
}
/// Encodes `data` as a base58 string (see also `base58::encode_check()`).
pub fn encode(data: &[u8]) -> String { encode_iter(data.iter().cloned()) }
pub fn encode(data: &[u8]) -> String {
encode_iter(data.iter().cloned())
}
/// Encodes `data` as a base58 string including the checksum.
///
@ -151,7 +153,7 @@ where
I: Iterator<Item = u8> + Clone,
W: fmt::Write,
{
let mut ret = SmallVec::new();
let mut ret = Vec::with_capacity(128);
let mut leading_zero_count = 0;
let mut leading_zeroes = true;
@ -187,37 +189,6 @@ where
Ok(())
}
/// Vector-like object that holds the first 100 elements on the stack. If more space is needed it
/// will be allocated on the heap.
struct SmallVec<T> {
len: usize,
stack: [T; 100],
heap: Vec<T>,
}
impl<T: Default + Copy> SmallVec<T> {
fn new() -> SmallVec<T> { SmallVec { len: 0, stack: [T::default(); 100], heap: Vec::new() } }
fn push(&mut self, val: T) {
if self.len < 100 {
self.stack[self.len] = val;
self.len += 1;
} else {
self.heap.push(val);
}
}
fn iter(&self) -> iter::Chain<slice::Iter<T>, slice::Iter<T>> {
// If len<100 then we just append an empty vec
self.stack[0..self.len].iter().chain(self.heap.iter())
}
fn iter_mut(&mut self) -> iter::Chain<slice::IterMut<T>, slice::IterMut<T>> {
// If len<100 then we just append an empty vec
self.stack[0..self.len].iter_mut().chain(self.heap.iter_mut())
}
}
#[cfg(test)]
mod tests {
use hex::test_hex_unwrap as hex;
@ -288,7 +259,6 @@ mod tests {
}
}
#[cfg(bench)]
mod benches {
use test::{black_box, Bencher};
@ -312,5 +282,4 @@ mod benches {
black_box(&r);
});
}
}