mirror of
https://github.com/GerbilSoft/zlib-ng.git
synced 2025-06-19 03:55:39 -04:00
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:
parent
bcb013d915
commit
53204685c0
@ -68,17 +68,18 @@ static void insert_match(deflate_state *s, struct match match) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if (likely(match.match_length == 1)) {
|
match.strstart++;
|
||||||
match.strstart++;
|
match.match_length--;
|
||||||
match.match_length = 0;
|
if (match.match_length > 0) {
|
||||||
}else{
|
|
||||||
match.strstart++;
|
|
||||||
match.match_length--;
|
|
||||||
if (match.strstart >= match.orgstart) {
|
if (match.strstart >= match.orgstart) {
|
||||||
insert_string(s, match.strstart, match.match_length);
|
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;
|
||||||
}
|
}
|
||||||
match.strstart += match.match_length;
|
|
||||||
match.match_length = 0;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return;
|
return;
|
||||||
@ -102,7 +103,11 @@ static void insert_match(deflate_state *s, struct match match) {
|
|||||||
} while (--match.match_length != 0);
|
} while (--match.match_length != 0);
|
||||||
#else
|
#else
|
||||||
if (likely(match.strstart >= match.orgstart)) {
|
if (likely(match.strstart >= match.orgstart)) {
|
||||||
insert_string(s, match.strstart, match.match_length);
|
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.strstart += match.match_length;
|
||||||
match.match_length = 0;
|
match.match_length = 0;
|
||||||
@ -111,7 +116,7 @@ static void insert_match(deflate_state *s, struct match match) {
|
|||||||
match.strstart += match.match_length;
|
match.strstart += match.match_length;
|
||||||
match.match_length = 0;
|
match.match_length = 0;
|
||||||
s->ins_h = s->window[match.strstart];
|
s->ins_h = s->window[match.strstart];
|
||||||
if (match.strstart >= 1)
|
if (match.strstart >= (MIN_MATCH - 2))
|
||||||
#ifndef NOT_TWEAK_COMPILER
|
#ifndef NOT_TWEAK_COMPILER
|
||||||
insert_string(s, match.strstart + 2 - MIN_MATCH, MIN_MATCH - 2);
|
insert_string(s, match.strstart + 2 - MIN_MATCH, MIN_MATCH - 2);
|
||||||
#else
|
#else
|
||||||
|
Loading…
Reference in New Issue
Block a user