From: Hans Kristian Rosbach Date: Fri, 26 Mar 2021 15:21:23 +0000 (+0100) Subject: Rebalance levels 1-4. X-Git-Tag: 2.1.0-beta1~582 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ce6789c7e093e8e6bb6fc591bbdf0f805999bdb9;p=thirdparty%2Fzlib-ng.git Rebalance levels 1-4. - 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. --- diff --git a/deflate.c b/deflate.c index 3acd6d4f7..076b05f19 100644 --- 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; diff --git a/deflate_medium.c b/deflate_medium.c index 59ccfa89e..303890a65 100644 --- a/deflate_medium.c +++ b/deflate_medium.c @@ -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(¤t_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);