Skip to content

Commit b75332a

Browse files
authored
Merge pull request #226 from 404Setup/bolt-optimize-compress-greedy-7613125628886538783
⚡ Bolt: Avoid redundant hash updates in greedy compression
2 parents 6c29561 + f6f45f9 commit b75332a

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

src/compress/mod.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1022,6 +1022,7 @@ impl Compressor {
10221022
let (mut len, mut offset) = mf.find_match(input, in_idx, self.max_search_depth);
10231023

10241024
if len >= 3 {
1025+
let mut skipped = 0;
10251026
if lazy_depth >= 1 && in_idx + 1 < input.len() {
10261027
let (next_len, next_offset) =
10271028
mf.find_match(input, in_idx + 1, self.max_search_depth);
@@ -1050,6 +1051,7 @@ impl Compressor {
10501051

10511052
len = next_len;
10521053
offset = next_offset;
1054+
skipped = 1;
10531055
}
10541056
} else {
10551057
self.split_stats.observe_literal(input[in_idx]);
@@ -1060,6 +1062,8 @@ impl Compressor {
10601062
len = next_len;
10611063
offset = next_offset;
10621064
}
1065+
} else {
1066+
skipped = 1;
10631067
}
10641068
}
10651069

@@ -1072,7 +1076,14 @@ impl Compressor {
10721076
self.litlen_freqs[257 + self.get_length_slot(len)] += 1;
10731077
self.offset_freqs[self.get_offset_slot(offset)] += 1;
10741078
litrunlen = 0;
1075-
mf.skip_positions(input, in_idx + 1, len - 1, self.max_search_depth);
1079+
if len - 1 > skipped {
1080+
mf.skip_positions(
1081+
input,
1082+
in_idx + 1 + skipped,
1083+
len - 1 - skipped,
1084+
self.max_search_depth,
1085+
);
1086+
}
10761087
in_idx += len;
10771088
} else {
10781089
self.split_stats.observe_literal(input[in_idx]);

0 commit comments

Comments
 (0)