]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Rebalance levels 1-4.
authorHans Kristian Rosbach <hk-git@circlestorm.org>
Fri, 26 Mar 2021 15:21:23 +0000 (16:21 +0100)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Sat, 12 Jun 2021 18:35:34 +0000 (20:35 +0200)
- Deflate_quick (level 1), no longer limit window, improves compression.
- Deflate_medium, don't check next position for levels below 5.
- Use deflate_medium instead of deflate_fast for level 3.
- Tweak level 4 to give a more predictable speed/compression tradeoff curve.

deflate.c
deflate_medium.c

index 3acd6d4f7309c90e2655e2cfc35c7f6053cacdaf..076b05f199bdf460b75b13f95f291ec605df0739 100644 (file)
--- a/deflate.c
+++ b/deflate.c
@@ -144,21 +144,21 @@ static const config configuration_table[10] = {
 /* 0 */ {0,    0,  0,    0, deflate_stored},  /* store only */
 
 #ifndef NO_QUICK_STRATEGY
-/* 1 */ {4,    4,  8,    4, deflate_quick},
+/* 1 */ {0,    0,  0,    0, deflate_quick},
 /* 2 */ {4,    4,  8,    4, deflate_fast}, /* max speed, no lazy matches */
 #else
 /* 1 */ {4,    4,  8,    4, deflate_fast}, /* max speed, no lazy matches */
 /* 2 */ {4,    5, 16,    8, deflate_fast},
 #endif
 
-/* 3 */ {4,    6, 32,   32, deflate_fast},
-
 #ifdef NO_MEDIUM_STRATEGY
+/* 3 */ {4,    6, 32,   32, deflate_fast},
 /* 4 */ {4,    4, 16,   16, deflate_slow},  /* lazy matches */
 /* 5 */ {8,   16, 32,   32, deflate_slow},
 /* 6 */ {8,   16, 128, 128, deflate_slow},
 #else
-/* 4 */ {4,    4, 16,   16, deflate_medium},  /* lazy matches */
+/* 3 */ {4,    6, 16,    6, deflate_medium},
+/* 4 */ {4,   12, 32,   24, deflate_medium},  /* lazy matches */
 /* 5 */ {8,   16, 32,   32, deflate_medium},
 /* 6 */ {8,   16, 128, 128, deflate_medium},
 #endif
@@ -281,11 +281,6 @@ int32_t Z_EXPORT PREFIX(deflateInit2_)(PREFIX3(stream) *strm, int32_t level, int
     if (windowBits == 8)
         windowBits = 9;  /* until 256-byte window bug fixed */
 
-#if !defined(NO_QUICK_STRATEGY) && !defined(S390_DFLTCC_DEFLATE)
-    if (level == 1)
-        windowBits = 13;
-#endif
-
     s = (deflate_state *) ZALLOC_STATE(strm, 1, sizeof(deflate_state));
     if (s == NULL)
         return Z_MEM_ERROR;
index 59ccfa89efce10aeb89c5e9fce19883fb2cdea3d..303890a651504060fdd2618578a31944105abb57 100644 (file)
@@ -165,6 +165,9 @@ Z_INTERNAL block_state deflate_medium(deflate_state *s, int flush) {
     ALIGNED_(16) struct match current_match;
                  struct match next_match;
 
+    /* For levels below 5, don't check the next position for a better match */
+    int early_exit = s->level < 5;
+
     memset(&current_match, 0, sizeof(struct match));
     memset(&next_match, 0, sizeof(struct match));
 
@@ -193,7 +196,7 @@ Z_INTERNAL block_state deflate_medium(deflate_state *s, int flush) {
          */
 
         /* If we already have a future match from a previous round, just use that */
-        if (next_match.match_length > 0) {
+        if (!early_exit && next_match.match_length > 0) {
             current_match = next_match;
             next_match.match_length = 0;
         } else {
@@ -233,7 +236,7 @@ Z_INTERNAL block_state deflate_medium(deflate_state *s, int flush) {
         insert_match(s, current_match);
 
         /* now, look ahead one */
-        if (LIKELY(s->lookahead > MIN_LOOKAHEAD && (uint32_t)(current_match.strstart + current_match.match_length) < (s->window_size - MIN_LOOKAHEAD))) {
+        if (LIKELY(!early_exit && s->lookahead > MIN_LOOKAHEAD && (uint32_t)(current_match.strstart + current_match.match_length) < (s->window_size - MIN_LOOKAHEAD))) {
             s->strstart = current_match.strstart + current_match.match_length;
             hash_head = functable.quick_insert_string(s, s->strstart);