From: Hans Kristian Rosbach Date: Fri, 28 Nov 2025 23:49:37 +0000 (-0500) Subject: Minor cleanups of some variables in deflate functions X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=829a23473ca0943e2ebae582b1d2211b42d862f8;p=thirdparty%2Fzlib-ng.git Minor cleanups of some variables in deflate functions --- diff --git a/deflate.h b/deflate.h index 26553983b..6d5558d66 100644 --- a/deflate.h +++ b/deflate.h @@ -155,7 +155,7 @@ struct ALIGNED_(64) internal_state { int last_flush; /* value of flush param for previous deflate call */ int reproducible; /* Whether reproducible compression results are required. */ - int block_open; + unsigned int block_open; /* Whether or not a block is currently open for the QUICK deflation scheme. * This is set to 1 if there is an active block, or 0 if the block was just closed. */ diff --git a/deflate_fast.c b/deflate_fast.c index e682697d5..efb95b856 100644 --- a/deflate_fast.c +++ b/deflate_fast.c @@ -17,9 +17,7 @@ * matches. It is used only for the fast compression options. */ Z_INTERNAL block_state deflate_fast(deflate_state *s, int flush) { - Pos hash_head; /* head of the hash chain */ int bflush = 0; /* set if current block must be flushed */ - int64_t dist; uint32_t match_len = 0; for (;;) { @@ -41,8 +39,8 @@ Z_INTERNAL block_state deflate_fast(deflate_state *s, int flush) { * dictionary, and set hash_head to the head of the hash chain: */ if (s->lookahead >= WANT_MIN_MATCH) { - hash_head = quick_insert_string(s, s->strstart); - dist = (int64_t)s->strstart - hash_head; + Pos hash_head = quick_insert_string(s, s->strstart); + int64_t dist = (int64_t)s->strstart - hash_head; /* Find the longest match, discarding those <= prev_length. * At this point we have always match length < WANT_MIN_MATCH @@ -94,6 +92,7 @@ Z_INTERNAL block_state deflate_fast(deflate_state *s, int flush) { FLUSH_BLOCK(s, 0); } 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; diff --git a/deflate_quick.c b/deflate_quick.c index d5fd986d7..f9312a2eb 100644 --- a/deflate_quick.c +++ b/deflate_quick.c @@ -29,7 +29,7 @@ extern const ct_data static_dtree[D_CODES]; #define QUICK_START_BLOCK(s, last) { \ zng_tr_emit_tree(s, STATIC_TREES, last); \ - s->block_open = 1 + (int)last; \ + s->block_open = 1 + last; \ s->block_start = (int)s->strstart; \ } @@ -45,12 +45,7 @@ extern const ct_data static_dtree[D_CODES]; } Z_INTERNAL block_state deflate_quick(deflate_state *s, int flush) { - Pos hash_head; - int64_t dist; - unsigned match_len, last; - - - last = (flush == Z_FINISH) ? 1 : 0; + unsigned last = (flush == Z_FINISH) ? 1 : 0; if (UNLIKELY(last && s->block_open != 2)) { /* Emit end of previous block */ QUICK_END_BLOCK(s, 0); @@ -86,15 +81,15 @@ Z_INTERNAL block_state deflate_quick(deflate_state *s, int flush) { } if (LIKELY(s->lookahead >= WANT_MIN_MATCH)) { - hash_head = quick_insert_string(s, s->strstart); - dist = (int64_t)s->strstart - hash_head; + Pos hash_head = quick_insert_string(s, s->strstart); + int64_t dist = (int64_t)s->strstart - hash_head; if (dist <= MAX_DIST(s) && dist > 0) { const uint8_t *str_start = s->window + s->strstart; const uint8_t *match_start = s->window + hash_head; if (zng_memcmp_2(str_start, match_start) == 0) { - match_len = FUNCTABLE_CALL(compare256)(str_start+2, match_start+2) + 2; + uint32_t match_len = FUNCTABLE_CALL(compare256)(str_start+2, match_start+2) + 2; if (match_len >= WANT_MIN_MATCH) { if (UNLIKELY(match_len > s->lookahead)) diff --git a/deflate_slow.c b/deflate_slow.c index 4165eea2a..e9d7fc76c 100644 --- a/deflate_slow.c +++ b/deflate_slow.c @@ -15,10 +15,7 @@ * no better match at the next window position. */ Z_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 */ - int64_t dist; - uint32_t match_len; match_func longest_match; if (s->max_chain_length <= 1024) @@ -45,7 +42,7 @@ Z_INTERNAL block_state deflate_slow(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: */ - hash_head = 0; + Pos hash_head = 0; if (LIKELY(s->lookahead >= WANT_MIN_MATCH)) { hash_head = s->quick_insert_string(s, s->strstart); } @@ -53,8 +50,8 @@ Z_INTERNAL block_state deflate_slow(deflate_state *s, int flush) { /* Find the longest match, discarding those <= prev_length. */ s->prev_match = (Pos)s->match_start; - match_len = STD_MIN_MATCH - 1; - dist = (int64_t)s->strstart - hash_head; + uint32_t match_len = STD_MIN_MATCH - 1; + int64_t dist = (int64_t)s->strstart - hash_head; if (dist <= MAX_DIST(s) && dist > 0 && s->prev_length < s->max_lazy_match && hash_head != 0) { /* To simplify the code, we prevent matches with the string