aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2018-02-03 01:30:12 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2018-02-03 01:30:12 +0100
commite594fb2171a40d6d8f438140440b6c6b1dad5c41 (patch)
treea3ef3ae4a472bd7b76496ec386a0fcc7a4226004
parent125c3ff4b10ee36b757924b3c55b3ac34e902120 (diff)
downloadbusybox-w32-e594fb2171a40d6d8f438140440b6c6b1dad5c41.tar.gz
busybox-w32-e594fb2171a40d6d8f438140440b6c6b1dad5c41.tar.bz2
busybox-w32-e594fb2171a40d6d8f438140440b6c6b1dad5c41.zip
bzip2: code shrink
function old new delta BZ2_compressBlock 225 230 +5 handle_compress 356 355 -1 bsW16 59 56 -3 bsW 64 61 -3 bsFinishWrite 37 32 -5 prepare_new_block 48 34 -14 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/5 up/down: 5/-26) Total: -21 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--archival/libarchive/bz/bzlib.c18
-rw-r--r--archival/libarchive/bz/bzlib_private.h5
-rw-r--r--archival/libarchive/bz/compress.c13
3 files changed, 18 insertions, 18 deletions
diff --git a/archival/libarchive/bz/bzlib.c b/archival/libarchive/bz/bzlib.c
index 5f7db747a..3572474f4 100644
--- a/archival/libarchive/bz/bzlib.c
+++ b/archival/libarchive/bz/bzlib.c
@@ -55,8 +55,9 @@ void prepare_new_block(EState* s)
55{ 55{
56 int i; 56 int i;
57 s->nblock = 0; 57 s->nblock = 0;
58 s->numZ = 0; 58 //indexes inot s->zbits[], initialzation moved to init of s->zbits
59 s->state_out_pos = 0; 59 //s->posZ = s->zbits; // was: s->numZ = 0;
60 //s->state_out_pos = s->zbits;
60 BZ_INITIALISE_CRC(s->blockCRC); 61 BZ_INITIALISE_CRC(s->blockCRC);
61 /* inlined memset would be nice to have here */ 62 /* inlined memset would be nice to have here */
62 for (i = 0; i < 256; i++) 63 for (i = 0; i < 256; i++)
@@ -237,11 +238,10 @@ void /*Bool*/ copy_output_until_stop(EState* s)
237 if (s->strm->avail_out == 0) break; 238 if (s->strm->avail_out == 0) break;
238 239
239 /*-- block done? --*/ 240 /*-- block done? --*/
240 if (s->state_out_pos >= s->numZ) break; 241 if (s->state_out_pos >= s->posZ) break;
241 242
242 /*progress_out = True;*/ 243 /*progress_out = True;*/
243 *(s->strm->next_out) = s->zbits[s->state_out_pos]; 244 *(s->strm->next_out) = *s->state_out_pos++;
244 s->state_out_pos++;
245 s->strm->avail_out--; 245 s->strm->avail_out--;
246 s->strm->next_out++; 246 s->strm->next_out++;
247 s->strm->total_out++; 247 s->strm->total_out++;
@@ -261,7 +261,7 @@ void /*Bool*/ handle_compress(bz_stream *strm)
261 while (1) { 261 while (1) {
262 if (s->state == BZ_S_OUTPUT) { 262 if (s->state == BZ_S_OUTPUT) {
263 /*progress_out |=*/ copy_output_until_stop(s); 263 /*progress_out |=*/ copy_output_until_stop(s);
264 if (s->state_out_pos < s->numZ) break; 264 if (s->state_out_pos < s->posZ) break;
265 if (s->mode == BZ_M_FINISHING 265 if (s->mode == BZ_M_FINISHING
266 //# && s->avail_in_expect == 0 266 //# && s->avail_in_expect == 0
267 && s->strm->avail_in == 0 267 && s->strm->avail_in == 0
@@ -336,7 +336,7 @@ int BZ2_bzCompress(bz_stream *strm, int action)
336 /*if (s->avail_in_expect != s->strm->avail_in) 336 /*if (s->avail_in_expect != s->strm->avail_in)
337 return BZ_SEQUENCE_ERROR;*/ 337 return BZ_SEQUENCE_ERROR;*/
338 /*progress =*/ handle_compress(strm); 338 /*progress =*/ handle_compress(strm);
339 if (s->avail_in_expect > 0 || !isempty_RL(s) || s->state_out_pos < s->numZ) 339 if (s->avail_in_expect > 0 || !isempty_RL(s) || s->state_out_pos < s->posZ)
340 return BZ_FLUSH_OK; 340 return BZ_FLUSH_OK;
341 s->mode = BZ_M_RUNNING; 341 s->mode = BZ_M_RUNNING;
342 return BZ_RUN_OK; 342 return BZ_RUN_OK;
@@ -349,9 +349,9 @@ int BZ2_bzCompress(bz_stream *strm, int action)
349 return BZ_SEQUENCE_ERROR;*/ 349 return BZ_SEQUENCE_ERROR;*/
350 /*progress =*/ handle_compress(strm); 350 /*progress =*/ handle_compress(strm);
351 /*if (!progress) return BZ_SEQUENCE_ERROR;*/ 351 /*if (!progress) return BZ_SEQUENCE_ERROR;*/
352 //#if (s->avail_in_expect > 0 || !isempty_RL(s) || s->state_out_pos < s->numZ) 352 //#if (s->avail_in_expect > 0 || !isempty_RL(s) || s->state_out_pos < s->posZ)
353 //# return BZ_FINISH_OK; 353 //# return BZ_FINISH_OK;
354 if (s->strm->avail_in > 0 || !isempty_RL(s) || s->state_out_pos < s->numZ) 354 if (s->strm->avail_in > 0 || !isempty_RL(s) || s->state_out_pos < s->posZ)
355 return BZ_FINISH_OK; 355 return BZ_FINISH_OK;
356 /*s->mode = BZ_M_IDLE;*/ 356 /*s->mode = BZ_M_IDLE;*/
357 return BZ_STREAM_END; 357 return BZ_STREAM_END;
diff --git a/archival/libarchive/bz/bzlib_private.h b/archival/libarchive/bz/bzlib_private.h
index 43e674bec..8e44a8e64 100644
--- a/archival/libarchive/bz/bzlib_private.h
+++ b/archival/libarchive/bz/bzlib_private.h
@@ -150,8 +150,9 @@ typedef struct EState {
150 /* input and output limits and current posns */ 150 /* input and output limits and current posns */
151 int32_t nblock; 151 int32_t nblock;
152 int32_t nblockMAX; 152 int32_t nblockMAX;
153 int32_t numZ; 153 //int32_t numZ; // index into s->zbits[], replaced by pointer:
154 int32_t state_out_pos; 154 uint8_t *posZ;
155 uint8_t *state_out_pos;
155 156
156 /* the buffer for bit stream creation */ 157 /* the buffer for bit stream creation */
157 uint32_t bsBuff; 158 uint32_t bsBuff;
diff --git a/archival/libarchive/bz/compress.c b/archival/libarchive/bz/compress.c
index c640173e5..534cf665a 100644
--- a/archival/libarchive/bz/compress.c
+++ b/archival/libarchive/bz/compress.c
@@ -50,8 +50,7 @@ static NOINLINE
50void bsFinishWrite(EState* s) 50void bsFinishWrite(EState* s)
51{ 51{
52 while (s->bsLive > 0) { 52 while (s->bsLive > 0) {
53 s->zbits[s->numZ] = (uint8_t)(s->bsBuff >> 24); 53 *s->posZ++ = (uint8_t)(s->bsBuff >> 24);
54 s->numZ++;
55 s->bsBuff <<= 8; 54 s->bsBuff <<= 8;
56 s->bsLive -= 8; 55 s->bsLive -= 8;
57 } 56 }
@@ -67,8 +66,7 @@ ALWAYS_INLINE
67void bsW(EState* s, int32_t n, uint32_t v) 66void bsW(EState* s, int32_t n, uint32_t v)
68{ 67{
69 while (s->bsLive >= 8) { 68 while (s->bsLive >= 8) {
70 s->zbits[s->numZ] = (uint8_t)(s->bsBuff >> 24); 69 *s->posZ++ = (uint8_t)(s->bsBuff >> 24);
71 s->numZ++;
72 s->bsBuff <<= 8; 70 s->bsBuff <<= 8;
73 s->bsLive -= 8; 71 s->bsLive -= 8;
74 } 72 }
@@ -83,8 +81,7 @@ ALWAYS_INLINE
83void bsW16(EState* s, uint32_t v) 81void bsW16(EState* s, uint32_t v)
84{ 82{
85 while (s->bsLive >= 8) { 83 while (s->bsLive >= 8) {
86 s->zbits[s->numZ] = (uint8_t)(s->bsBuff >> 24); 84 *s->posZ++ = (uint8_t)(s->bsBuff >> 24);
87 s->numZ++;
88 s->bsBuff <<= 8; 85 s->bsBuff <<= 8;
89 s->bsLive -= 8; 86 s->bsLive -= 8;
90 } 87 }
@@ -624,12 +621,14 @@ void BZ2_compressBlock(EState* s, int is_last_block)
624 s->combinedCRC = (s->combinedCRC << 1) | (s->combinedCRC >> 31); 621 s->combinedCRC = (s->combinedCRC << 1) | (s->combinedCRC >> 31);
625 s->combinedCRC ^= s->blockCRC; 622 s->combinedCRC ^= s->blockCRC;
626 if (s->blockNo > 1) 623 if (s->blockNo > 1)
627 s->numZ = 0; 624 s->posZ = s->zbits; // was: s->numZ = 0;
628 625
629 BZ2_blockSort(s); 626 BZ2_blockSort(s);
630 } 627 }
631 628
632 s->zbits = &((uint8_t*)s->arr2)[s->nblock]; 629 s->zbits = &((uint8_t*)s->arr2)[s->nblock];
630 s->posZ = s->zbits;
631 s->state_out_pos = s->zbits;
633 632
634 /*-- If this is the first block, create the stream header. --*/ 633 /*-- If this is the first block, create the stream header. --*/
635 if (s->blockNo == 1) { 634 if (s->blockNo == 1) {