Fixed missing compressed_len count in deflate_quick when ZLIB_DEBUG defined. Put most likely condition in send_bits first.

This commit is contained in:
Nathan Moinvaziri 2020-02-07 15:01:10 -08:00 committed by Hans Kristian Rosbach
parent a4d947e85b
commit b2304c7fc0
2 changed files with 12 additions and 7 deletions

View File

@ -135,6 +135,9 @@ static inline void static_emit_ptr(deflate_state *const s, const int lc, const u
send_bits(s, code1, len1, bi_buf, bi_valid); send_bits(s, code1, len1, bi_buf, bi_valid);
send_bits(s, code2, len2, bi_buf, bi_valid); send_bits(s, code2, len2, bi_buf, bi_valid);
#ifdef ZLIB_DEBUG
s->compressed_len += len1 + len2;
#endif
s->bi_valid = bi_valid; s->bi_valid = bi_valid;
s->bi_buf = bi_buf; s->bi_buf = bi_buf;
@ -147,6 +150,9 @@ static inline void static_emit_lit(deflate_state *const s, const int lit) {
uint32_t bi_buf = s->bi_buf; uint32_t bi_buf = s->bi_buf;
send_bits(s, static_ltree[lit].Code, static_ltree[lit].Len, bi_buf, bi_valid); send_bits(s, static_ltree[lit].Code, static_ltree[lit].Len, bi_buf, bi_valid);
#ifdef ZLIB_DEBUG
s->compressed_len += static_ltree[lit].Len;
#endif
s->bi_valid = bi_valid; s->bi_valid = bi_valid;
s->bi_buf = bi_buf; s->bi_buf = bi_buf;

View File

@ -473,7 +473,7 @@ extern const unsigned char ZLIB_INTERNAL zng_dist_code[];
#ifdef ZLIB_DEBUG #ifdef ZLIB_DEBUG
# define send_debug_trace(s, value, length) {\ # define send_debug_trace(s, value, length) {\
Tracevv((stderr, " l %2d v %4x ", length, value));\ Tracevv((stderr, " l %2d v %4x ", length, value));\
Assert(length > 0 && length <= BIT_BUF_SIZE - 1, "invalid length");\ Assert(length > 0 && length <= BIT_BUF_SIZE, "invalid length");\
s->bits_sent += (unsigned long)length;\ s->bits_sent += (unsigned long)length;\
} }
#else #else
@ -488,19 +488,18 @@ extern const unsigned char ZLIB_INTERNAL zng_dist_code[];
uint32_t val = (uint32_t)t_val;\ uint32_t val = (uint32_t)t_val;\
uint32_t len = (uint32_t)t_len;\ uint32_t len = (uint32_t)t_len;\
send_debug_trace(s, val, len);\ send_debug_trace(s, val, len);\
if (bits_valid == BIT_BUF_SIZE) {\ if (bits_valid + len < BIT_BUF_SIZE) {\
bit_buf |= val << bits_valid;\
bits_valid += len;\
} else if (bits_valid == BIT_BUF_SIZE) {\
put_uint32(s, bit_buf);\ put_uint32(s, bit_buf);\
bit_buf = val;\ bit_buf = val;\
bits_valid = len;\ bits_valid = len;\
} else if (bits_valid + len >= BIT_BUF_SIZE) {\ } else {\
bit_buf |= val << bits_valid;\ bit_buf |= val << bits_valid;\
put_uint32(s, bit_buf);\ put_uint32(s, bit_buf);\
bit_buf = val >> (BIT_BUF_SIZE - bits_valid);\ bit_buf = val >> (BIT_BUF_SIZE - bits_valid);\
bits_valid += len - BIT_BUF_SIZE;\ bits_valid += len - BIT_BUF_SIZE;\
} else {\
bit_buf |= val << bits_valid;\
bits_valid += len;\
}\ }\
} }
#endif /* DEFLATE_H_ */ #endif /* DEFLATE_H_ */