Improve performance by preallocating a bit
This commit is contained in:
parent
911f149892
commit
17707b8421
|
@ -11,14 +11,14 @@ pub struct IOList {
|
|||
impl IOList {
|
||||
pub fn new() -> Self {
|
||||
IOList {
|
||||
chunks: vec![],
|
||||
chunks: Vec::with_capacity(5),
|
||||
len: 0,
|
||||
}
|
||||
}
|
||||
|
||||
fn rightmost_chunk(&mut self) -> &mut Vec<u8> {
|
||||
if self.chunks.is_empty() {
|
||||
self.chunks.push(vec![]);
|
||||
self.chunks.push(Vec::with_capacity(64))
|
||||
}
|
||||
self.chunks.last_mut().unwrap()
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ impl<W: io::Write> PackedWriter<W> {
|
|||
PackedWriter {
|
||||
w: write,
|
||||
buffer: IOList::new(),
|
||||
items: Vec::new(),
|
||||
items: Vec::with_capacity(16),
|
||||
streaming: false,
|
||||
}
|
||||
}
|
||||
|
@ -117,7 +117,7 @@ impl<W: io::Write> PackedWriter<W> {
|
|||
}
|
||||
|
||||
pub fn start_seq(&mut self) -> io::Result<()> {
|
||||
self.items.push(Vec::new());
|
||||
self.items.push(Vec::with_capacity(32));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue