aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <dvlasenk@redhat.com>2010-10-30 00:55:02 +0200
committerDenys Vlasenko <dvlasenk@redhat.com>2010-10-30 00:55:02 +0200
commitf16727ebbbb385b1bf4d03608a04f8310469cf1f (patch)
treec606facf27e7e157cafe525b7d4a6b50d8c539e7
parent0c576975c87c543522ab31566139c078429dff38 (diff)
downloadbusybox-w32-f16727ebbbb385b1bf4d03608a04f8310469cf1f.tar.gz
busybox-w32-f16727ebbbb385b1bf4d03608a04f8310469cf1f.tar.bz2
busybox-w32-f16727ebbbb385b1bf4d03608a04f8310469cf1f.zip
decompress_bunzip2: code shrink ~5 bytes
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
-rw-r--r--archival/libunarchive/decompress_bunzip2.c25
1 files changed, 13 insertions, 12 deletions
diff --git a/archival/libunarchive/decompress_bunzip2.c b/archival/libunarchive/decompress_bunzip2.c
index 2d4867220..d30166fa4 100644
--- a/archival/libunarchive/decompress_bunzip2.c
+++ b/archival/libunarchive/decompress_bunzip2.c
@@ -153,6 +153,7 @@ static int get_next_block(bunzip_data *bd)
153 struct group_data *hufGroup; 153 struct group_data *hufGroup;
154 int dbufCount, dbufSize, groupCount, *base, *limit, selector, 154 int dbufCount, dbufSize, groupCount, *base, *limit, selector,
155 i, j, t, runPos, symCount, symTotal, nSelectors, byteCount[256]; 155 i, j, t, runPos, symCount, symTotal, nSelectors, byteCount[256];
156 int runCnt = runCnt; /* for compiler */
156 uint8_t uc, symToByte[256], mtfSymbol[256], *selectors; 157 uint8_t uc, symToByte[256], mtfSymbol[256], *selectors;
157 uint32_t *dbuf; 158 uint32_t *dbuf;
158 unsigned origPtr; 159 unsigned origPtr;
@@ -242,19 +243,19 @@ static int get_next_block(bunzip_data *bd)
242 uint8_t length[MAX_SYMBOLS]; 243 uint8_t length[MAX_SYMBOLS];
243 /* 8 bits is ALMOST enough for temp[], see below */ 244 /* 8 bits is ALMOST enough for temp[], see below */
244 unsigned temp[MAX_HUFCODE_BITS+1]; 245 unsigned temp[MAX_HUFCODE_BITS+1];
245 int minLen, maxLen, pp; 246 int minLen, maxLen, pp, len_m1;
246 247
247 /* Read Huffman code lengths for each symbol. They're stored in 248 /* Read Huffman code lengths for each symbol. They're stored in
248 a way similar to mtf; record a starting value for the first symbol, 249 a way similar to mtf; record a starting value for the first symbol,
249 and an offset from the previous value for everys symbol after that. 250 and an offset from the previous value for every symbol after that.
250 (Subtracting 1 before the loop and then adding it back at the end is 251 (Subtracting 1 before the loop and then adding it back at the end is
251 an optimization that makes the test inside the loop simpler: symbol 252 an optimization that makes the test inside the loop simpler: symbol
252 length 0 becomes negative, so an unsigned inequality catches it.) */ 253 length 0 becomes negative, so an unsigned inequality catches it.) */
253 t = get_bits(bd, 5) - 1; 254 len_m1 = get_bits(bd, 5) - 1;
254 for (i = 0; i < symCount; i++) { 255 for (i = 0; i < symCount; i++) {
255 for (;;) { 256 for (;;) {
256 int two_bits; 257 int two_bits;
257 if ((unsigned)t > (MAX_HUFCODE_BITS-1)) 258 if ((unsigned)len_m1 > (MAX_HUFCODE_BITS-1))
258 return RETVAL_DATA_ERROR; 259 return RETVAL_DATA_ERROR;
259 260
260 /* If first bit is 0, stop. Else second bit indicates whether 261 /* If first bit is 0, stop. Else second bit indicates whether
@@ -267,11 +268,11 @@ static int get_next_block(bunzip_data *bd)
267 } 268 }
268 269
269 /* Add one if second bit 1, else subtract 1. Avoids if/else */ 270 /* Add one if second bit 1, else subtract 1. Avoids if/else */
270 t += (((two_bits+1) & 2) - 1); 271 len_m1 += (((two_bits+1) & 2) - 1);
271 } 272 }
272 273
273 /* Correct for the initial -1, to get the final symbol length */ 274 /* Correct for the initial -1, to get the final symbol length */
274 length[i] = t + 1; 275 length[i] = len_m1 + 1;
275 } 276 }
276 277
277 /* Find largest and smallest lengths in this group */ 278 /* Find largest and smallest lengths in this group */
@@ -337,8 +338,8 @@ static int get_next_block(bunzip_data *bd)
337 t += temp_i; 338 t += temp_i;
338 base[++i] = pp - t; 339 base[++i] = pp - t;
339 } 340 }
340 limit[maxLen+1] = INT_MAX; /* Sentinel value for reading next sym. */
341 limit[maxLen] = pp + temp[maxLen] - 1; 341 limit[maxLen] = pp + temp[maxLen] - 1;
342 limit[maxLen+1] = INT_MAX; /* Sentinel value for reading next sym. */
342 base[minLen] = 0; 343 base[minLen] = 0;
343 } 344 }
344 345
@@ -418,7 +419,7 @@ static int get_next_block(bunzip_data *bd)
418 /* If this is the start of a new run, zero out counter */ 419 /* If this is the start of a new run, zero out counter */
419 if (runPos == 0) { 420 if (runPos == 0) {
420 runPos = 1; 421 runPos = 1;
421 t = 0; 422 runCnt = 0;
422 } 423 }
423 424
424 /* Neat trick that saves 1 symbol: instead of or-ing 0 or 1 at 425 /* Neat trick that saves 1 symbol: instead of or-ing 0 or 1 at
@@ -428,7 +429,7 @@ static int get_next_block(bunzip_data *bd)
428 the basic or 0/1 method (except all bits 0, which would use no 429 the basic or 0/1 method (except all bits 0, which would use no
429 symbols, but a run of length 0 doesn't mean anything in this 430 symbols, but a run of length 0 doesn't mean anything in this
430 context). Thus space is saved. */ 431 context). Thus space is saved. */
431 t += (runPos << nextSym); /* +runPos if RUNA; +2*runPos if RUNB */ 432 runCnt += (runPos << nextSym); /* +runPos if RUNA; +2*runPos if RUNB */
432 if (runPos < dbufSize) runPos <<= 1; 433 if (runPos < dbufSize) runPos <<= 1;
433 goto end_of_huffman_loop; 434 goto end_of_huffman_loop;
434 } 435 }
@@ -439,10 +440,10 @@ static int get_next_block(bunzip_data *bd)
439 literal used is the one at the head of the mtfSymbol array.) */ 440 literal used is the one at the head of the mtfSymbol array.) */
440 if (runPos != 0) { 441 if (runPos != 0) {
441 uint8_t tmp_byte; 442 uint8_t tmp_byte;
442 if (dbufCount + t >= dbufSize) return RETVAL_DATA_ERROR; 443 if (dbufCount + runCnt >= dbufSize) return RETVAL_DATA_ERROR;
443 tmp_byte = symToByte[mtfSymbol[0]]; 444 tmp_byte = symToByte[mtfSymbol[0]];
444 byteCount[tmp_byte] += t; 445 byteCount[tmp_byte] += runCnt;
445 while (--t >= 0) dbuf[dbufCount++] = tmp_byte; 446 while (--runCnt >= 0) dbuf[dbufCount++] = (uint32_t)tmp_byte;
446 runPos = 0; 447 runPos = 0;
447 } 448 }
448 449