Skip to content
This repository was archived by the owner on Mar 1, 2024. It is now read-only.

Commit a43a247

Browse files
committed
deflate_medium: avoid emitting a suboptimal literal in the restart case
When we load new data into the window, we invalidate the next match, in case the match would improve. In this case, the hash has already been updated with this data, so when we look for a new match it will point it back at itself. As a result, a literal is generated even when a better match is available. This avoids that by catching this case and ensuring we're looking at the past.
1 parent 3dd73ae commit a43a247

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

deflate_medium.c

+6
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,9 @@ block_state deflate_medium(deflate_state *s, int flush)
216216
if (s->lookahead >= MIN_MATCH) {
217217
INSERT_STRING(s, s->strstart, hash_head);
218218
}
219+
220+
if (hash_head && hash_head == s->strstart)
221+
hash_head--;
219222

220223
/* set up the initial match to be a 1 byte literal */
221224
current_match.match_start = 0;
@@ -249,6 +252,9 @@ block_state deflate_medium(deflate_state *s, int flush)
249252
if (s->lookahead > MIN_LOOKAHEAD) {
250253
s->strstart = current_match.strstart + current_match.match_length;
251254
INSERT_STRING(s, s->strstart, hash_head);
255+
256+
if (hash_head && hash_head == s->strstart)
257+
hash_head--;
252258

253259
/* set up the initial match to be a 1 byte literal */
254260
next_match.match_start = 0;

0 commit comments

Comments
 (0)