aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2018-01-31 15:32:32 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2018-01-31 15:32:32 +0100
commit468731a86b850f6f1430a81b87cd7e2288300101 (patch)
tree1882f9969b19d398928fc3978b416ea77a484d26
parent631c16855a05f0699149502bba93a3ad8f88608e (diff)
downloadbusybox-w32-468731a86b850f6f1430a81b87cd7e2288300101.tar.gz
busybox-w32-468731a86b850f6f1430a81b87cd7e2288300101.tar.bz2
busybox-w32-468731a86b850f6f1430a81b87cd7e2288300101.zip
gzip: code shrink and speedup
function old new delta pack_gzip 908 861 -47 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--archival/gzip.c29
1 files changed, 17 insertions, 12 deletions
diff --git a/archival/gzip.c b/archival/gzip.c
index 5812f4b27..fa7a79b04 100644
--- a/archival/gzip.c
+++ b/archival/gzip.c
@@ -478,15 +478,14 @@ static void put_16bit(ush w)
478 put_8bit(w); 478 put_8bit(w);
479} 479}
480 480
481#define OPTIMIZED_PUT_32BIT (CONFIG_GZIP_FAST > 0 && BB_UNALIGNED_MEMACCESS_OK && BB_LITTLE_ENDIAN)
481static void put_32bit(ulg n) 482static void put_32bit(ulg n)
482{ 483{
483#if CONFIG_GZIP_FAST > 0 \ 484#if OPTIMIZED_PUT_32BIT
484 && BB_UNALIGNED_MEMACCESS_OK && BB_LITTLE_ENDIAN
485 unsigned outcnt = G1.outcnt; 485 unsigned outcnt = G1.outcnt;
486 if (outcnt < OUTBUFSIZ-4) { 486 if (outcnt < OUTBUFSIZ-4) {
487 /* Common case */ 487 /* Common case */
488 uch *dst = &G1.outbuf[outcnt]; 488 ulg *dst32 = (void*) &G1.outbuf[outcnt];
489 ulg *dst32 = (void*) dst;
490 *dst32 = n; /* unaligned LSB 32-bit store */ 489 *dst32 = n; /* unaligned LSB 32-bit store */
491 G1.outcnt = outcnt + 4; 490 G1.outcnt = outcnt + 4;
492 return; 491 return;
@@ -1951,7 +1950,7 @@ static void bi_init(void)
1951/* =========================================================================== 1950/* ===========================================================================
1952 * Initialize the "longest match" routines for a new file 1951 * Initialize the "longest match" routines for a new file
1953 */ 1952 */
1954static void lm_init(ush * flagsp) 1953static void lm_init(unsigned *flags16p)
1955{ 1954{
1956 unsigned j; 1955 unsigned j;
1957 1956
@@ -1960,7 +1959,7 @@ static void lm_init(ush * flagsp)
1960 /* prev will be initialized on the fly */ 1959 /* prev will be initialized on the fly */
1961 1960
1962 /* speed options for the general purpose bit flag */ 1961 /* speed options for the general purpose bit flag */
1963 *flagsp |= 2; /* FAST 4, SLOW 2 */ 1962 *flags16p |= 2; /* FAST 4, SLOW 2 */
1964 /* ??? reduce max_chain_length for binary files */ 1963 /* ??? reduce max_chain_length for binary files */
1965 1964
1966 //G1.strstart = 0; // globals are zeroed in pack_gzip() 1965 //G1.strstart = 0; // globals are zeroed in pack_gzip()
@@ -2044,9 +2043,8 @@ static void ct_init(void)
2044 Assert(dist == 256, "ct_init: 256+dist != 512"); 2043 Assert(dist == 256, "ct_init: 256+dist != 512");
2045 2044
2046 /* Construct the codes of the static literal tree */ 2045 /* Construct the codes of the static literal tree */
2047 /* already zeroed - it's in bss 2046 //for (n = 0; n <= MAX_BITS; n++) // globals are zeroed in pack_gzip()
2048 for (n = 0; n <= MAX_BITS; n++) 2047 // G2.bl_count[n] = 0;
2049 G2.bl_count[n] = 0; */
2050 2048
2051 n = 0; 2049 n = 0;
2052 while (n <= 143) { 2050 while (n <= 143) {
@@ -2088,7 +2086,7 @@ static void ct_init(void)
2088 */ 2086 */
2089static void zip(void) 2087static void zip(void)
2090{ 2088{
2091 ush deflate_flags = 0; /* pkzip -es, -en or -ex equivalent */ 2089 unsigned deflate_flags;
2092 2090
2093 //G1.outcnt = 0; // globals are zeroed in pack_gzip() 2091 //G1.outcnt = 0; // globals are zeroed in pack_gzip()
2094 2092
@@ -2104,10 +2102,17 @@ static void zip(void)
2104 2102
2105 bi_init(); 2103 bi_init();
2106 ct_init(); 2104 ct_init();
2105 deflate_flags = 0; /* pkzip -es, -en or -ex equivalent */
2107 lm_init(&deflate_flags); 2106 lm_init(&deflate_flags);
2108 2107
2109 put_8bit(deflate_flags); /* extra flags */ 2108 put_16bit(deflate_flags | 0x300); /* extra flags. OS id = 3 (Unix) */
2110 put_8bit(3); /* OS identifier = 3 (Unix) */ 2109
2110#if OPTIMIZED_PUT_32BIT
2111 /* put_32bit() performs 32bit stores. If we use it in send_bits()... */
2112 if (BUF_SIZE > 16)
2113 /* then all stores are misaligned, unless we flush the buffer now */
2114 flush_outbuf();
2115#endif
2111 2116
2112 deflate(); 2117 deflate();
2113 2118