diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2019-10-19 18:52:41 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2019-10-19 18:53:19 +0200 |
commit | 6572ef6e1e4822f785b7139ef166586c444dc01e (patch) | |
tree | 1d102276021114de586d3463ae47c823cd7af6a3 | |
parent | c763392458304d68951d0b22e89e2422b9c2f8ef (diff) | |
download | busybox-w32-6572ef6e1e4822f785b7139ef166586c444dc01e.tar.gz busybox-w32-6572ef6e1e4822f785b7139ef166586c444dc01e.tar.bz2 busybox-w32-6572ef6e1e4822f785b7139ef166586c444dc01e.zip |
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>
-rw-r--r-- | archival/libarchive/decompress_gunzip.c | 55 |
1 files changed, 26 insertions, 29 deletions
diff --git a/archival/libarchive/decompress_gunzip.c b/archival/libarchive/decompress_gunzip.c index e01687000..530661e15 100644 --- a/archival/libarchive/decompress_gunzip.c +++ b/archival/libarchive/decompress_gunzip.c | |||
@@ -184,29 +184,26 @@ static const uint16_t mask_bits[] ALIGN2 = { | |||
184 | 0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff | 184 | 0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff |
185 | }; | 185 | }; |
186 | 186 | ||
187 | /* Copy lengths for literal codes 257..285 */ | 187 | /* Put lengths/offsets and extra bits in a struct of arrays |
188 | static const uint16_t cplens[] ALIGN2 = { | 188 | * to make calls to huft_build() have one fewer parameter. |
189 | 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59, | 189 | */ |
190 | 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0 | 190 | struct cp_ext { |
191 | uint16_t cp[31]; | ||
192 | uint8_t ext[31]; | ||
191 | }; | 193 | }; |
192 | 194 | /* Copy lengths and extra bits for literal codes 257..285 */ | |
193 | /* note: see note #13 above about the 258 in this list. */ | 195 | /* note: see note #13 above about the 258 in this list. */ |
194 | /* Extra bits for literal codes 257..285 */ | 196 | static const struct cp_ext lit = { |
195 | static const uint8_t cplext[] ALIGN1 = { | 197 | /*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 */ |
196 | 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, | 198 | /*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 */ |
197 | 5, 5, 5, 0, 99, 99 | 199 | { 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 }, |
198 | }; /* 99 == invalid */ | 200 | { 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 */ |
199 | |||
200 | /* Copy offsets for distance codes 0..29 */ | ||
201 | static const uint16_t cpdist[] ALIGN2 = { | ||
202 | 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, | ||
203 | 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577 | ||
204 | }; | 201 | }; |
205 | 202 | /* Copy offsets and extra bits for distance codes 0..29 */ | |
206 | /* Extra bits for distance codes */ | 203 | static const struct cp_ext dist = { |
207 | static const uint8_t cpdext[] ALIGN1 = { | 204 | /*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 */ |
208 | 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, | 205 | { 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 }, |
209 | 11, 11, 12, 12, 13, 13 | 206 | { 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 } |
210 | }; | 207 | }; |
211 | 208 | ||
212 | /* Tables for deflate from PKZIP's appnote.txt. */ | 209 | /* Tables for deflate from PKZIP's appnote.txt. */ |
@@ -288,8 +285,8 @@ static unsigned fill_bitbuffer(STATE_PARAM unsigned bitbuffer, unsigned *current | |||
288 | * result: starting table | 285 | * result: starting table |
289 | */ | 286 | */ |
290 | static huft_t* huft_build(const unsigned *b, const unsigned n, | 287 | static huft_t* huft_build(const unsigned *b, const unsigned n, |
291 | const unsigned s, const uint16_t *d, | 288 | const unsigned s, const struct cp_ext *cp_ext, |
292 | const uint8_t *e, unsigned *m) | 289 | unsigned *m) |
293 | { | 290 | { |
294 | unsigned a; /* counter for codes of length k */ | 291 | unsigned a; /* counter for codes of length k */ |
295 | unsigned c[BMAX + 1]; /* bit length count table */ | 292 | unsigned c[BMAX + 1]; /* bit length count table */ |
@@ -447,8 +444,8 @@ static huft_t* huft_build(const unsigned *b, const unsigned n, | |||
447 | r.e = (unsigned char) (*p < 256 ? 16 : 15); /* 256 is EOB code */ | 444 | r.e = (unsigned char) (*p < 256 ? 16 : 15); /* 256 is EOB code */ |
448 | r.v.n = (unsigned short) (*p++); /* simple code is just the value */ | 445 | r.v.n = (unsigned short) (*p++); /* simple code is just the value */ |
449 | } else { | 446 | } else { |
450 | r.e = (unsigned char) e[*p - s]; /* non-simple--look up in lists */ | 447 | r.e = (unsigned char) cp_ext->ext[*p - s]; /* non-simple--look up in lists */ |
451 | r.v.n = d[*p++ - s]; | 448 | r.v.n = cp_ext->cp[*p++ - s]; |
452 | } | 449 | } |
453 | 450 | ||
454 | /* fill code-like entries with r */ | 451 | /* fill code-like entries with r */ |
@@ -777,14 +774,14 @@ static int inflate_block(STATE_PARAM smallint *e) | |||
777 | for (; i < 288; i++) /* make a complete, but wrong code set */ | 774 | for (; i < 288; i++) /* make a complete, but wrong code set */ |
778 | ll[i] = 8; | 775 | ll[i] = 8; |
779 | bl = 7; | 776 | bl = 7; |
780 | inflate_codes_tl = huft_build(ll, 288, 257, cplens, cplext, &bl); | 777 | inflate_codes_tl = huft_build(ll, 288, 257, &lit, &bl); |
781 | /* huft_build() never returns error here - we use known data */ | 778 | /* huft_build() never returns error here - we use known data */ |
782 | 779 | ||
783 | /* set up distance table */ | 780 | /* set up distance table */ |
784 | for (i = 0; i < 30; i++) /* make an incomplete code set */ | 781 | for (i = 0; i < 30; i++) /* make an incomplete code set */ |
785 | ll[i] = 5; | 782 | ll[i] = 5; |
786 | bd = 5; | 783 | bd = 5; |
787 | inflate_codes_td = huft_build(ll, 30, 0, cpdist, cpdext, &bd); | 784 | inflate_codes_td = huft_build(ll, 30, 0, &dist, &bd); |
788 | 785 | ||
789 | /* set up data for inflate_codes() */ | 786 | /* set up data for inflate_codes() */ |
790 | inflate_codes_setup(PASS_STATE bl, bd); | 787 | inflate_codes_setup(PASS_STATE bl, bd); |
@@ -850,7 +847,7 @@ static int inflate_block(STATE_PARAM smallint *e) | |||
850 | 847 | ||
851 | /* build decoding table for trees - single level, 7 bit lookup */ | 848 | /* build decoding table for trees - single level, 7 bit lookup */ |
852 | bl = 7; | 849 | bl = 7; |
853 | inflate_codes_tl = huft_build(ll, 19, 19, NULL, NULL, &bl); | 850 | inflate_codes_tl = huft_build(ll, 19, 19, NULL, &bl); |
854 | if (!inflate_codes_tl) { | 851 | if (!inflate_codes_tl) { |
855 | abort_unzip(PASS_STATE_ONLY); /* incomplete code set */ | 852 | abort_unzip(PASS_STATE_ONLY); /* incomplete code set */ |
856 | } | 853 | } |
@@ -915,12 +912,12 @@ static int inflate_block(STATE_PARAM smallint *e) | |||
915 | 912 | ||
916 | /* build the decoding tables for literal/length and distance codes */ | 913 | /* build the decoding tables for literal/length and distance codes */ |
917 | bl = lbits; | 914 | bl = lbits; |
918 | inflate_codes_tl = huft_build(ll, nl, 257, cplens, cplext, &bl); | 915 | inflate_codes_tl = huft_build(ll, nl, 257, &lit, &bl); |
919 | if (!inflate_codes_tl) { | 916 | if (!inflate_codes_tl) { |
920 | abort_unzip(PASS_STATE_ONLY); | 917 | abort_unzip(PASS_STATE_ONLY); |
921 | } | 918 | } |
922 | bd = dbits; | 919 | bd = dbits; |
923 | inflate_codes_td = huft_build(ll + nl, nd, 0, cpdist, cpdext, &bd); | 920 | inflate_codes_td = huft_build(ll + nl, nd, 0, &dist, &bd); |
924 | if (!inflate_codes_td) { | 921 | if (!inflate_codes_td) { |
925 | abort_unzip(PASS_STATE_ONLY); | 922 | abort_unzip(PASS_STATE_ONLY); |
926 | } | 923 | } |