]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Separate MIN_MATCH into STD_MIN_MATCH and WANT_MIN_MATCH
authorHans Kristian Rosbach <hk-git@circlestorm.org>
Mon, 10 May 2021 14:48:29 +0000 (16:48 +0200)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Sun, 13 Jun 2021 18:55:01 +0000 (20:55 +0200)
Rename MAX_MATCH to STD_MAX_MATCH

14 files changed:
deflate.c
deflate.h
deflate_fast.c
deflate_medium.c
deflate_p.h
deflate_quick.c
deflate_rle.c
deflate_slow.c
insert_string_tpl.h
match_tpl.h
tools/maketrees.c
trees_emit.h
trees_tbl.h
zutil.h

index dd1f120c4dd85f2e0b4a6a50ee68727045bbca4e..f95c6859afdf0e649fdfa7e7a4af45c1b629355f 100644 (file)
--- a/deflate.c
+++ b/deflate.c
@@ -167,7 +167,7 @@ static const config configuration_table[10] = {
 /* 8 */ {32, 128, 258, 1024, deflate_slow},
 /* 9 */ {32, 258, 258, 4096, deflate_slow}}; /* max compression */
 
-/* Note: the deflate() code requires max_lazy >= MIN_MATCH and max_chain >= 4
+/* Note: the deflate() code requires max_lazy >= STD_MIN_MATCH and max_chain >= 4
  * For deflate_fast() (levels <= 3) good is ignored and lazy has a different
  * meaning.
  */
@@ -431,19 +431,19 @@ int32_t Z_EXPORT PREFIX(deflateSetDictionary)(PREFIX3(stream) *strm, const uint8
     strm->avail_in = dictLength;
     strm->next_in = (z_const unsigned char *)dictionary;
     fill_window(s);
-    while (s->lookahead >= MIN_MATCH) {
+    while (s->lookahead >= STD_MIN_MATCH) {
         str = s->strstart;
-        n = s->lookahead - (MIN_MATCH-1);
+        n = s->lookahead - (STD_MIN_MATCH-1);
         functable.insert_string(s, str, n);
         s->strstart = str + n;
-        s->lookahead = MIN_MATCH-1;
+        s->lookahead = STD_MIN_MATCH-1;
         fill_window(s);
     }
     s->strstart += s->lookahead;
     s->block_start = (int)s->strstart;
     s->insert = s->lookahead;
     s->lookahead = 0;
-    s->prev_length = MIN_MATCH-1;
+    s->prev_length = STD_MIN_MATCH-1;
     s->match_available = 0;
     strm->next_in = (z_const unsigned char *)next;
     strm->avail_in = avail;
@@ -1160,7 +1160,7 @@ static void lm_init(deflate_state *s) {
     s->block_start = 0;
     s->lookahead = 0;
     s->insert = 0;
-    s->prev_length = MIN_MATCH-1;
+    s->prev_length = STD_MIN_MATCH-1;
     s->match_available = 0;
     s->match_start = 0;
 }
@@ -1224,17 +1224,16 @@ void Z_INTERNAL fill_window(deflate_state *s) {
         s->lookahead += n;
 
         /* Initialize the hash value now that we have some input: */
-        if (s->lookahead + s->insert >= MIN_MATCH) {
+        if (s->lookahead + s->insert >= STD_MIN_MATCH) {
             unsigned int str = s->strstart - s->insert;
             if (str >= 1)
-                functable.quick_insert_string(s, str + 2 - MIN_MATCH);
-#if MIN_MATCH != 3
-#error Call insert_string() MIN_MATCH-3 more times
+                functable.quick_insert_string(s, str + 2 - STD_MIN_MATCH);
+#if STD_MIN_MATCH != 3
             while (s->insert) {
                 functable.quick_insert_string(s, str);
                 str++;
                 s->insert--;
-                if (s->lookahead + s->insert < MIN_MATCH)
+                if (s->lookahead + s->insert < STD_MIN_MATCH)
                     break;
             }
 #else
@@ -1250,7 +1249,7 @@ void Z_INTERNAL fill_window(deflate_state *s) {
             }
 #endif
         }
-        /* If the whole input has less than MIN_MATCH bytes, ins_h is garbage,
+        /* If the whole input has less than STD_MIN_MATCH bytes, ins_h is garbage,
          * but this is not important since only literal bytes will be emitted.
          */
     } while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0);
@@ -1259,8 +1258,8 @@ void Z_INTERNAL fill_window(deflate_state *s) {
      * written, then zero those bytes in order to avoid memory check reports of
      * the use of uninitialized (or uninitialised as Julian writes) bytes by
      * the longest match routines.  Update the high water mark for the next
-     * time through here.  WIN_INIT is set to MAX_MATCH since the longest match
-     * routines allow scanning to strstart + MAX_MATCH, ignoring lookahead.
+     * time through here.  WIN_INIT is set to STD_MAX_MATCH since the longest match
+     * routines allow scanning to strstart + STD_MAX_MATCH, ignoring lookahead.
      */
     if (s->high_water < s->window_size) {
         unsigned int curr = s->strstart + s->lookahead;
@@ -1292,8 +1291,6 @@ void Z_INTERNAL fill_window(deflate_state *s) {
            "not enough room for search");
 }
 
-
-
 #ifndef ZLIB_COMPAT
 /* =========================================================================
  * Checks whether buffer size is sufficient and whether this parameter is a duplicate.
index 7243d1d9d8f82669aad494abf7b2a71d41138632..cf7d4906161932551f0aedd4d6456e17285b62d1 100644 (file)
--- a/deflate.h
+++ b/deflate.h
@@ -141,7 +141,7 @@ typedef struct internal_state {
     /* Sliding window. Input bytes are read into the second half of the window,
      * and move to the first half later to keep a dictionary of at least wSize
      * bytes. With this organization, matches are limited to a distance of
-     * wSize-MAX_MATCH bytes, but this ensures that IO is always
+     * wSize-STD_MAX_MATCH bytes, but this ensures that IO is always
      * performed with a length multiple of the block size. Also, it limits
      * the window size to 64K, which is quite useful on MSDOS.
      * To do: use the user input buffer as sliding window.
@@ -363,17 +363,17 @@ static inline void put_uint64(deflate_state *s, uint64_t lld) {
 #endif
 }
 
-#define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
+#define MIN_LOOKAHEAD (STD_MAX_MATCH + STD_MIN_MATCH + 1)
 /* Minimum amount of lookahead, except at the end of the input file.
- * See deflate.c for comments about the MIN_MATCH+1.
+ * See deflate.c for comments about the STD_MIN_MATCH+1.
  */
 
-#define MAX_DIST(s)  ((s)->w_size-MIN_LOOKAHEAD)
+#define MAX_DIST(s)  ((s)->w_size - MIN_LOOKAHEAD)
 /* In order to simplify the code, particularly on 16 bit machines, match
  * distances are limited to MAX_DIST instead of WSIZE.
  */
 
-#define WIN_INIT MAX_MATCH
+#define WIN_INIT STD_MAX_MATCH
 /* Number of bytes after end of data in window to initialize in order to avoid
    memory checker errors from longest match routines */
 
index 1594886f8c5c8799a310e5060df122f0046faac1..4d335a3dc68b4b24f0fd00c35828ef2851148855 100644 (file)
@@ -24,8 +24,8 @@ Z_INTERNAL block_state deflate_fast(deflate_state *s, int flush) {
 
     for (;;) {
         /* Make sure that we always have enough lookahead, except
-         * at the end of the input file. We need MAX_MATCH bytes
-         * for the next match, plus MIN_MATCH bytes to insert the
+         * at the end of the input file. We need STD_MAX_MATCH bytes
+         * for the next match, plus WANT_MIN_MATCH bytes to insert the
          * string following the next match.
          */
         if (s->lookahead < MIN_LOOKAHEAD) {
@@ -40,14 +40,14 @@ Z_INTERNAL block_state deflate_fast(deflate_state *s, int flush) {
         /* Insert the string window[strstart .. strstart+2] in the
          * dictionary, and set hash_head to the head of the hash chain:
          */
-        if (s->lookahead >= MIN_MATCH) {
+        if (s->lookahead >= WANT_MIN_MATCH) {
             hash_head = functable.quick_insert_string(s, s->strstart);
             dist = (int64_t)s->strstart - hash_head;
 
             /* Find the longest match, discarding those <= prev_length.
-             * At this point we have always match length < MIN_MATCH
+             * At this point we have always match length < WANT_MIN_MATCH
              */
-            
+
             if (dist <= MAX_DIST(s) && dist > 0 && hash_head != 0) {
                 /* To simplify the code, we prevent matches with the string
                  * of window index 0 (in particular we have to avoid a match
@@ -58,17 +58,17 @@ Z_INTERNAL block_state deflate_fast(deflate_state *s, int flush) {
             }
         }
 
-        if (match_len >= MIN_MATCH) {
+        if (match_len >= WANT_MIN_MATCH) {
             check_match(s, s->strstart, s->match_start, match_len);
 
-            bflush = zng_tr_tally_dist(s, s->strstart - s->match_start, match_len - MIN_MATCH);
+            bflush = zng_tr_tally_dist(s, s->strstart - s->match_start, match_len - STD_MIN_MATCH);
 
             s->lookahead -= match_len;
 
             /* Insert new strings in the hash table only if the match length
              * is not too large. This saves time but degrades compression.
              */
-            if (match_len <= s->max_insert_length && s->lookahead >= MIN_MATCH) {
+            if (match_len <= s->max_insert_length && s->lookahead >= WANT_MIN_MATCH) {
                 match_len--; /* string at strstart already in table */
                 s->strstart++;
 
@@ -76,12 +76,12 @@ Z_INTERNAL block_state deflate_fast(deflate_state *s, int flush) {
                 s->strstart += match_len;
             } else {
                 s->strstart += match_len;
-#if MIN_MATCH != 3
-                functable.insert_string(s, s->strstart + 2 - MIN_MATCH, MIN_MATCH - 2);
+#if STD_MIN_MATCH != 3
+                functable.insert_string(s, s->strstart + 2 - STD_MIN_MATCH, STD_MIN_MATCH - 2);
 #else
-                functable.quick_insert_string(s, s->strstart + 2 - MIN_MATCH);
+                functable.quick_insert_string(s, s->strstart + 2 - STD_MIN_MATCH);
 #endif
-                /* If lookahead < MIN_MATCH, ins_h is garbage, but it does not
+                /* If lookahead < STD_MIN_MATCH, ins_h is garbage, but it does not
                  * matter since it will be recomputed at next deflate call.
                  */
             }
@@ -95,7 +95,7 @@ Z_INTERNAL block_state deflate_fast(deflate_state *s, int flush) {
         if (UNLIKELY(bflush))
             FLUSH_BLOCK(s, 0);
     }
-    s->insert = s->strstart < MIN_MATCH-1 ? s->strstart : MIN_MATCH-1;
+    s->insert = s->strstart < STD_MIN_MATCH-1 ? s->strstart : STD_MIN_MATCH-1;
     if (UNLIKELY(flush == Z_FINISH)) {
         FLUSH_BLOCK(s, 1);
         return finish_done;
index 303890a651504060fdd2618578a31944105abb57..25f3a0b1834f2c638bbead379830e1a6869d8704 100644 (file)
@@ -24,7 +24,7 @@ static int emit_match(deflate_state *s, struct match match) {
     int bflush = 0;
 
     /* matches that are not long enough we need to emit as literals */
-    if (match.match_length < MIN_MATCH) {
+    if (match.match_length < WANT_MIN_MATCH) {
         while (match.match_length) {
             bflush += zng_tr_tally_lit(s, s->window[match.strstart]);
             s->lookahead--;
@@ -36,18 +36,18 @@ static int emit_match(deflate_state *s, struct match match) {
 
     check_match(s, match.strstart, match.match_start, match.match_length);
 
-    bflush += zng_tr_tally_dist(s, match.strstart - match.match_start, match.match_length - MIN_MATCH);
+    bflush += zng_tr_tally_dist(s, match.strstart - match.match_start, match.match_length - STD_MIN_MATCH);
 
     s->lookahead -= match.match_length;
     return bflush;
 }
 
 static void insert_match(deflate_state *s, struct match match) {
-    if (UNLIKELY(s->lookahead <= (unsigned int)(match.match_length + MIN_MATCH)))
+    if (UNLIKELY(s->lookahead <= (unsigned int)(match.match_length + WANT_MIN_MATCH)))
         return;
 
     /* matches that are not long enough we need to emit as literals */
-    if (LIKELY(match.match_length < MIN_MATCH)) {
+    if (LIKELY(match.match_length < WANT_MIN_MATCH)) {
         match.strstart++;
         match.match_length--;
         if (UNLIKELY(match.match_length > 0)) {
@@ -67,7 +67,7 @@ static void insert_match(deflate_state *s, struct match match) {
     /* Insert new strings in the hash table only if the match length
      * is not too large. This saves time but degrades compression.
      */
-    if (match.match_length <= 16* s->max_insert_length && s->lookahead >= MIN_MATCH) {
+    if (match.match_length <= 16* s->max_insert_length && s->lookahead >= WANT_MIN_MATCH) {
         match.match_length--; /* string at strstart already in table */
         match.strstart++;
 
@@ -85,13 +85,13 @@ static void insert_match(deflate_state *s, struct match match) {
     } else {
         match.strstart += match.match_length;
         match.match_length = 0;
-        if (match.strstart >= (MIN_MATCH - 2))
-#if MIN_MATCH != 3
-            functable.insert_string(s, match.strstart + 2 - MIN_MATCH, MIN_MATCH - 2);
+        if (match.strstart >= (STD_MIN_MATCH - 2))
+#if STD_MIN_MATCH != 3
+            functable.insert_string(s, match.strstart + 2 - STD_MIN_MATCH, STD_MIN_MATCH - 2);
 #else
-            functable.quick_insert_string(s, match.strstart + 2 - MIN_MATCH);
+            functable.quick_insert_string(s, match.strstart + 2 - STD_MIN_MATCH);
 #endif
-        /* If lookahead < MIN_MATCH, ins_h is garbage, but it does not
+        /* If lookahead < WANT_MIN_MATCH, ins_h is garbage, but it does not
          * matter since it will be recomputed at next deflate call.
          */
     }
@@ -177,8 +177,8 @@ Z_INTERNAL block_state deflate_medium(deflate_state *s, int flush) {
         int64_t dist;
 
         /* Make sure that we always have enough lookahead, except
-         * at the end of the input file. We need MAX_MATCH bytes
-         * for the next match, plus MIN_MATCH bytes to insert the
+         * at the end of the input file. We need STD_MAX_MATCH bytes
+         * for the next match, plus WANT_MIN_MATCH bytes to insert the
          * string following the next current_match.
          */
         if (s->lookahead < MIN_LOOKAHEAD) {
@@ -201,7 +201,7 @@ Z_INTERNAL block_state deflate_medium(deflate_state *s, int flush) {
             next_match.match_length = 0;
         } else {
             hash_head = 0;
-            if (s->lookahead >= MIN_MATCH) {
+            if (s->lookahead >= WANT_MIN_MATCH) {
                 hash_head = functable.quick_insert_string(s, s->strstart);
             }
 
@@ -209,7 +209,7 @@ Z_INTERNAL block_state deflate_medium(deflate_state *s, int flush) {
             current_match.orgstart = current_match.strstart;
 
             /* Find the longest match, discarding those <= prev_length.
-             * At this point we have always match_length < MIN_MATCH
+             * At this point we have always match_length < WANT_MIN_MATCH
              */
 
             dist = (int64_t)s->strstart - hash_head;
@@ -220,7 +220,7 @@ Z_INTERNAL block_state deflate_medium(deflate_state *s, int flush) {
                  */
                 current_match.match_length = (uint16_t)functable.longest_match(s, hash_head);
                 current_match.match_start = (uint16_t)s->match_start;
-                if (UNLIKELY(current_match.match_length < MIN_MATCH))
+                if (UNLIKELY(current_match.match_length < WANT_MIN_MATCH))
                     current_match.match_length = 1;
                 if (UNLIKELY(current_match.match_start >= current_match.strstart)) {
                     /* this can happen due to some restarts */
@@ -244,7 +244,7 @@ Z_INTERNAL block_state deflate_medium(deflate_state *s, int flush) {
             next_match.orgstart = next_match.strstart;
 
             /* Find the longest match, discarding those <= prev_length.
-             * At this point we have always match_length < MIN_MATCH
+             * At this point we have always match_length < WANT_MIN_MATCH
              */
 
             dist = (int64_t)s->strstart - hash_head;
@@ -259,7 +259,7 @@ Z_INTERNAL block_state deflate_medium(deflate_state *s, int flush) {
                     /* this can happen due to some restarts */
                     next_match.match_length = 1;
                 }
-                if (next_match.match_length < MIN_MATCH)
+                if (next_match.match_length < WANT_MIN_MATCH)
                     next_match.match_length = 1;
                 else
                     fizzle_matches(s, &current_match, &next_match);
@@ -283,7 +283,7 @@ Z_INTERNAL block_state deflate_medium(deflate_state *s, int flush) {
         if (UNLIKELY(bflush))
             FLUSH_BLOCK(s, 0);
     }
-    s->insert = s->strstart < MIN_MATCH-1 ? s->strstart : MIN_MATCH-1;
+    s->insert = s->strstart < STD_MIN_MATCH-1 ? s->strstart : STD_MIN_MATCH-1;
     if (flush == Z_FINISH) {
         FLUSH_BLOCK(s, 1);
         return finish_done;
index becaf71e3e8b264da365e7b3f1ccdc6a9ff05e41..9b23c51ebad762cc6f9dddf02c7c15eac39fa1af 100644 (file)
@@ -17,7 +17,7 @@
  */
 static inline void check_match(deflate_state *s, Pos start, Pos match, int length) {
     /* check that the match length is valid*/
-    if (length < MIN_MATCH || length > MAX_MATCH) {
+    if (length < STD_MIN_MATCH || length > STD_MAX_MATCH) {
         fprintf(stderr, " start %u, match %u, length %d\n", start, match, length);
         z_error("invalid match length");
     }
@@ -65,13 +65,13 @@ static inline int zng_tr_tally_lit(deflate_state *s, unsigned char c) {
     s->sym_buf[s->sym_next++] = c;
     s->dyn_ltree[c].Freq++;
     Tracevv((stderr, "%c", c));
-    Assert(c <= (MAX_MATCH-MIN_MATCH), "zng_tr_tally: bad literal");
+    Assert(c <= (STD_MAX_MATCH-STD_MIN_MATCH), "zng_tr_tally: bad literal");
     return (s->sym_next == s->sym_end);
 }
 
 static inline int zng_tr_tally_dist(deflate_state *s, uint32_t dist, uint32_t len) {
     /* dist: distance of matched string */
-    /* len: match length-MIN_MATCH */
+    /* len: match length-STD_MIN_MATCH */
     s->sym_buf[s->sym_next++] = (uint8_t)(dist);
     s->sym_buf[s->sym_next++] = (uint8_t)(dist >> 8);
     s->sym_buf[s->sym_next++] = (uint8_t)len;
index b4397434988190834967d4a49ad386ea011ec35c..50e861cceb51c3783430e06724d49704eb1cd91a 100644 (file)
@@ -84,20 +84,20 @@ Z_INTERNAL block_state deflate_quick(deflate_state *s, int flush) {
             }
         }
 
-        if (LIKELY(s->lookahead >= MIN_MATCH)) {
+        if (LIKELY(s->lookahead >= WANT_MIN_MATCH)) {
             hash_head = functable.quick_insert_string(s, s->strstart);
             dist = (int64_t)s->strstart - hash_head;
 
             if (dist <= MAX_DIST(s) && dist > 0) {
                 match_len = functable.compare258(s->window + s->strstart, s->window + hash_head);
 
-                if (match_len >= MIN_MATCH) {
+                if (match_len >= WANT_MIN_MATCH) {
                     if (UNLIKELY(match_len > s->lookahead))
                         match_len = s->lookahead;
 
                     check_match(s, s->strstart, hash_head, match_len);
 
-                    zng_tr_emit_dist(s, static_ltree, static_dtree, match_len - MIN_MATCH, (uint32_t)dist);
+                    zng_tr_emit_dist(s, static_ltree, static_dtree, match_len - STD_MIN_MATCH, (uint32_t)dist);
                     s->lookahead -= match_len;
                     s->strstart += match_len;
                     continue;
@@ -110,7 +110,7 @@ Z_INTERNAL block_state deflate_quick(deflate_state *s, int flush) {
         s->lookahead--;
     }
 
-    s->insert = s->strstart < MIN_MATCH-1 ? s->strstart : MIN_MATCH-1;
+    s->insert = s->strstart < STD_MIN_MATCH-1 ? s->strstart : STD_MIN_MATCH-1;
     if (UNLIKELY(last)) {
         QUICK_END_BLOCK(s, 1);
         return finish_done;
index c3899b775137e6afded7d963be6464cf17786991..9e669ec545a3287ec4921b349327dd763b490d3d 100644 (file)
@@ -22,40 +22,40 @@ Z_INTERNAL block_state deflate_rle(deflate_state *s, int flush) {
 
     for (;;) {
         /* Make sure that we always have enough lookahead, except
-         * at the end of the input file. We need MAX_MATCH bytes
+         * at the end of the input file. We need STD_MAX_MATCH bytes
          * for the longest run, plus one for the unrolled loop.
          */
-        if (s->lookahead <= MAX_MATCH) {
+        if (s->lookahead <= STD_MAX_MATCH) {
             fill_window(s);
-            if (s->lookahead <= MAX_MATCH && flush == Z_NO_FLUSH)
+            if (s->lookahead <= STD_MAX_MATCH && flush == Z_NO_FLUSH)
                 return need_more;
             if (s->lookahead == 0)
                 break; /* flush the current block */
         }
 
         /* See how many times the previous byte repeats */
-        if (s->lookahead >= MIN_MATCH && s->strstart > 0) {
+        if (s->lookahead >= STD_MIN_MATCH && s->strstart > 0) {
             scan = s->window + s->strstart - 1;
             prev = *scan;
             if (prev == *++scan && prev == *++scan && prev == *++scan) {
-                strend = s->window + s->strstart + MAX_MATCH;
+                strend = s->window + s->strstart + STD_MAX_MATCH;
                 do {
                 } while (prev == *++scan && prev == *++scan &&
                          prev == *++scan && prev == *++scan &&
                          prev == *++scan && prev == *++scan &&
                          prev == *++scan && prev == *++scan &&
                          scan < strend);
-                match_len = MAX_MATCH - (unsigned int)(strend - scan);
+                match_len = STD_MAX_MATCH - (unsigned int)(strend - scan);
                 match_len = MIN(match_len, s->lookahead);
             }
             Assert(scan <= s->window + s->window_size - 1, "wild scan");
         }
 
-        /* Emit match if have run of MIN_MATCH or longer, else emit literal */
-        if (match_len >= MIN_MATCH) {
+        /* Emit match if have run of STD_MIN_MATCH or longer, else emit literal */
+        if (match_len >= STD_MIN_MATCH) {
             check_match(s, s->strstart, s->strstart - 1, match_len);
 
-            bflush = zng_tr_tally_dist(s, 1, match_len - MIN_MATCH);
+            bflush = zng_tr_tally_dist(s, 1, match_len - STD_MIN_MATCH);
 
             s->lookahead -= match_len;
             s->strstart += match_len;
index dc1c0723913401b8cfbb01ec05879781188e825c..d97eb2c974dce2b2adc9329a9114ae8a62216f20 100644 (file)
@@ -23,8 +23,8 @@ Z_INTERNAL block_state deflate_slow(deflate_state *s, int flush) {
     /* Process the input block. */
     for (;;) {
         /* Make sure that we always have enough lookahead, except
-         * at the end of the input file. We need MAX_MATCH bytes
-         * for the next match, plus MIN_MATCH bytes to insert the
+         * at the end of the input file. We need STD_MAX_MATCH bytes
+         * for the next match, plus WANT_MIN_MATCH bytes to insert the
          * string following the next match.
          */
         if (s->lookahead < MIN_LOOKAHEAD) {
@@ -40,14 +40,14 @@ Z_INTERNAL block_state deflate_slow(deflate_state *s, int flush) {
          * dictionary, and set hash_head to the head of the hash chain:
          */
         hash_head = 0;
-        if (LIKELY(s->lookahead >= MIN_MATCH)) {
+        if (LIKELY(s->lookahead >= WANT_MIN_MATCH)) {
             hash_head = functable.quick_insert_string(s, s->strstart);
         }
 
         /* Find the longest match, discarding those <= prev_length.
          */
         s->prev_match = (Pos)s->match_start;
-        match_len = MIN_MATCH-1;
+        match_len = STD_MIN_MATCH-1;
         dist = (int64_t)s->strstart - hash_head;
 
         if (dist <= MAX_DIST(s) && dist > 0 && s->prev_length < s->max_lazy_match && hash_head != 0) {
@@ -59,22 +59,22 @@ Z_INTERNAL block_state deflate_slow(deflate_state *s, int flush) {
             /* longest_match() sets match_start */
 
             if (match_len <= 5 && (s->strategy == Z_FILTERED)) {
-                /* If prev_match is also MIN_MATCH, match_start is garbage
+                /* If prev_match is also WANT_MIN_MATCH, match_start is garbage
                  * but we will ignore the current match anyway.
                  */
-                match_len = MIN_MATCH-1;
+                match_len = STD_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 && match_len <= s->prev_length) {
-            unsigned int max_insert = s->strstart + s->lookahead - MIN_MATCH;
+        if (s->prev_length >= WANT_MIN_MATCH && match_len <= s->prev_length) {
+            unsigned int max_insert = s->strstart + s->lookahead - WANT_MIN_MATCH;
             /* Do not insert strings in hash table beyond this. */
 
             check_match(s, s->strstart-1, s->prev_match, s->prev_length);
 
-            bflush = zng_tr_tally_dist(s, s->strstart -1 - s->prev_match, s->prev_length - MIN_MATCH);
+            bflush = zng_tr_tally_dist(s, s->strstart -1 - s->prev_match, s->prev_length - STD_MIN_MATCH);
 
             /* Insert in hash table all strings up to the end of the match.
              * strstart-1 and strstart are already inserted. If there is not
@@ -126,7 +126,7 @@ Z_INTERNAL block_state deflate_slow(deflate_state *s, int flush) {
         (void) zng_tr_tally_lit(s, s->window[s->strstart-1]);
         s->match_available = 0;
     }
-    s->insert = s->strstart < MIN_MATCH-1 ? s->strstart : MIN_MATCH-1;
+    s->insert = s->strstart < STD_MIN_MATCH-1 ? s->strstart : STD_MIN_MATCH-1;
     if (UNLIKELY(flush == Z_FINISH)) {
         FLUSH_BLOCK(s, 1);
         return finish_done;
index 9796e5196cc4fb2fc741bebdbdde78e1a3c061ae..11d54643fed6cd6e7609e31b6b7008f55edaa3cd 100644 (file)
@@ -57,8 +57,8 @@ Z_INTERNAL Pos QUICK_INSERT_STRING(deflate_state *const s, const uint32_t str) {
  * of the hash chain (the most recent string with same hash key). Return
  * the previous length of the hash chain.
  * IN  assertion: all calls to to INSERT_STRING are made with consecutive
- *    input characters and the first MIN_MATCH bytes of str are valid
- *    (except for the last MIN_MATCH-1 bytes of the input file).
+ *    input characters and the first STD_MIN_MATCH bytes of str are valid
+ *    (except for the last STD_MIN_MATCH-1 bytes of the input file).
  */
 Z_INTERNAL void INSERT_STRING(deflate_state *const s, const uint32_t str, uint32_t count) {
     uint8_t *strstart = s->window + str;
index b15ca17b9105a9b8d1b26e0dd0bb48225abe48ac..04eac1aa8f2d419cedae32d154eab6d3c0c56061 100644 (file)
@@ -52,8 +52,8 @@ Z_INTERNAL uint32_t LONGEST_MATCH(deflate_state *const s, Pos cur_match) {
         continue; \
     return best_len;
 
-    /* The code is optimized for MAX_MATCH-2 multiple of 16. */
-    Assert(MAX_MATCH == 258, "Code too clever");
+    /* The code is optimized for STD_MAX_MATCH-2 multiple of 16. */
+    Assert(STD_MAX_MATCH == 258, "Code too clever");
 
     best_len = s->prev_length ? s->prev_length : 1;
 
index c648a650c8a6dece62abfe834b2008d39120bd8b..282bddc2e5d3f07c2f38c8da8490597ff26fe7a6 100644 (file)
@@ -23,11 +23,11 @@ static unsigned char dist_code[DIST_CODE_LEN];
  * the last 256 values correspond to the top 8 bits of the 15 bit distances.
  */
 
-static unsigned char length_code[MAX_MATCH-MIN_MATCH+1];
-/* length code for each normalized match length (0 == MIN_MATCH) */
+static unsigned char length_code[STD_MAX_MATCH-STD_MIN_MATCH+1];
+/* length code for each normalized match length (0 == STD_MIN_MATCH) */
 
 static int base_length[LENGTH_CODES];
-/* First normalized length for each code (0 = MIN_MATCH) */
+/* First normalized length for each code (0 = STD_MIN_MATCH) */
 
 static int base_dist[D_CODES];
 /* First normalized distance for each code (0 = distance of 1) */
@@ -121,9 +121,9 @@ static void gen_trees_header() {
         printf("%2u%s", dist_code[i], SEPARATOR(i, DIST_CODE_LEN-1, 20));
     }
 
-    printf("const unsigned char Z_INTERNAL zng_length_code[MAX_MATCH-MIN_MATCH+1] = {\n");
-    for (i = 0; i < MAX_MATCH-MIN_MATCH+1; i++) {
-        printf("%2u%s", length_code[i], SEPARATOR(i, MAX_MATCH-MIN_MATCH, 20));
+    printf("const unsigned char Z_INTERNAL zng_length_code[STD_MAX_MATCH-STD_MIN_MATCH+1] = {\n");
+    for (i = 0; i < STD_MAX_MATCH-STD_MIN_MATCH+1; i++) {
+        printf("%2u%s", length_code[i], SEPARATOR(i, STD_MAX_MATCH-STD_MIN_MATCH, 20));
     }
 
     printf("Z_INTERNAL const int base_length[LENGTH_CODES] = {\n");
index 118dbb2d8fd6fbaa01d974aca13c103caa0d21d6..454488edb36ac2d349877ecc933ef2f20d6940bd 100644 (file)
@@ -16,7 +16,7 @@ extern Z_INTERNAL const ct_data static_ltree[L_CODES+2];
 extern Z_INTERNAL const ct_data static_dtree[D_CODES];
 
 extern const unsigned char Z_INTERNAL zng_dist_code[DIST_CODE_LEN];
-extern const unsigned char Z_INTERNAL zng_length_code[MAX_MATCH-MIN_MATCH+1];
+extern const unsigned char Z_INTERNAL zng_length_code[STD_MAX_MATCH-STD_MIN_MATCH+1];
 
 extern Z_INTERNAL const int base_length[LENGTH_CODES];
 extern Z_INTERNAL const int base_dist[D_CODES];
@@ -126,7 +126,7 @@ static inline uint32_t zng_emit_dist(deflate_state *s, const ct_data *ltree, con
     uint32_t bi_valid = s->bi_valid;
     uint64_t bi_buf = s->bi_buf;
 
-    /* Send the length code, len is the match length - MIN_MATCH */
+    /* Send the length code, len is the match length - STD_MIN_MATCH */
     code = zng_length_code[lc];
     c = code+LITERALS+1;
     Assert(c < L_CODES, "bad l_code");
index a4c68a56651cd5b0d0198bbd86a19534bd7c27ac..a3912b7fd7677e2e9b53f667997d98c1e22099df 100644 (file)
@@ -102,7 +102,7 @@ const unsigned char Z_INTERNAL zng_dist_code[DIST_CODE_LEN] = {
 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29
 };
 
-const unsigned char Z_INTERNAL zng_length_code[MAX_MATCH-MIN_MATCH+1] = {
+const unsigned char Z_INTERNAL zng_length_code[STD_MAX_MATCH-STD_MIN_MATCH+1] = {
  0,  1,  2,  3,  4,  5,  6,  7,  8,  8,  9,  9, 10, 10, 11, 11, 12, 12, 12, 12,
 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16,
 17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19,
diff --git a/zutil.h b/zutil.h
index 11e48757614d5911d7a5fbf16bf08a3cd0a795a1..fa08f2aa782a57fef80d9319b1aef0440bd0e7b3 100644 (file)
--- a/zutil.h
+++ b/zutil.h
@@ -70,9 +70,12 @@ extern z_const char * const PREFIX(z_errmsg)[10]; /* indexed by 2-zlib_error */
 #define DYN_TREES    2
 /* The three kinds of block type */
 
-#define MIN_MATCH  3
-#define MAX_MATCH  258
-/* The minimum and maximum match lengths */
+#define STD_MIN_MATCH  3
+#define STD_MAX_MATCH  258
+/* The minimum and maximum match lengths mandated by the deflate standard */
+
+#define WANT_MIN_MATCH  4
+/* The minimum wanted match length, affects deflate_quick, deflate_fast, deflate_medium and deflate_slow  */
 
 #define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */