diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 18:31:44 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 18:31:44 +0000 |
commit | c23a457e72abe608715ac76f076f47dc42af07a5 (patch) | |
tree | 2772049aaf84b5c9d0ed12ec8d86812f7a7904b6 /vendor/gix-pack/src/data/input | |
parent | Releasing progress-linux version 1.73.0+dfsg1-1~progress7.99u1. (diff) | |
download | rustc-c23a457e72abe608715ac76f076f47dc42af07a5.tar.xz rustc-c23a457e72abe608715ac76f076f47dc42af07a5.zip |
Merging upstream version 1.74.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/gix-pack/src/data/input')
4 files changed, 56 insertions, 34 deletions
diff --git a/vendor/gix-pack/src/data/input/bytes_to_entries.rs b/vendor/gix-pack/src/data/input/bytes_to_entries.rs index 995c8df2c..7450e9134 100644 --- a/vendor/gix-pack/src/data/input/bytes_to_entries.rs +++ b/vendor/gix-pack/src/data/input/bytes_to_entries.rs @@ -1,10 +1,6 @@ use std::{fs, io}; -use gix_features::{ - hash, - hash::Sha1, - zlib::{stream::inflate::ReadBoxed, Decompress}, -}; +use gix_features::{hash::Sha1, zlib::Decompress}; use gix_hash::ObjectId; use crate::data::input; @@ -14,7 +10,7 @@ use crate::data::input; /// The iterator used as part of [`Bundle::write_to_directory(…)`][crate::Bundle::write_to_directory()]. pub struct BytesToEntriesIter<BR> { read: BR, - decompressor: Option<Box<Decompress>>, + decompressor: Decompress, offset: u64, had_error: bool, version: crate::data::Version, @@ -66,7 +62,7 @@ where ); Ok(BytesToEntriesIter { read, - decompressor: None, + decompressor: Decompress::new(true), compressed, offset: 12, had_error: false, @@ -88,31 +84,25 @@ where self.objects_left -= 1; // even an error counts as objects // Read header - let entry = match self.hash.take() { + let entry = match self.hash.as_mut() { Some(hash) => { let mut read = read_and_pass_to( &mut self.read, - hash::Write { + HashWrite { inner: io::sink(), hash, }, ); - let res = crate::data::Entry::from_read(&mut read, self.offset, self.hash_len); - self.hash = Some(read.write.hash); - res + crate::data::Entry::from_read(&mut read, self.offset, self.hash_len) } None => crate::data::Entry::from_read(&mut self.read, self.offset, self.hash_len), } .map_err(input::Error::from)?; // Decompress object to learn its compressed bytes - let mut decompressor = self - .decompressor - .take() - .unwrap_or_else(|| Box::new(Decompress::new(true))); let compressed_buf = self.compressed_buf.take().unwrap_or_else(|| Vec::with_capacity(4096)); - decompressor.reset(true); - let mut decompressed_reader = ReadBoxed { + self.decompressor.reset(true); + let mut decompressed_reader = DecompressRead { inner: read_and_pass_to( &mut self.read, if self.compressed.keep() { @@ -121,7 +111,7 @@ where compressed_buf }, ), - decompressor, + decompressor: &mut self.decompressor, }; let bytes_copied = io::copy(&mut decompressed_reader, &mut io::sink())?; @@ -135,7 +125,6 @@ where let pack_offset = self.offset; let compressed_size = decompressed_reader.decompressor.total_in(); self.offset += entry.header_size() as u64 + compressed_size; - self.decompressor = Some(decompressed_reader.decompressor); let mut compressed = decompressed_reader.inner.write; debug_assert_eq!( @@ -149,7 +138,7 @@ where let crc32 = if self.compressed.crc32() { let mut header_buf = [0u8; 12 + gix_hash::Kind::longest().len_in_bytes()]; - let header_len = entry.header.write_to(bytes_copied, header_buf.as_mut())?; + let header_len = entry.header.write_to(bytes_copied, &mut header_buf.as_mut())?; let state = gix_features::hash::crc32_update(0, &header_buf[..header_len]); Some(gix_features::hash::crc32_update(state, &compressed)) } else { @@ -293,3 +282,43 @@ impl crate::data::File { ) } } + +/// The boxed variant is faster for what we do (moving the decompressor in and out a lot) +pub struct DecompressRead<'a, R> { + /// The reader from which bytes should be decompressed. + pub inner: R, + /// The decompressor doing all the work. + pub decompressor: &'a mut Decompress, +} + +impl<'a, R> io::Read for DecompressRead<'a, R> +where + R: io::BufRead, +{ + fn read(&mut self, into: &mut [u8]) -> io::Result<usize> { + gix_features::zlib::stream::inflate::read(&mut self.inner, self.decompressor, into) + } +} + +/// A utility to automatically generate a hash while writing into an inner writer. +pub struct HashWrite<'a, T> { + /// The hash implementation. + pub hash: &'a mut Sha1, + /// The inner writer. + pub inner: T, +} + +impl<'a, T> std::io::Write for HashWrite<'a, T> +where + T: std::io::Write, +{ + fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> { + let written = self.inner.write(buf)?; + self.hash.update(&buf[..written]); + Ok(written) + } + + fn flush(&mut self) -> std::io::Result<()> { + self.inner.flush() + } +} diff --git a/vendor/gix-pack/src/data/input/entries_to_bytes.rs b/vendor/gix-pack/src/data/input/entries_to_bytes.rs index a8c21e653..27cd04648 100644 --- a/vendor/gix-pack/src/data/input/entries_to_bytes.rs +++ b/vendor/gix-pack/src/data/input/entries_to_bytes.rs @@ -73,12 +73,11 @@ where } self.num_entries += 1; entry.header.write_to(entry.decompressed_size, &mut self.output)?; - std::io::copy( - &mut entry + self.output.write_all( + entry .compressed .as_deref() .expect("caller must configure generator to keep compressed bytes"), - &mut self.output, )?; Ok(entry) } diff --git a/vendor/gix-pack/src/data/input/entry.rs b/vendor/gix-pack/src/data/input/entry.rs index 74d4800a0..7d3d9b3cb 100644 --- a/vendor/gix-pack/src/data/input/entry.rs +++ b/vendor/gix-pack/src/data/input/entry.rs @@ -33,7 +33,7 @@ impl input::Entry { let mut header_buf = [0u8; 12 + gix_hash::Kind::longest().len_in_bytes()]; let header_len = self .header - .write_to(self.decompressed_size, header_buf.as_mut()) + .write_to(self.decompressed_size, &mut header_buf.as_mut()) .expect("write to memory will not fail"); let state = gix_features::hash::crc32_update(0, &header_buf[..header_len]); gix_features::hash::crc32_update(state, self.compressed.as_ref().expect("we always set it")) diff --git a/vendor/gix-pack/src/data/input/lookup_ref_delta_objects.rs b/vendor/gix-pack/src/data/input/lookup_ref_delta_objects.rs index d95e6176d..60f686d3a 100644 --- a/vendor/gix-pack/src/data/input/lookup_ref_delta_objects.rs +++ b/vendor/gix-pack/src/data/input/lookup_ref_delta_objects.rs @@ -47,13 +47,7 @@ where /// positive `size_change` values mean an object grew or was more commonly, was inserted. Negative values /// mean the object shrunk, usually because there header changed from ref-deltas to ofs deltas. - fn track_change( - &mut self, - shifted_pack_offset: u64, - pack_offset: u64, - size_change: i64, - oid: impl Into<Option<ObjectId>>, - ) { + fn track_change(&mut self, shifted_pack_offset: u64, pack_offset: u64, size_change: i64, oid: Option<ObjectId>) { if size_change == 0 { return; } @@ -61,7 +55,7 @@ where shifted_pack_offset, pack_offset, size_change_in_bytes: size_change, - oid: oid.into().unwrap_or_else(|| + oid: oid.unwrap_or_else(|| // NOTE: this value acts as sentinel and the actual hash kind doesn't matter. gix_hash::Kind::Sha1.null()), }); @@ -112,7 +106,7 @@ where entry.pack_offset, current_pack_offset, entry.bytes_in_pack() as i64, - base_id, + Some(base_id), ); entry } |