History

Only keep decompressed bytes of base objects…

…because • decompressed deltas are really not useful nor do they speed up anything. Oposedly, it costs more to allocate. * base objects at least are fully resolved so that might one day be useful.

Sebastian Thiel committed 6 years ago

Commit b39ad891 parent 8812e914 files · +29 −14Browse files

Unified · Split

4 files
  1. git-odb/src/pack/data/iter.rs +12 −4
  2. git-odb/src/pack/index/write/mod.rs +4 −3
  3. git-odb/tests/pack/index.rs +10 −3
  4. git-odb/tests/pack/iter.rs +3 −4
git-odb/src/pack/data/iter.rs+12−4
@@ -35,8 +35,10 @@ pub struct Entry { · 34 unmodified lines
3535 /// These do not contain the header, which makes it possible to easily replace a RefDelta with offset deltas
3636 /// when resolving thin packs.
3737 pub compressed: Vec<u8>,
38− /// The decompressed data.
39− pub decompressed: Vec<u8>,
38+ /// The decompressed data of a base object, which are the only ones who are fully resolved.
39+ pub decompressed: Option<Vec<u8>>,
40+ /// The amount of decompressed bytes
41+ pub decompressed_size: u64,
4042 /// Set for the last object in the iteration, providing the hash over all bytes of the iteration
4143 /// for use as trailer in a pack
4244 pub trailer: Option<owned::Id>,
@@ -142,8 +144,13 @@ where · 99 unmodified lines
142144 decompressor,
143145 };
144146
145− let mut decompressed = Vec::with_capacity(entry.decompressed_size as usize);
146− let bytes_copied = io::copy(&mut reader, &mut decompressed)?;
147+ let (bytes_copied, decompressed) = if entry.header.is_delta() {
148+ let mut decompressed = Vec::with_capacity(entry.decompressed_size as usize);
149+ let bytes_copied = io::copy(&mut reader, &mut decompressed)?;
150+ (bytes_copied, Some(decompressed))
151+ } else {
152+ (io::copy(&mut reader, &mut io::sink())?, None)
153+ };
147154 debug_assert_eq!(
148155 bytes_copied, entry.decompressed_size,
149156 "We should have decompressed {} bytes, but got {} instead",
@@ -201,6 +208,7 @@ where · 51 unmodified lines
201208 compressed,
202209 pack_offset,
203210 decompressed,
211+ decompressed_size: bytes_copied,
204212 trailer,
205213 })
206214 }
git-odb/src/pack/index/write/mod.rs+4−3
@@ -55,15 +55,16 @@ impl pack::index::File { · 54 unmodified lines
5555 pack_offset,
5656 header_size,
5757 compressed,
58− decompressed,
58+ decompressed: _,
59+ decompressed_size,
5960 trailer,
6061 } = entry?;
6162
6263 let compressed_len = compressed.len();
63− bytes_to_process += decompressed.len() as u64;
64+ bytes_to_process += decompressed_size;
6465 let entry_len = header_size as usize + compressed_len;
6566 let crc32 = {
66− let header_len = header.to_write(decompressed.len() as u64, header_buf.as_mut())?;
67+ let header_len = header.to_write(decompressed_size, header_buf.as_mut())?;
6768 let state = hash::crc32_update(0, &header_buf[..header_len]);
6869 hash::crc32_update(state, &compressed)
6970 };
git-odb/tests/pack/index.rs+10−3
@@ -298,14 +298,21 @@ fn pack_lookup() -> Result<(), Box<dyn std::error::Error>> { · 297 unmodified lines
298298 );
299299
300300 let mut buf = Vec::new();
301− buf.resize(entry.decompressed.len(), 0);
301+ buf.resize(entry.decompressed_size as usize, 0);
302302 let pack_entry = pack.entry(offset_from_index);
303303 pack.decompress_entry(&pack_entry, &mut buf)?;
304304
305305 assert_eq!(
306− buf, entry.decompressed,
307− "the decompressed bytes are the same no matter what who decompressed them"
306+ buf.len() as u64,
307+ entry.decompressed_size,
308+ "the decompressed length are the same no matter what decompressed them"
308309 );
310+ if let Some(decompressed) = entry.decompressed {
311+ assert_eq!(
312+ buf, decompressed,
313+ "the decompressed bytes are the same no matter what decompressed them"
314+ );
315+ }
309316
310317 let next_offset_index = sorted_offsets
311318 .binary_search(&entry.pack_offset)
git-odb/tests/pack/iter.rs+3−4
@@ -4,7 +4,7 @@ use git_odb::pack; · 3 unmodified lines
44 fn size_of_entry() {
55 assert_eq!(
66 std::mem::size_of::<pack::data::iter::Entry>(),
7− 104,
7+ 112,
88 "let's keep the size in check as we have many of them"
99 );
1010 }
@@ -22,7 +22,7 @@ mod new_from_header { · 11 unmodified lines
2222 let entry = entry?;
2323
2424 let mut buf = Vec::<u8>::new();
25− entry.header.to_write(entry.decompressed.len() as u64, &mut buf)?;
25+ entry.header.to_write(entry.decompressed_size, &mut buf)?;
2626 let new_entry = pack::data::Entry::from_bytes(&buf, entry.pack_offset);
2727
2828 assert_eq!(
@@ -31,8 +31,7 @@ mod new_from_header { · 2 unmodified lines
3131 "it should consume all provided bytes"
3232 );
3333 assert_eq!(
34− new_entry.decompressed_size,
35− entry.decompressed.len() as u64,
34+ new_entry.decompressed_size, entry.decompressed_size as u64,
3635 "decoded size must match"
3736 );
3837 assert_eq!(new_entry.header, entry.header, "headers match after roundtrip");

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t