[thin_metadata_pack/unpack] Use Vec::with_capacity() to avoid reallocs.
Gives a small speed boost to both pack and unpack.
This commit is contained in:
parent
c9a759b4e8
commit
b01a0a46d1
@ -13,7 +13,7 @@ use Delta::*;
|
||||
pub fn to_delta(ns: &[u64]) -> Vec<Delta> {
|
||||
use std::cmp::Ordering::*;
|
||||
|
||||
let mut ds = Vec::new();
|
||||
let mut ds = Vec::with_capacity(ns.len());
|
||||
|
||||
if !ns.is_empty() {
|
||||
let mut base = ns[0];
|
||||
|
@ -146,8 +146,8 @@ pub fn pack_u64s<W: Write>(w: &mut W, ns: &[u64]) -> io::Result<()> {
|
||||
}
|
||||
|
||||
fn unshift_nrs(shift: usize, ns: &[u64]) -> (Vec<u64>, Vec<u64>) {
|
||||
let mut values = Vec::new();
|
||||
let mut shifts = Vec::new();
|
||||
let mut values = Vec::with_capacity(ns.len());
|
||||
let mut shifts = Vec::with_capacity(ns.len());
|
||||
|
||||
let mask = (1 << shift) - 1;
|
||||
for n in ns {
|
||||
@ -207,7 +207,7 @@ fn unpack_with_width<R: Read>(r: &mut R, nibble: u8) -> io::Result<u64> {
|
||||
}
|
||||
|
||||
fn unpack_u64s<R: Read>(r: &mut R, count: usize) -> io::Result<Vec<u64>> {
|
||||
let mut v = Vec::new();
|
||||
let mut v = Vec::with_capacity(count);
|
||||
for _ in 0..count {
|
||||
let n = r.read_u64::<LittleEndian>()?;
|
||||
v.push(n);
|
||||
|
Loading…
Reference in New Issue
Block a user