Non Z_RLE -related patches

There are a couple of patches to deflate.c, not related to Z_RLE.

This patch removes an unnecessary assignment to level (applied in pngcrush by Glenn Randers-Pehrson):
@@ -232,9 +232,10 @@
     }
     if (strm->zfree == Z_NULL) strm->zfree = zcfree;

-    if (level == Z_DEFAULT_COMPRESSION) level = 6;
 #ifdef FASTEST
     level = 1;
+#else
+    if (level == Z_DEFAULT_COMPRESSION) level = 6;
 #endif

     if (windowBits < 0) { /* undocumented feature: suppress zlib header */


This patch is really making compilers happy. The previous solution was not enough, because the "vacuous" variable assignment is happening with or without "if (hash_head) hash_head = 0":
@@ -327,8 +330,7 @@
     for (n = 0; n <= length - MIN_MATCH; n++) {
 	INSERT_STRING(s, n, hash_head);
     }
-    if (hash_head) hash_head = 0;  /* to make compiler happy */
-    return Z_OK;
+    return (hash_head) ? Z_OK : Z_OK;  /* make compilers happy */
 }


This patch is eliminating the test "more == (unsigned)(-1)" at compile time, if the machine word has more than 16 bits:
@@ -1017,7 +1019,7 @@
         if (more == 0 && s->strstart == 0 && s->lookahead == 0) {
             more = wsize;

-        } else if (more == (unsigned)(-1)) {
+        } else if (sizeof(more) == 2 && more == (unsigned)(-1)) {
             /* Very unlikely, but possible on 16 bit machine if strstart == 0
              * and lookahead == 1 (input done one byte at time)
              */


This patch is eliminating the comparison with TOO_FAR at compile time, if possible (applied in pngcrush by Glenn Randers-Pehrson):
@@ -1321,9 +1323,12 @@
             }
             /* longest_match() sets match_start */

-            if (s->match_length <= 5 && (s->strategy == Z_FILTERED ||
-                 (s->match_length == MIN_MATCH &&
-                  s->strstart - s->match_start > TOO_FAR))) {
+            if (s->match_length <= 5 && (s->strategy == Z_FILTERED
+#if TOO_FAR > 0 && TOO_FAR < 32767
+                || (s->match_length == MIN_MATCH &&
+                    s->strstart - s->match_start > TOO_FAR)
+#endif
+                )) {

                 /* If prev_match is also MIN_MATCH, match_start is garbage
                  * but we will ignore the current match anyway.

Back to Z_RLE main page