gzip: code shrink
huft_build() still has way too many params function old new delta lit - 94 +94 dist - 94 +94 huft_build 1058 1054 -4 inflate_block 1281 1254 -27 cpdext 30 - -30 cplext 31 - -31 cpdist 60 - -60 cplens 62 - -62 ------------------------------------------------------------------------------ (add/remove: 2/4 grow/shrink: 0/2 up/down: 188/-214) Total: -26 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
c763392458
commit
6572ef6e1e
@ -184,29 +184,26 @@ static const uint16_t mask_bits[] ALIGN2 = {
|
|||||||
0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff
|
0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Copy lengths for literal codes 257..285 */
|
/* Put lengths/offsets and extra bits in a struct of arrays
|
||||||
static const uint16_t cplens[] ALIGN2 = {
|
* to make calls to huft_build() have one fewer parameter.
|
||||||
3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59,
|
*/
|
||||||
67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0
|
struct cp_ext {
|
||||||
|
uint16_t cp[31];
|
||||||
|
uint8_t ext[31];
|
||||||
};
|
};
|
||||||
|
/* Copy lengths and extra bits for literal codes 257..285 */
|
||||||
/* note: see note #13 above about the 258 in this list. */
|
/* note: see note #13 above about the 258 in this list. */
|
||||||
/* Extra bits for literal codes 257..285 */
|
static const struct cp_ext lit = {
|
||||||
static const uint8_t cplext[] ALIGN1 = {
|
/*257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 */
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5,
|
/*0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 */
|
||||||
5, 5, 5, 0, 99, 99
|
{ 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0 },
|
||||||
}; /* 99 == invalid */
|
{ 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 99, 99 } /* 99 == invalid */
|
||||||
|
|
||||||
/* Copy offsets for distance codes 0..29 */
|
|
||||||
static const uint16_t cpdist[] ALIGN2 = {
|
|
||||||
1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513,
|
|
||||||
769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577
|
|
||||||
};
|
};
|
||||||
|
/* Copy offsets and extra bits for distance codes 0..29 */
|
||||||
/* Extra bits for distance codes */
|
static const struct cp_ext dist = {
|
||||||
static const uint8_t cpdext[] ALIGN1 = {
|
/*0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 */
|
||||||
0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10,
|
{ 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577 },
|
||||||
11, 11, 12, 12, 13, 13
|
{ 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13 }
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Tables for deflate from PKZIP's appnote.txt. */
|
/* Tables for deflate from PKZIP's appnote.txt. */
|
||||||
@ -288,8 +285,8 @@ static unsigned fill_bitbuffer(STATE_PARAM unsigned bitbuffer, unsigned *current
|
|||||||
* result: starting table
|
* result: starting table
|
||||||
*/
|
*/
|
||||||
static huft_t* huft_build(const unsigned *b, const unsigned n,
|
static huft_t* huft_build(const unsigned *b, const unsigned n,
|
||||||
const unsigned s, const uint16_t *d,
|
const unsigned s, const struct cp_ext *cp_ext,
|
||||||
const uint8_t *e, unsigned *m)
|
unsigned *m)
|
||||||
{
|
{
|
||||||
unsigned a; /* counter for codes of length k */
|
unsigned a; /* counter for codes of length k */
|
||||||
unsigned c[BMAX + 1]; /* bit length count table */
|
unsigned c[BMAX + 1]; /* bit length count table */
|
||||||
@ -447,8 +444,8 @@ static huft_t* huft_build(const unsigned *b, const unsigned n,
|
|||||||
r.e = (unsigned char) (*p < 256 ? 16 : 15); /* 256 is EOB code */
|
r.e = (unsigned char) (*p < 256 ? 16 : 15); /* 256 is EOB code */
|
||||||
r.v.n = (unsigned short) (*p++); /* simple code is just the value */
|
r.v.n = (unsigned short) (*p++); /* simple code is just the value */
|
||||||
} else {
|
} else {
|
||||||
r.e = (unsigned char) e[*p - s]; /* non-simple--look up in lists */
|
r.e = (unsigned char) cp_ext->ext[*p - s]; /* non-simple--look up in lists */
|
||||||
r.v.n = d[*p++ - s];
|
r.v.n = cp_ext->cp[*p++ - s];
|
||||||
}
|
}
|
||||||
|
|
||||||
/* fill code-like entries with r */
|
/* fill code-like entries with r */
|
||||||
@ -777,14 +774,14 @@ static int inflate_block(STATE_PARAM smallint *e)
|
|||||||
for (; i < 288; i++) /* make a complete, but wrong code set */
|
for (; i < 288; i++) /* make a complete, but wrong code set */
|
||||||
ll[i] = 8;
|
ll[i] = 8;
|
||||||
bl = 7;
|
bl = 7;
|
||||||
inflate_codes_tl = huft_build(ll, 288, 257, cplens, cplext, &bl);
|
inflate_codes_tl = huft_build(ll, 288, 257, &lit, &bl);
|
||||||
/* huft_build() never returns error here - we use known data */
|
/* huft_build() never returns error here - we use known data */
|
||||||
|
|
||||||
/* set up distance table */
|
/* set up distance table */
|
||||||
for (i = 0; i < 30; i++) /* make an incomplete code set */
|
for (i = 0; i < 30; i++) /* make an incomplete code set */
|
||||||
ll[i] = 5;
|
ll[i] = 5;
|
||||||
bd = 5;
|
bd = 5;
|
||||||
inflate_codes_td = huft_build(ll, 30, 0, cpdist, cpdext, &bd);
|
inflate_codes_td = huft_build(ll, 30, 0, &dist, &bd);
|
||||||
|
|
||||||
/* set up data for inflate_codes() */
|
/* set up data for inflate_codes() */
|
||||||
inflate_codes_setup(PASS_STATE bl, bd);
|
inflate_codes_setup(PASS_STATE bl, bd);
|
||||||
@ -850,7 +847,7 @@ static int inflate_block(STATE_PARAM smallint *e)
|
|||||||
|
|
||||||
/* build decoding table for trees - single level, 7 bit lookup */
|
/* build decoding table for trees - single level, 7 bit lookup */
|
||||||
bl = 7;
|
bl = 7;
|
||||||
inflate_codes_tl = huft_build(ll, 19, 19, NULL, NULL, &bl);
|
inflate_codes_tl = huft_build(ll, 19, 19, NULL, &bl);
|
||||||
if (!inflate_codes_tl) {
|
if (!inflate_codes_tl) {
|
||||||
abort_unzip(PASS_STATE_ONLY); /* incomplete code set */
|
abort_unzip(PASS_STATE_ONLY); /* incomplete code set */
|
||||||
}
|
}
|
||||||
@ -915,12 +912,12 @@ static int inflate_block(STATE_PARAM smallint *e)
|
|||||||
|
|
||||||
/* build the decoding tables for literal/length and distance codes */
|
/* build the decoding tables for literal/length and distance codes */
|
||||||
bl = lbits;
|
bl = lbits;
|
||||||
inflate_codes_tl = huft_build(ll, nl, 257, cplens, cplext, &bl);
|
inflate_codes_tl = huft_build(ll, nl, 257, &lit, &bl);
|
||||||
if (!inflate_codes_tl) {
|
if (!inflate_codes_tl) {
|
||||||
abort_unzip(PASS_STATE_ONLY);
|
abort_unzip(PASS_STATE_ONLY);
|
||||||
}
|
}
|
||||||
bd = dbits;
|
bd = dbits;
|
||||||
inflate_codes_td = huft_build(ll + nl, nd, 0, cpdist, cpdext, &bd);
|
inflate_codes_td = huft_build(ll + nl, nd, 0, &dist, &bd);
|
||||||
if (!inflate_codes_td) {
|
if (!inflate_codes_td) {
|
||||||
abort_unzip(PASS_STATE_ONLY);
|
abort_unzip(PASS_STATE_ONLY);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user