]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Clean up deflate_stored and deflate_rle by using MIN() where applicable.
authorNathan Moinvaziri <nathan@solidstatenetworks.com>
Sat, 29 May 2021 01:15:50 +0000 (18:15 -0700)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Sat, 12 Jun 2021 17:34:42 +0000 (19:34 +0200)
deflate_rle.c
deflate_stored.c

index c09bcc44ec4e0067da21e5502b5ff4e16688eb24..c3899b775137e6afded7d963be6464cf17786991 100644 (file)
@@ -46,8 +46,7 @@ Z_INTERNAL block_state deflate_rle(deflate_state *s, int flush) {
                          prev == *++scan && prev == *++scan &&
                          scan < strend);
                 match_len = MAX_MATCH - (unsigned int)(strend - scan);
-                if (match_len > s->lookahead)
-                    match_len = s->lookahead;
+                match_len = MIN(match_len, s->lookahead);
             }
             Assert(scan <= s->window + s->window_size - 1, "wild scan");
         }
index 134ed619babc0f302b4f3e2d68ae7f60c55e299e..860d894ddd923754d1aea1ea2de93f4989fa8f8a 100644 (file)
@@ -51,8 +51,7 @@ Z_INTERNAL block_state deflate_stored(deflate_state *s, int flush) {
         left = (int)s->strstart - s->block_start;    /* bytes left in window */
         if (len > (unsigned long)left + s->strm->avail_in)
             len = left + s->strm->avail_in;     /* limit len to the input */
-        if (len > have)
-            len = have;                         /* limit len to the output */
+        len = MIN(len, have);                   /* limit len to the output */
 
         /* If the stored block would be less than min_block in length, or if
          * unable to copy all of the available input when flushing, then try
@@ -82,8 +81,7 @@ Z_INTERNAL block_state deflate_stored(deflate_state *s, int flush) {
 
         /* Copy uncompressed bytes from the window to next_out. */
         if (left) {
-            if (left > len)
-                left = len;
+            left = MIN(left, len);
             memcpy(s->strm->next_out, s->window + s->block_start, left);
             s->strm->next_out += left;
             s->strm->avail_out -= left;
@@ -126,8 +124,7 @@ Z_INTERNAL block_state deflate_stored(deflate_state *s, int flush) {
                 memcpy(s->window, s->window + s->w_size, s->strstart);
                 if (s->matches < 2)
                     s->matches++;   /* add a pending slide_hash() */
-                if (s->insert > s->strstart)
-                    s->insert = s->strstart;
+                s->insert = MIN(s->insert, s->strstart);
             }
             memcpy(s->window + s->strstart, s->strm->next_in - used, used);
             s->strstart += used;
@@ -135,8 +132,7 @@ Z_INTERNAL block_state deflate_stored(deflate_state *s, int flush) {
         }
         s->block_start = (int)s->strstart;
     }
-    if (s->high_water < s->strstart)
-        s->high_water = s->strstart;
+    s->high_water = MIN(s->high_water, s->strstart);
 
     /* If the last block was written to next_out, then done. */
     if (last)
@@ -156,18 +152,16 @@ Z_INTERNAL block_state deflate_stored(deflate_state *s, int flush) {
         if (s->matches < 2)
             s->matches++;           /* add a pending slide_hash() */
         have += s->w_size;          /* more space now */
-        if (s->insert > s->strstart)
-            s->insert = s->strstart;
+        s->insert = MIN(s->insert, s->strstart);
     }
-    if (have > s->strm->avail_in)
-        have = s->strm->avail_in;
+
+    have = MIN(have, s->strm->avail_in);
     if (have) {
         read_buf(s->strm, s->window + s->strstart, have);
         s->strstart += have;
         s->insert += MIN(have, s->w_size - s->insert);
     }
-    if (s->high_water < s->strstart)
-        s->high_water = s->strstart;
+    s->high_water = MIN(s->high_water, s->strstart);
 
     /* There was not enough avail_out to write a complete worthy or flushed
      * stored block to next_out. Write a stored block to pending instead, if we