Skip to content

Commit 2bb6fd2

Browse files
committed
don't cause re-allocs of the compression buffer
They are used once anyway, and downstream users can minimize size if needed.
1 parent 31934f6 commit 2bb6fd2

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

git-object/src/borrowed/tree.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ fn parse_entry(i: &[u8]) -> IResult<&[u8], Entry, Error> {
6161
}
6262

6363
fn parse(i: &[u8]) -> IResult<&[u8], Tree, Error> {
64-
let (i, mut entries) = all_consuming(many1(parse_entry))(i)?;
65-
entries.shrink_to_fit();
64+
let (i, entries) = all_consuming(many1(parse_entry))(i)?;
6665
Ok((i, Tree { entries }))
6766
}
6867

git-odb/src/pack/data/iter.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ pub struct Entry {
3131
/// amount of bytes used to encode the `header`. `pack_offset + header_size` is the beginning of the compressed data in the pack.
3232
pub header_size: u16,
3333
pub pack_offset: u64,
34-
/// amount bytes consumed while producing `decompressed`
34+
/// The bytes consumed while producing `decompressed`
35+
/// These do not contain the header, which makes it possible to easily replace a RefDelta with offset deltas
36+
/// when resolving thin packs.
3537
pub compressed: Vec<u8>,
3638
/// The decompressed data.
3739
pub decompressed: Vec<u8>,
@@ -136,10 +138,7 @@ where
136138
let mut decompressor = self.decompressor.take().unwrap_or_default();
137139
decompressor.reset();
138140
let mut reader = InflateReaderBoxed {
139-
inner: read_and_pass_to(
140-
&mut self.read,
141-
Vec::with_capacity((entry.decompressed_size / 2) as usize),
142-
),
141+
inner: read_and_pass_to(&mut self.read, Vec::with_capacity((entry.decompressed_size) as usize)),
143142
decompressor,
144143
};
145144

@@ -156,8 +155,7 @@ where
156155
self.offset += entry.header_size() as u64 + compressed_size;
157156
self.decompressor = Some(reader.decompressor);
158157

159-
let mut compressed = reader.inner.write;
160-
compressed.shrink_to_fit();
158+
let compressed = reader.inner.write;
161159
debug_assert_eq!(
162160
compressed_size,
163161
compressed.len() as u64,
@@ -209,7 +207,7 @@ where
209207
}
210208

211209
fn read_and_pass_to<R: io::Read, W: io::Write>(read: &mut R, to: W) -> PassThrough<&mut R, W> {
212-
PassThrough { read: read, write: to }
210+
PassThrough { read, write: to }
213211
}
214212

215213
impl<R> Iterator for Iter<R>

0 commit comments

Comments
 (0)