diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2018-01-30 17:39:57 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-01-30 17:39:57 +0100 |
commit | c6d2a26fac47eafc08f291dab78bbca3088f8ca2 (patch) | |
tree | fb8ad6248c1fca9b1b839607f790397f1852e5b1 | |
parent | 749575d3c52c32f57f46f2cbb2942a2204d333ee (diff) | |
download | busybox-w32-c6d2a26fac47eafc08f291dab78bbca3088f8ca2.tar.gz busybox-w32-c6d2a26fac47eafc08f291dab78bbca3088f8ca2.tar.bz2 busybox-w32-c6d2a26fac47eafc08f291dab78bbca3088f8ca2.zip |
gzip: code shrink (consolidate zeroing on reinit)
function old new delta
deflate - 938 +938
pack_gzip 1903 923 -980
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | archival/gzip.c | 125 |
1 files changed, 55 insertions, 70 deletions
diff --git a/archival/gzip.c b/archival/gzip.c index 2a5288cce..10eda7aa3 100644 --- a/archival/gzip.c +++ b/archival/gzip.c | |||
@@ -15,21 +15,6 @@ | |||
15 | * | 15 | * |
16 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. | 16 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. |
17 | */ | 17 | */ |
18 | /* big objects in bss: | ||
19 | * 00000020 b bl_count | ||
20 | * 00000074 b base_length | ||
21 | * 00000078 b base_dist | ||
22 | * 00000078 b static_dtree | ||
23 | * 0000009c b bl_tree | ||
24 | * 000000f4 b dyn_dtree | ||
25 | * 00000100 b length_code | ||
26 | * 00000200 b dist_code | ||
27 | * 0000023d b depth | ||
28 | * 00000400 b flag_buf | ||
29 | * 0000047a b heap | ||
30 | * 00000480 b static_ltree | ||
31 | * 000008f4 b dyn_ltree | ||
32 | */ | ||
33 | /* TODO: full support for -v for DESKTOP | 18 | /* TODO: full support for -v for DESKTOP |
34 | * "/usr/bin/gzip -v a bogus aa" should say: | 19 | * "/usr/bin/gzip -v a bogus aa" should say: |
35 | a: 85.1% -- replaced with a.gz | 20 | a: 85.1% -- replaced with a.gz |
@@ -351,6 +336,44 @@ struct globals { | |||
351 | unsigned match_start; /* start of matching string */ | 336 | unsigned match_start; /* start of matching string */ |
352 | unsigned lookahead; /* number of valid bytes ahead in window */ | 337 | unsigned lookahead; /* number of valid bytes ahead in window */ |
353 | 338 | ||
339 | /* number of input bytes */ | ||
340 | ulg isize; /* only 32 bits stored in .gz file */ | ||
341 | |||
342 | /* bbox always use stdin/stdout */ | ||
343 | #define ifd STDIN_FILENO /* input file descriptor */ | ||
344 | #define ofd STDOUT_FILENO /* output file descriptor */ | ||
345 | |||
346 | #ifdef DEBUG | ||
347 | unsigned insize; /* valid bytes in l_buf */ | ||
348 | #endif | ||
349 | unsigned outcnt; /* bytes in output buffer */ | ||
350 | |||
351 | smallint eofile; /* flag set at end of input file */ | ||
352 | |||
353 | /* =========================================================================== | ||
354 | * Local data used by the "bit string" routines. | ||
355 | */ | ||
356 | |||
357 | unsigned short bi_buf; | ||
358 | |||
359 | /* Output buffer. bits are inserted starting at the bottom (least significant | ||
360 | * bits). | ||
361 | */ | ||
362 | #undef BUF_SIZE | ||
363 | #define BUF_SIZE (8 * sizeof(G1.bi_buf)) | ||
364 | |||
365 | /* Number of bits used within bi_buf. (bi_buf might be implemented on | ||
366 | * more than 16 bits on some systems.) | ||
367 | */ | ||
368 | int bi_valid; | ||
369 | |||
370 | #ifdef DEBUG | ||
371 | ulg bits_sent; /* bit length of the compressed data */ | ||
372 | #endif | ||
373 | |||
374 | /*uint32_t *crc_32_tab;*/ | ||
375 | uint32_t crc; /* shift register contents */ | ||
376 | |||
354 | /* =========================================================================== | 377 | /* =========================================================================== |
355 | */ | 378 | */ |
356 | #define DECLARE(type, array, size) \ | 379 | #define DECLARE(type, array, size) \ |
@@ -390,47 +413,6 @@ struct globals { | |||
390 | /* Heads of the hash chains or 0. */ | 413 | /* Heads of the hash chains or 0. */ |
391 | /* DECLARE(Pos, head, 1<<HASH_BITS); */ | 414 | /* DECLARE(Pos, head, 1<<HASH_BITS); */ |
392 | #define head (G1.prev + WSIZE) /* hash head (see deflate.c) */ | 415 | #define head (G1.prev + WSIZE) /* hash head (see deflate.c) */ |
393 | |||
394 | /* number of input bytes */ | ||
395 | ulg isize; /* only 32 bits stored in .gz file */ | ||
396 | |||
397 | /* bbox always use stdin/stdout */ | ||
398 | #define ifd STDIN_FILENO /* input file descriptor */ | ||
399 | #define ofd STDOUT_FILENO /* output file descriptor */ | ||
400 | |||
401 | #ifdef DEBUG | ||
402 | unsigned insize; /* valid bytes in l_buf */ | ||
403 | #endif | ||
404 | unsigned outcnt; /* bytes in output buffer */ | ||
405 | |||
406 | smallint eofile; /* flag set at end of input file */ | ||
407 | |||
408 | /* =========================================================================== | ||
409 | * Local data used by the "bit string" routines. | ||
410 | */ | ||
411 | |||
412 | unsigned short bi_buf; | ||
413 | |||
414 | /* Output buffer. bits are inserted starting at the bottom (least significant | ||
415 | * bits). | ||
416 | */ | ||
417 | |||
418 | #undef BUF_SIZE | ||
419 | #define BUF_SIZE (8 * sizeof(G1.bi_buf)) | ||
420 | /* Number of bits used within bi_buf. (bi_buf might be implemented on | ||
421 | * more than 16 bits on some systems.) | ||
422 | */ | ||
423 | |||
424 | int bi_valid; | ||
425 | |||
426 | /* Current input function. Set to mem_read for in-memory compression */ | ||
427 | |||
428 | #ifdef DEBUG | ||
429 | ulg bits_sent; /* bit length of the compressed data */ | ||
430 | #endif | ||
431 | |||
432 | /*uint32_t *crc_32_tab;*/ | ||
433 | uint32_t crc; /* shift register contents */ | ||
434 | }; | 416 | }; |
435 | 417 | ||
436 | #define G1 (*(ptr_to_globals - 1)) | 418 | #define G1 (*(ptr_to_globals - 1)) |
@@ -1816,7 +1798,7 @@ do { \ | |||
1816 | head[G1.ins_h] = (s); \ | 1798 | head[G1.ins_h] = (s); \ |
1817 | } while (0) | 1799 | } while (0) |
1818 | 1800 | ||
1819 | static ulg deflate(void) | 1801 | static NOINLINE ulg deflate(void) |
1820 | { | 1802 | { |
1821 | IPos hash_head; /* head of hash chain */ | 1803 | IPos hash_head; /* head of hash chain */ |
1822 | IPos prev_match; /* previous match */ | 1804 | IPos prev_match; /* previous match */ |
@@ -1927,10 +1909,10 @@ static ulg deflate(void) | |||
1927 | */ | 1909 | */ |
1928 | static void bi_init(void) | 1910 | static void bi_init(void) |
1929 | { | 1911 | { |
1930 | G1.bi_buf = 0; | 1912 | //G1.bi_buf = 0; // globals are zeroed in pack_gzip() |
1931 | G1.bi_valid = 0; | 1913 | //G1.bi_valid = 0; // globals are zeroed in pack_gzip() |
1932 | #ifdef DEBUG | 1914 | #ifdef DEBUG |
1933 | G1.bits_sent = 0L; | 1915 | //G1.bits_sent = 0L; // globals are zeroed in pack_gzip() |
1934 | #endif | 1916 | #endif |
1935 | } | 1917 | } |
1936 | 1918 | ||
@@ -1950,8 +1932,8 @@ static void lm_init(ush * flagsp) | |||
1950 | *flagsp |= 2; /* FAST 4, SLOW 2 */ | 1932 | *flagsp |= 2; /* FAST 4, SLOW 2 */ |
1951 | /* ??? reduce max_chain_length for binary files */ | 1933 | /* ??? reduce max_chain_length for binary files */ |
1952 | 1934 | ||
1953 | G1.strstart = 0; | 1935 | //G1.strstart = 0; // globals are zeroed in pack_gzip() |
1954 | G1.block_start = 0L; | 1936 | //G1.block_start = 0L; // globals are zeroed in pack_gzip() |
1955 | 1937 | ||
1956 | G1.lookahead = file_read(G1.window, | 1938 | G1.lookahead = file_read(G1.window, |
1957 | sizeof(int) <= 2 ? (unsigned) WSIZE : 2 * WSIZE); | 1939 | sizeof(int) <= 2 ? (unsigned) WSIZE : 2 * WSIZE); |
@@ -1961,14 +1943,15 @@ static void lm_init(ush * flagsp) | |||
1961 | G1.lookahead = 0; | 1943 | G1.lookahead = 0; |
1962 | return; | 1944 | return; |
1963 | } | 1945 | } |
1964 | G1.eofile = 0; | 1946 | //G1.eofile = 0; // globals are zeroed in pack_gzip() |
1947 | |||
1965 | /* Make sure that we always have enough lookahead. This is important | 1948 | /* Make sure that we always have enough lookahead. This is important |
1966 | * if input comes from a device such as a tty. | 1949 | * if input comes from a device such as a tty. |
1967 | */ | 1950 | */ |
1968 | while (G1.lookahead < MIN_LOOKAHEAD && !G1.eofile) | 1951 | while (G1.lookahead < MIN_LOOKAHEAD && !G1.eofile) |
1969 | fill_window(); | 1952 | fill_window(); |
1970 | 1953 | ||
1971 | G1.ins_h = 0; | 1954 | //G1.ins_h = 0; // globals are zeroed in pack_gzip() |
1972 | for (j = 0; j < MIN_MATCH - 1; j++) | 1955 | for (j = 0; j < MIN_MATCH - 1; j++) |
1973 | UPDATE_HASH(G1.ins_h, G1.window[j]); | 1956 | UPDATE_HASH(G1.ins_h, G1.window[j]); |
1974 | /* If lookahead < MIN_MATCH, ins_h is garbage, but this is | 1957 | /* If lookahead < MIN_MATCH, ins_h is garbage, but this is |
@@ -1990,7 +1973,7 @@ static void ct_init(void) | |||
1990 | int code; /* code value */ | 1973 | int code; /* code value */ |
1991 | int dist; /* distance index */ | 1974 | int dist; /* distance index */ |
1992 | 1975 | ||
1993 | G2.compressed_len = 0L; | 1976 | //G2.compressed_len = 0L; // globals are zeroed in pack_gzip() |
1994 | 1977 | ||
1995 | #ifdef NOT_NEEDED | 1978 | #ifdef NOT_NEEDED |
1996 | if (G2.static_dtree[0].Len != 0) | 1979 | if (G2.static_dtree[0].Len != 0) |
@@ -2073,12 +2056,11 @@ static void ct_init(void) | |||
2073 | * Deflate in to out. | 2056 | * Deflate in to out. |
2074 | * IN assertions: the input and output buffers are cleared. | 2057 | * IN assertions: the input and output buffers are cleared. |
2075 | */ | 2058 | */ |
2076 | |||
2077 | static void zip(void) | 2059 | static void zip(void) |
2078 | { | 2060 | { |
2079 | ush deflate_flags = 0; /* pkzip -es, -en or -ex equivalent */ | 2061 | ush deflate_flags = 0; /* pkzip -es, -en or -ex equivalent */ |
2080 | 2062 | ||
2081 | G1.outcnt = 0; | 2063 | //G1.outcnt = 0; // globals are zeroed in pack_gzip() |
2082 | 2064 | ||
2083 | /* Write the header to the gzip file. See algorithm.doc for the format */ | 2065 | /* Write the header to the gzip file. See algorithm.doc for the format */ |
2084 | /* magic header for gzip files: 1F 8B */ | 2066 | /* magic header for gzip files: 1F 8B */ |
@@ -2111,12 +2093,15 @@ static void zip(void) | |||
2111 | static | 2093 | static |
2112 | IF_DESKTOP(long long) int FAST_FUNC pack_gzip(transformer_state_t *xstate UNUSED_PARAM) | 2094 | IF_DESKTOP(long long) int FAST_FUNC pack_gzip(transformer_state_t *xstate UNUSED_PARAM) |
2113 | { | 2095 | { |
2096 | /* Reinit G1.xxx except pointers to allocated buffers */ | ||
2097 | memset(&G1, 0, offsetof(struct globals, l_buf)); | ||
2098 | |||
2114 | /* Clear input and output buffers */ | 2099 | /* Clear input and output buffers */ |
2115 | G1.outcnt = 0; | 2100 | //G1.outcnt = 0; |
2116 | #ifdef DEBUG | 2101 | #ifdef DEBUG |
2117 | G1.insize = 0; | 2102 | //G1.insize = 0; |
2118 | #endif | 2103 | #endif |
2119 | G1.isize = 0; | 2104 | //G1.isize = 0; |
2120 | 2105 | ||
2121 | /* Reinit G2.xxx */ | 2106 | /* Reinit G2.xxx */ |
2122 | memset(&G2, 0, sizeof(G2)); | 2107 | memset(&G2, 0, sizeof(G2)); |