Remove branch that is almost impossible to hit in bi_flush().

Add case that handles sizes >=48.
This commit is contained in:
Hans Kristian Rosbach 2024-02-07 19:21:36 +01:00 committed by Hans Kristian Rosbach
parent 20498320cd
commit 6f5bdddad1

39
trees.c
View File

@ -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;
}
}