From: Hans Kristian Rosbach Date: Wed, 7 Feb 2024 18:21:36 +0000 (+0100) Subject: Remove branch that is almost impossible to hit in bi_flush(). X-Git-Tag: 2.2.0~79 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6f5bdddad17e6e0e13dd8be82fa80858d4616b45;p=thirdparty%2Fzlib-ng.git Remove branch that is almost impossible to hit in bi_flush(). Add case that handles sizes >=48. --- diff --git a/trees.c b/trees.c index 44b4a878..4189cc73 100644 --- a/trees.c +++ b/trees.c @@ -791,26 +791,25 @@ static int detect_data_type(deflate_state *s) { * Flush the bit buffer, keeping at most 7 bits in it. */ static void bi_flush(deflate_state *s) { - if (s->bi_valid == 64) { - put_uint64(s, s->bi_buf); - s->bi_buf = 0; - s->bi_valid = 0; - } else { - if (s->bi_valid >= 32) { - put_uint32(s, (uint32_t)s->bi_buf); - s->bi_buf >>= 32; - s->bi_valid -= 32; - } - if (s->bi_valid >= 16) { - put_short(s, (uint16_t)s->bi_buf); - s->bi_buf >>= 16; - s->bi_valid -= 16; - } - if (s->bi_valid >= 8) { - put_byte(s, s->bi_buf); - s->bi_buf >>= 8; - s->bi_valid -= 8; - } + if (s->bi_valid >= 48) { + put_uint32(s, (uint32_t)s->bi_buf); + put_short(s, (uint16_t)(s->bi_buf >> 32)); + s->bi_buf >>= 48; + s->bi_valid -= 48; + } else if (s->bi_valid >= 32) { + put_uint32(s, (uint32_t)s->bi_buf); + s->bi_buf >>= 32; + s->bi_valid -= 32; + } + if (s->bi_valid >= 16) { + put_short(s, (uint16_t)s->bi_buf); + s->bi_buf >>= 16; + s->bi_valid -= 16; + } + if (s->bi_valid >= 8) { + put_byte(s, s->bi_buf); + s->bi_buf >>= 8; + s->bi_valid -= 8; } }