Skip to content

Commit f58090e

Browse files
committed
feat: improve performance by avoiding zeroying buffers. (#851)
Previously we would use `resize(new_len, 0)` to resize buffers, even though these values would then be overwritten (or the buffer isn't available). Now we use `set_len(new_len)` after calling `reserve` to do the same, but safe a memset.
1 parent 0c09c48 commit f58090e

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

gix-pack/src/cache/delta/traverse/resolve.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use crate::{
1414
data::EntryRange,
1515
};
1616

17+
#[allow(clippy::too_many_arguments)]
1718
pub(crate) fn deltas<T, F, P, MBFN, S, E>(
1819
object_counter: Option<gix_features::progress::StepShared>,
1920
size_counter: Option<gix_features::progress::StepShared>,
@@ -147,8 +148,14 @@ where
147148
}
148149

149150
fn decompress_all_at_once(b: &[u8], decompressed_len: usize) -> Result<Vec<u8>, Error> {
150-
let mut out = Vec::new();
151-
out.resize(decompressed_len, 0);
151+
let mut out = Vec::with_capacity(decompressed_len);
152+
// SAFETY:
153+
// 1. we have reserved `decompressed_len`
154+
// 2. zlib is going to write all of `decompressed_len`. On error, none of the the buffer is made available to the user.
155+
#[allow(unsafe_code, clippy::uninit_vec)]
156+
unsafe {
157+
out.set_len(decompressed_len);
158+
}
152159
zlib::Inflate::default()
153160
.once(b, &mut out)
154161
.map_err(|err| Error::ZlibInflate {

0 commit comments

Comments
 (0)