Improve performance by preallocating a bit

This commit is contained in:
Tony Garnock-Jones 2022-07-13 13:43:35 +02:00
parent 911f149892
commit 17707b8421
2 changed files with 4 additions and 4 deletions

View File

@ -11,14 +11,14 @@ pub struct IOList {
impl IOList { impl IOList {
pub fn new() -> Self { pub fn new() -> Self {
IOList { IOList {
chunks: vec![], chunks: Vec::with_capacity(5),
len: 0, len: 0,
} }
} }
fn rightmost_chunk(&mut self) -> &mut Vec<u8> { fn rightmost_chunk(&mut self) -> &mut Vec<u8> {
if self.chunks.is_empty() { if self.chunks.is_empty() {
self.chunks.push(vec![]); self.chunks.push(Vec::with_capacity(64))
} }
self.chunks.last_mut().unwrap() self.chunks.last_mut().unwrap()
} }

View File

@ -55,7 +55,7 @@ impl<W: io::Write> PackedWriter<W> {
PackedWriter { PackedWriter {
w: write, w: write,
buffer: IOList::new(), buffer: IOList::new(),
items: Vec::new(), items: Vec::with_capacity(16),
streaming: false, streaming: false,
} }
} }
@ -117,7 +117,7 @@ impl<W: io::Write> PackedWriter<W> {
} }
pub fn start_seq(&mut self) -> io::Result<()> { pub fn start_seq(&mut self) -> io::Result<()> {
self.items.push(Vec::new()); self.items.push(Vec::with_capacity(32));
Ok(()) Ok(())
} }