gzip: code shrink
function old new delta send_bits 92 70 -22 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
9c499a5af4
commit
e4c4e6ddc3
@ -358,7 +358,7 @@ struct globals {
|
|||||||
unsigned short bi_buf;
|
unsigned short bi_buf;
|
||||||
|
|
||||||
#undef BUF_SIZE
|
#undef BUF_SIZE
|
||||||
#define BUF_SIZE (8 * sizeof(G1.bi_buf))
|
#define BUF_SIZE (int)(8 * sizeof(G1.bi_buf))
|
||||||
|
|
||||||
/* Number of bits used within bi_buf. (bi_buf might be implemented on
|
/* Number of bits used within bi_buf. (bi_buf might be implemented on
|
||||||
* more than 16 bits on some systems.)
|
* more than 16 bits on some systems.)
|
||||||
@ -522,24 +522,29 @@ static unsigned file_read(void *buf, unsigned size)
|
|||||||
*/
|
*/
|
||||||
static void send_bits(int value, int length)
|
static void send_bits(int value, int length)
|
||||||
{
|
{
|
||||||
|
unsigned new_buf;
|
||||||
|
int remain;
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
Tracev((stderr, " l %2d v %4x ", length, value));
|
Tracev((stderr, " l %2d v %4x ", length, value));
|
||||||
Assert(length > 0 && length <= 15, "invalid length");
|
Assert(length > 0 && length <= 15, "invalid length");
|
||||||
G1.bits_sent += length;
|
G1.bits_sent += length;
|
||||||
#endif
|
#endif
|
||||||
/* If not enough room in bi_buf, use (valid) bits from bi_buf and
|
|
||||||
* (16 - bi_valid) bits from value, leaving (width - (16-bi_valid))
|
new_buf = G1.bi_buf | (value << G1.bi_valid);
|
||||||
* unused bits in value.
|
remain = BUF_SIZE - G1.bi_valid;
|
||||||
*/
|
/* If not enough room in bi_buf */
|
||||||
if (G1.bi_valid > (int) BUF_SIZE - length) {
|
if (length > remain) {
|
||||||
G1.bi_buf |= (value << G1.bi_valid);
|
/* ...use (valid) bits from bi_buf and
|
||||||
put_16bit(G1.bi_buf);
|
* (16 - bi_valid) bits from value,
|
||||||
G1.bi_buf = (ush) value >> (BUF_SIZE - G1.bi_valid);
|
* leaving (width - (16-bi_valid)) unused bits in value.
|
||||||
G1.bi_valid += length - BUF_SIZE;
|
*/
|
||||||
} else {
|
put_16bit(new_buf);
|
||||||
G1.bi_buf |= value << G1.bi_valid;
|
new_buf = (ush) value >> remain;
|
||||||
G1.bi_valid += length;
|
length -= BUF_SIZE;
|
||||||
}
|
}
|
||||||
|
G1.bi_buf = new_buf;
|
||||||
|
G1.bi_valid += length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user