remove SmallVec
This commit is contained in:
parent
e4b707ba83
commit
deeb160b86
|
@ -31,7 +31,7 @@ pub mod error;
|
||||||
|
|
||||||
#[cfg(not(feature = "std"))]
|
#[cfg(not(feature = "std"))]
|
||||||
pub use alloc::{string::String, vec::Vec};
|
pub use alloc::{string::String, vec::Vec};
|
||||||
use core::{fmt, iter, slice, str};
|
use core::{fmt, str};
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
pub use std::{string::String, vec::Vec};
|
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()`).
|
/// 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.
|
/// Encodes `data` as a base58 string including the checksum.
|
||||||
///
|
///
|
||||||
|
@ -151,7 +153,7 @@ where
|
||||||
I: Iterator<Item = u8> + Clone,
|
I: Iterator<Item = u8> + Clone,
|
||||||
W: fmt::Write,
|
W: fmt::Write,
|
||||||
{
|
{
|
||||||
let mut ret = SmallVec::new();
|
let mut ret = Vec::with_capacity(128);
|
||||||
|
|
||||||
let mut leading_zero_count = 0;
|
let mut leading_zero_count = 0;
|
||||||
let mut leading_zeroes = true;
|
let mut leading_zeroes = true;
|
||||||
|
@ -187,37 +189,6 @@ where
|
||||||
Ok(())
|
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)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use hex::test_hex_unwrap as hex;
|
use hex::test_hex_unwrap as hex;
|
||||||
|
@ -288,7 +259,6 @@ mod tests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[cfg(bench)]
|
#[cfg(bench)]
|
||||||
mod benches {
|
mod benches {
|
||||||
use test::{black_box, Bencher};
|
use test::{black_box, Bencher};
|
||||||
|
@ -312,5 +282,4 @@ mod benches {
|
||||||
black_box(&r);
|
black_box(&r);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue