From: Nathan Moinvaziri Date: Sat, 29 May 2021 01:15:50 +0000 (-0700) Subject: Clean up deflate_stored and deflate_rle by using MIN() where applicable. X-Git-Tag: 2.1.0-beta1~584 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d4dd539d1c08ce0affb360120a9e4ac2396e734b;p=thirdparty%2Fzlib-ng.git Clean up deflate_stored and deflate_rle by using MIN() where applicable. --- diff --git a/deflate_rle.c b/deflate_rle.c index c09bcc44e..c3899b775 100644 --- a/deflate_rle.c +++ b/deflate_rle.c @@ -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"); } diff --git a/deflate_stored.c b/deflate_stored.c index 134ed619b..860d894dd 100644 --- a/deflate_stored.c +++ b/deflate_stored.c @@ -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