aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2019-10-19 18:33:49 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2019-10-19 18:33:49 +0200
commitc763392458304d68951d0b22e89e2422b9c2f8ef (patch)
treea6d19c55dea5386b98d0306b72d7ef76920441e7
parent95867147f5cdf6650dbfc207c8dada86246f23ae (diff)
downloadbusybox-w32-c763392458304d68951d0b22e89e2422b9c2f8ef.tar.gz
busybox-w32-c763392458304d68951d0b22e89e2422b9c2f8ef.tar.bz2
busybox-w32-c763392458304d68951d0b22e89e2422b9c2f8ef.zip
gzip: code shrink
huft_build() has way too many params function old new delta inflate_block 1293 1281 -12 huft_build 1085 1058 -27 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-39) Total: -39 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--archival/libarchive/decompress_gunzip.c53
1 files changed, 26 insertions, 27 deletions
diff --git a/archival/libarchive/decompress_gunzip.c b/archival/libarchive/decompress_gunzip.c
index 1ddce610c..e01687000 100644
--- a/archival/libarchive/decompress_gunzip.c
+++ b/archival/libarchive/decompress_gunzip.c
@@ -277,22 +277,19 @@ static unsigned fill_bitbuffer(STATE_PARAM unsigned bitbuffer, unsigned *current
277 277
278 278
279/* Given a list of code lengths and a maximum table size, make a set of 279/* Given a list of code lengths and a maximum table size, make a set of
280 * tables to decode that set of codes. Return zero on success, one if 280 * tables to decode that set of codes.
281 * the given code set is incomplete (the tables are still built in this
282 * case), two if the input is invalid (an oversubscribed set of lengths)
283 * - in this case stores NULL in *t.
284 * 281 *
285 * b: code lengths in bits (all assumed <= BMAX) 282 * b: code lengths in bits (all assumed <= BMAX)
286 * n: number of codes (assumed <= N_MAX) 283 * n: number of codes (assumed <= N_MAX)
287 * s: number of simple-valued codes (0..s-1) 284 * s: number of simple-valued codes (0..s-1)
288 * d: list of base values for non-simple codes 285 * d: list of base values for non-simple codes
289 * e: list of extra bits for non-simple codes 286 * e: list of extra bits for non-simple codes
290 * t: result: starting table
291 * m: maximum lookup bits, returns actual 287 * m: maximum lookup bits, returns actual
288 * result: starting table
292 */ 289 */
293static int huft_build(const unsigned *b, const unsigned n, 290static huft_t* huft_build(const unsigned *b, const unsigned n,
294 const unsigned s, const unsigned short *d, 291 const unsigned s, const uint16_t *d,
295 const unsigned char *e, huft_t **t, unsigned *m) 292 const uint8_t *e, unsigned *m)
296{ 293{
297 unsigned a; /* counter for codes of length k */ 294 unsigned a; /* counter for codes of length k */
298 unsigned c[BMAX + 1]; /* bit length count table */ 295 unsigned c[BMAX + 1]; /* bit length count table */
@@ -314,12 +311,12 @@ static int huft_build(const unsigned *b, const unsigned n,
314 unsigned *xp; /* pointer into x */ 311 unsigned *xp; /* pointer into x */
315 int y; /* number of dummy codes added */ 312 int y; /* number of dummy codes added */
316 unsigned z; /* number of entries in current table */ 313 unsigned z; /* number of entries in current table */
314 huft_t *result;
315 huft_t **t;
317 316
318 /* Length of EOB code, if any */ 317 /* Length of EOB code, if any */
319 eob_len = n > 256 ? b[256] : BMAX; 318 eob_len = n > 256 ? b[256] : BMAX;
320 319
321 *t = NULL;
322
323 /* Generate counts for each bit length */ 320 /* Generate counts for each bit length */
324 memset(c, 0, sizeof(c)); 321 memset(c, 0, sizeof(c));
325 p = b; 322 p = b;
@@ -335,9 +332,8 @@ static int huft_build(const unsigned *b, const unsigned n,
335 q[1].b = 1; 332 q[1].b = 1;
336 q[2].e = 99; /* invalid code marker */ 333 q[2].e = 99; /* invalid code marker */
337 q[2].b = 1; 334 q[2].b = 1;
338 *t = q + 1;
339 *m = 1; 335 *m = 1;
340 return 0; 336 return q + 1;
341 } 337 }
342 338
343 /* Find minimum and maximum length, bound *m by those */ 339 /* Find minimum and maximum length, bound *m by those */
@@ -353,11 +349,11 @@ static int huft_build(const unsigned *b, const unsigned n,
353 for (y = 1 << j; j < i; j++, y <<= 1) { 349 for (y = 1 << j; j < i; j++, y <<= 1) {
354 y -= c[j]; 350 y -= c[j];
355 if (y < 0) 351 if (y < 0)
356 return 2; /* bad input: more codes than bits */ 352 return NULL; /* bad input: more codes than bits */
357 } 353 }
358 y -= c[i]; 354 y -= c[i];
359 if (y < 0) 355 if (y < 0)
360 return 2; 356 return NULL;
361 c[i] += y; 357 c[i] += y;
362 358
363 /* Generate starting offsets into the value table for each length */ 359 /* Generate starting offsets into the value table for each length */
@@ -384,6 +380,8 @@ static int huft_build(const unsigned *b, const unsigned n,
384 } while (++i < n); 380 } while (++i < n);
385 381
386 /* Generate the Huffman codes and for each, make the table entries */ 382 /* Generate the Huffman codes and for each, make the table entries */
383 result = NULL;
384 t = &result;
387 x[0] = i = 0; /* first Huffman code is zero */ 385 x[0] = i = 0; /* first Huffman code is zero */
388 p = v; /* grab values in bit order */ 386 p = v; /* grab values in bit order */
389 htl = -1; /* no tables yet--level -1 */ 387 htl = -1; /* no tables yet--level -1 */
@@ -475,8 +473,10 @@ static int huft_build(const unsigned *b, const unsigned n,
475 /* return actual size of base table */ 473 /* return actual size of base table */
476 *m = ws[1]; 474 *m = ws[1];
477 475
478 /* Return 1 if we were given an incomplete table */ 476 if (y != 0 && g != 1) /* we were given an incomplete table */
479 return y != 0 && g != 1; 477 return NULL;
478
479 return result;
480} 480}
481 481
482 482
@@ -777,14 +777,14 @@ static int inflate_block(STATE_PARAM smallint *e)
777 for (; i < 288; i++) /* make a complete, but wrong code set */ 777 for (; i < 288; i++) /* make a complete, but wrong code set */
778 ll[i] = 8; 778 ll[i] = 8;
779 bl = 7; 779 bl = 7;
780 huft_build(ll, 288, 257, cplens, cplext, &inflate_codes_tl, &bl); 780 inflate_codes_tl = huft_build(ll, 288, 257, cplens, cplext, &bl);
781 /* huft_build() never return nonzero - we use known data */ 781 /* huft_build() never returns error here - we use known data */
782 782
783 /* set up distance table */ 783 /* set up distance table */
784 for (i = 0; i < 30; i++) /* make an incomplete code set */ 784 for (i = 0; i < 30; i++) /* make an incomplete code set */
785 ll[i] = 5; 785 ll[i] = 5;
786 bd = 5; 786 bd = 5;
787 huft_build(ll, 30, 0, cpdist, cpdext, &inflate_codes_td, &bd); 787 inflate_codes_td = huft_build(ll, 30, 0, cpdist, cpdext, &bd);
788 788
789 /* set up data for inflate_codes() */ 789 /* set up data for inflate_codes() */
790 inflate_codes_setup(PASS_STATE bl, bd); 790 inflate_codes_setup(PASS_STATE bl, bd);
@@ -850,9 +850,9 @@ static int inflate_block(STATE_PARAM smallint *e)
850 850
851 /* build decoding table for trees - single level, 7 bit lookup */ 851 /* build decoding table for trees - single level, 7 bit lookup */
852 bl = 7; 852 bl = 7;
853 i = huft_build(ll, 19, 19, NULL, NULL, &inflate_codes_tl, &bl); 853 inflate_codes_tl = huft_build(ll, 19, 19, NULL, NULL, &bl);
854 if (i != 0) { 854 if (!inflate_codes_tl) {
855 abort_unzip(PASS_STATE_ONLY); //return i; /* incomplete code set */ 855 abort_unzip(PASS_STATE_ONLY); /* incomplete code set */
856 } 856 }
857 857
858 /* read in literal and distance code lengths */ 858 /* read in literal and distance code lengths */
@@ -915,14 +915,13 @@ static int inflate_block(STATE_PARAM smallint *e)
915 915
916 /* build the decoding tables for literal/length and distance codes */ 916 /* build the decoding tables for literal/length and distance codes */
917 bl = lbits; 917 bl = lbits;
918 918 inflate_codes_tl = huft_build(ll, nl, 257, cplens, cplext, &bl);
919 i = huft_build(ll, nl, 257, cplens, cplext, &inflate_codes_tl, &bl); 919 if (!inflate_codes_tl) {
920 if (i != 0) {
921 abort_unzip(PASS_STATE_ONLY); 920 abort_unzip(PASS_STATE_ONLY);
922 } 921 }
923 bd = dbits; 922 bd = dbits;
924 i = huft_build(ll + nl, nd, 0, cpdist, cpdext, &inflate_codes_td, &bd); 923 inflate_codes_td = huft_build(ll + nl, nd, 0, cpdist, cpdext, &bd);
925 if (i != 0) { 924 if (!inflate_codes_td) {
926 abort_unzip(PASS_STATE_ONLY); 925 abort_unzip(PASS_STATE_ONLY);
927 } 926 }
928 927