Improve performance by preallocating a bit
This commit is contained in:
parent
911f149892
commit
17707b8421
|
@ -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()
|
||||||
}
|
}
|
||||||
|
|
|
@ -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(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue