]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Minor cleanups of some variables in deflate functions
authorHans Kristian Rosbach <hk-git@circlestorm.org>
Fri, 28 Nov 2025 23:49:37 +0000 (18:49 -0500)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Sat, 29 Nov 2025 22:14:49 +0000 (23:14 +0100)
deflate.h
deflate_fast.c
deflate_quick.c
deflate_slow.c

index 26553983b2b9c8234069a79c69414a7c75bcb6bc..6d5558d66cb195c7c6a9f91d60c1c9c8c3fb7819 100644 (file)
--- 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.
      */
index e682697d5cc51849e098635c95d5adcc24ce6e7f..efb95b856ed578da3d24468a5c3f4daa8cb76975 100644 (file)
@@ -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;
index d5fd986d7ac6d58dee3efa062c9ee3117d891da2..f9312a2eba9e735dd0189ce9112b4b4879980d9d 100644 (file)
@@ -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))
index 4165eea2afe72a767c81b905d0c85bef41c5047b..e9d7fc76cea4d3e587d4393f8f5e18b967cd36a2 100644 (file)
  * 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