diff options
author | Mika Lindqvist <postmaster@raasu.org> | 2017-02-14 11:40:52 +0200 |
---|---|---|
committer | Hans Kristian Rosbach <hk-git@circlestorm.org> | 2017-02-16 11:19:57 +0100 |
commit | 53204685c0165028e6a33f13e22fdda3c70a218c (patch) | |
tree | 0f87451418fdd2ff5424310173389479a68546ed /deflate_medium.c | |
parent | bcb013d915b087c62772c7e778f4954f6a3d14fa (diff) |
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.
Diffstat (limited to 'deflate_medium.c')
-rw-r--r-- | deflate_medium.c | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/deflate_medium.c b/deflate_medium.c index 82301d1..046449f 100644 --- a/deflate_medium.c +++ b/deflate_medium.c @@ -68,17 +68,18 @@ 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--; + match.strstart++; + match.match_length--; + if (match.match_length > 0) { 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 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)) { - 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.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 |