Avoid hashing same memory location twice by truncating overlapping byte ranges,

it's speed optimization as the inner code also checks that previous hash value
is not same as new hash value. Essentially those two checks together makes the
compression a little more efficient as it can remember matches further apart.
As far as I remember from my tests, the secondary path was triggered only twice
in very long uncompressed file, but the gain in compression rate was still noticeable.
This commit is contained in:
Mika Lindqvist 2017-02-14 11:40:52 +02:00 committed by Hans Kristian Rosbach
parent bcb013d915
commit 53204685c0

View File

@ -68,18 +68,19 @@ static void insert_match(deflate_state *s, struct match match) {
}
}
#else
if (likely(match.match_length == 1)) {
match.strstart++;
match.match_length = 0;
}else{
match.strstart++;
match.match_length--;
if (match.match_length > 0) {
if (match.strstart >= match.orgstart) {
if (match.strstart + match.match_length - 1 >= match.orgstart) {
insert_string(s, match.strstart, match.match_length);
} else {
insert_string(s, match.strstart, match.orgstart - match.strstart + 1);
}
match.strstart += match.match_length;
match.match_length = 0;
}
}
#endif
return;
}
@ -102,7 +103,11 @@ static void insert_match(deflate_state *s, struct match match) {
} while (--match.match_length != 0);
#else
if (likely(match.strstart >= match.orgstart)) {
if (likely(match.strstart + match.match_length - 1 >= match.orgstart)) {
insert_string(s, match.strstart, match.match_length);
} else {
insert_string(s, match.strstart, match.orgstart - match.strstart + 1);
}
}
match.strstart += match.match_length;
match.match_length = 0;
@ -111,7 +116,7 @@ static void insert_match(deflate_state *s, struct match match) {
match.strstart += match.match_length;
match.match_length = 0;
s->ins_h = s->window[match.strstart];
if (match.strstart >= 1)
if (match.strstart >= (MIN_MATCH - 2))
#ifndef NOT_TWEAK_COMPILER
insert_string(s, match.strstart + 2 - MIN_MATCH, MIN_MATCH - 2);
#else