diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2018-01-30 22:37:06 +0100 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-01-30 22:37:06 +0100 |
| commit | e4c4e6ddc365d8e9b5409e2f929116624c932c1d (patch) | |
| tree | 446538d917e662f9cd986fd6507f3033b580aec2 | |
| parent | 9c499a5af48bd4d9d635c8021e6ad14fd4e939dc (diff) | |
| download | busybox-w32-e4c4e6ddc365d8e9b5409e2f929116624c932c1d.tar.gz busybox-w32-e4c4e6ddc365d8e9b5409e2f929116624c932c1d.tar.bz2 busybox-w32-e4c4e6ddc365d8e9b5409e2f929116624c932c1d.zip | |
gzip: code shrink
function old new delta
send_bits 92 70 -22
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| -rw-r--r-- | archival/gzip.c | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/archival/gzip.c b/archival/gzip.c index 8ef66390a..efc5a0eea 100644 --- a/archival/gzip.c +++ b/archival/gzip.c | |||
| @@ -358,7 +358,7 @@ struct globals { | |||
| 358 | unsigned short bi_buf; | 358 | unsigned short bi_buf; |
| 359 | 359 | ||
| 360 | #undef BUF_SIZE | 360 | #undef BUF_SIZE |
| 361 | #define BUF_SIZE (8 * sizeof(G1.bi_buf)) | 361 | #define BUF_SIZE (int)(8 * sizeof(G1.bi_buf)) |
| 362 | 362 | ||
| 363 | /* Number of bits used within bi_buf. (bi_buf might be implemented on | 363 | /* Number of bits used within bi_buf. (bi_buf might be implemented on |
| 364 | * more than 16 bits on some systems.) | 364 | * more than 16 bits on some systems.) |
| @@ -522,24 +522,29 @@ static unsigned file_read(void *buf, unsigned size) | |||
| 522 | */ | 522 | */ |
| 523 | static void send_bits(int value, int length) | 523 | static void send_bits(int value, int length) |
| 524 | { | 524 | { |
| 525 | unsigned new_buf; | ||
| 526 | int remain; | ||
| 527 | |||
| 525 | #ifdef DEBUG | 528 | #ifdef DEBUG |
| 526 | Tracev((stderr, " l %2d v %4x ", length, value)); | 529 | Tracev((stderr, " l %2d v %4x ", length, value)); |
| 527 | Assert(length > 0 && length <= 15, "invalid length"); | 530 | Assert(length > 0 && length <= 15, "invalid length"); |
| 528 | G1.bits_sent += length; | 531 | G1.bits_sent += length; |
| 529 | #endif | 532 | #endif |
| 530 | /* If not enough room in bi_buf, use (valid) bits from bi_buf and | 533 | |
| 531 | * (16 - bi_valid) bits from value, leaving (width - (16-bi_valid)) | 534 | new_buf = G1.bi_buf | (value << G1.bi_valid); |
| 532 | * unused bits in value. | 535 | remain = BUF_SIZE - G1.bi_valid; |
| 533 | */ | 536 | /* If not enough room in bi_buf */ |
| 534 | if (G1.bi_valid > (int) BUF_SIZE - length) { | 537 | if (length > remain) { |
| 535 | G1.bi_buf |= (value << G1.bi_valid); | 538 | /* ...use (valid) bits from bi_buf and |
| 536 | put_16bit(G1.bi_buf); | 539 | * (16 - bi_valid) bits from value, |
| 537 | G1.bi_buf = (ush) value >> (BUF_SIZE - G1.bi_valid); | 540 | * leaving (width - (16-bi_valid)) unused bits in value. |
| 538 | G1.bi_valid += length - BUF_SIZE; | 541 | */ |
| 539 | } else { | 542 | put_16bit(new_buf); |
| 540 | G1.bi_buf |= value << G1.bi_valid; | 543 | new_buf = (ush) value >> remain; |
| 541 | G1.bi_valid += length; | 544 | length -= BUF_SIZE; |
| 542 | } | 545 | } |
| 546 | G1.bi_buf = new_buf; | ||
| 547 | G1.bi_valid += length; | ||
| 543 | } | 548 | } |
| 544 | 549 | ||
| 545 | 550 | ||
