]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Use local match_len variable in deflate_slow.
authorNathan Moinvaziri <nathan@nathanm.com>
Sun, 28 Jun 2020 21:14:24 +0000 (14:14 -0700)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Tue, 30 Jun 2020 16:21:45 +0000 (18:21 +0200)
Remove match_len from deflate internal_state.

deflate.c
deflate_slow.c

index 02d8c736cd78cd574eb1770280b00a7571f25c69..f224952ca7c51be1c2cb5e6606b89f957e6354c7 100644 (file)
--- a/deflate.c
+++ b/deflate.c
@@ -482,7 +482,7 @@ int32_t ZEXPORT PREFIX(deflateSetDictionary)(PREFIX3(stream) *strm, const uint8_
     s->block_start = (long)s->strstart;
     s->insert = s->lookahead;
     s->lookahead = 0;
-    s->match_length = s->prev_length = MIN_MATCH-1;
+    s->prev_length = MIN_MATCH-1;
     s->match_available = 0;
     strm->next_in = next;
     strm->avail_in = avail;
@@ -1201,7 +1201,7 @@ static void lm_init(deflate_state *s) {
     s->block_start = 0L;
     s->lookahead = 0;
     s->insert = 0;
-    s->match_length = s->prev_length = MIN_MATCH-1;
+    s->prev_length = MIN_MATCH-1;
     s->match_available = 0;
     s->match_start = 0;
 }
index b526be46302bd50303d3852107af9b0e558c4745..0e28e3503bf3ab7c46c1be42964f690f406c3c09 100644 (file)
@@ -17,6 +17,7 @@
 ZLIB_INTERNAL block_state deflate_slow(deflate_state *s, int flush) {
     Pos hash_head;           /* head of hash chain */
     int bflush;              /* set if current block must be flushed */
+    uint32_t match_len;
 
     /* Process the input block. */
     for (;;) {
@@ -44,28 +45,28 @@ ZLIB_INTERNAL block_state deflate_slow(deflate_state *s, int flush) {
 
         /* Find the longest match, discarding those <= prev_length.
          */
-        s->prev_length = s->match_length, s->prev_match = s->match_start;
-        s->match_length = MIN_MATCH-1;
+        s->prev_match = s->match_start;
+        match_len = MIN_MATCH-1;
 
         if (hash_head != NIL && s->prev_length < s->max_lazy_match && s->strstart - hash_head <= MAX_DIST(s)) {
             /* To simplify the code, we prevent matches with the string
              * of window index 0 (in particular we have to avoid a match
              * of the string with itself at the start of the input file).
              */
-            s->match_length = functable.longest_match(s, hash_head);
+            match_len = functable.longest_match(s, hash_head);
             /* longest_match() sets match_start */
 
-            if (s->match_length <= 5 && (s->strategy == Z_FILTERED)) {
+            if (match_len <= 5 && (s->strategy == Z_FILTERED)) {
                 /* If prev_match is also MIN_MATCH, match_start is garbage
                  * but we will ignore the current match anyway.
                  */
-                s->match_length = MIN_MATCH-1;
+                match_len = MIN_MATCH-1;
             }
         }
         /* If there was a match at the previous step and the current
          * match is not better, output the previous match:
          */
-        if (s->prev_length >= MIN_MATCH && s->match_length <= s->prev_length) {
+        if (s->prev_length >= MIN_MATCH && match_len <= s->prev_length) {
             unsigned int max_insert = s->strstart + s->lookahead - MIN_MATCH;
             /* Do not insert strings in hash table beyond this. */
 
@@ -90,7 +91,6 @@ ZLIB_INTERNAL block_state deflate_slow(deflate_state *s, int flush) {
             }
             s->prev_length = 0;
             s->match_available = 0;
-            s->match_length = MIN_MATCH-1;
             s->strstart += mov_fwd + 1;
 
             if (bflush)
@@ -104,6 +104,7 @@ ZLIB_INTERNAL block_state deflate_slow(deflate_state *s, int flush) {
             bflush = zng_tr_tally_lit(s, s->window[s->strstart-1]);
             if (bflush)
                 FLUSH_BLOCK_ONLY(s, 0);
+            s->prev_length = match_len;
             s->strstart++;
             s->lookahead--;
             if (s->strm->avail_out == 0)
@@ -112,6 +113,7 @@ ZLIB_INTERNAL block_state deflate_slow(deflate_state *s, int flush) {
             /* There is no previous match to compare with, wait for
              * the next step to decide.
              */
+            s->prev_length = match_len;
             s->match_available = 1;
             s->strstart++;
             s->lookahead--;