diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2018-01-30 18:15:39 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-01-30 18:15:39 +0100 |
commit | 9c499a5af48bd4d9d635c8021e6ad14fd4e939dc (patch) | |
tree | d1e5f5c5bbde5c34cb70a2f1e2bf37bbe15ac24c | |
parent | c6d2a26fac47eafc08f291dab78bbca3088f8ca2 (diff) | |
download | busybox-w32-9c499a5af48bd4d9d635c8021e6ad14fd4e939dc.tar.gz busybox-w32-9c499a5af48bd4d9d635c8021e6ad14fd4e939dc.tar.bz2 busybox-w32-9c499a5af48bd4d9d635c8021e6ad14fd4e939dc.zip |
gzip: code shrink
function old new delta
fill_window_if_needed - 238 +238
deflate 924 907 -17
pack_gzip 809 790 -19
fill_window 216 - -216
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 0/2 up/down: 238/-252) Total: -14 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | archival/gzip.c | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/archival/gzip.c b/archival/gzip.c index 10eda7aa3..8ef66390a 100644 --- a/archival/gzip.c +++ b/archival/gzip.c | |||
@@ -312,25 +312,24 @@ struct globals { | |||
312 | #define nice_match (G1.nice_match) | 312 | #define nice_match (G1.nice_match) |
313 | #endif | 313 | #endif |
314 | 314 | ||
315 | lng block_start; | ||
316 | |||
317 | /* window position at the beginning of the current output block. Gets | 315 | /* window position at the beginning of the current output block. Gets |
318 | * negative when the window is moved backwards. | 316 | * negative when the window is moved backwards. |
319 | */ | 317 | */ |
318 | lng block_start; | ||
319 | |||
320 | unsigned ins_h; /* hash index of string to be inserted */ | 320 | unsigned ins_h; /* hash index of string to be inserted */ |
321 | 321 | ||
322 | #define H_SHIFT ((HASH_BITS+MIN_MATCH-1) / MIN_MATCH) | ||
323 | /* Number of bits by which ins_h and del_h must be shifted at each | 322 | /* Number of bits by which ins_h and del_h must be shifted at each |
324 | * input step. It must be such that after MIN_MATCH steps, the oldest | 323 | * input step. It must be such that after MIN_MATCH steps, the oldest |
325 | * byte no longer takes part in the hash key, that is: | 324 | * byte no longer takes part in the hash key, that is: |
326 | * H_SHIFT * MIN_MATCH >= HASH_BITS | 325 | * H_SHIFT * MIN_MATCH >= HASH_BITS |
327 | */ | 326 | */ |
328 | 327 | #define H_SHIFT ((HASH_BITS+MIN_MATCH-1) / MIN_MATCH) | |
329 | unsigned prev_length; | ||
330 | 328 | ||
331 | /* Length of the best match at previous step. Matches not greater than this | 329 | /* Length of the best match at previous step. Matches not greater than this |
332 | * are discarded. This is used in the lazy match evaluation. | 330 | * are discarded. This is used in the lazy match evaluation. |
333 | */ | 331 | */ |
332 | unsigned prev_length; | ||
334 | 333 | ||
335 | unsigned strstart; /* start of string to insert */ | 334 | unsigned strstart; /* start of string to insert */ |
336 | unsigned match_start; /* start of matching string */ | 335 | unsigned match_start; /* start of matching string */ |
@@ -347,18 +346,17 @@ struct globals { | |||
347 | unsigned insize; /* valid bytes in l_buf */ | 346 | unsigned insize; /* valid bytes in l_buf */ |
348 | #endif | 347 | #endif |
349 | unsigned outcnt; /* bytes in output buffer */ | 348 | unsigned outcnt; /* bytes in output buffer */ |
350 | |||
351 | smallint eofile; /* flag set at end of input file */ | 349 | smallint eofile; /* flag set at end of input file */ |
352 | 350 | ||
353 | /* =========================================================================== | 351 | /* =========================================================================== |
354 | * Local data used by the "bit string" routines. | 352 | * Local data used by the "bit string" routines. |
355 | */ | 353 | */ |
356 | 354 | ||
357 | unsigned short bi_buf; | ||
358 | |||
359 | /* Output buffer. bits are inserted starting at the bottom (least significant | 355 | /* Output buffer. bits are inserted starting at the bottom (least significant |
360 | * bits). | 356 | * bits). |
361 | */ | 357 | */ |
358 | unsigned short bi_buf; | ||
359 | |||
362 | #undef BUF_SIZE | 360 | #undef BUF_SIZE |
363 | #define BUF_SIZE (8 * sizeof(G1.bi_buf)) | 361 | #define BUF_SIZE (8 * sizeof(G1.bi_buf)) |
364 | 362 | ||
@@ -368,7 +366,7 @@ struct globals { | |||
368 | int bi_valid; | 366 | int bi_valid; |
369 | 367 | ||
370 | #ifdef DEBUG | 368 | #ifdef DEBUG |
371 | ulg bits_sent; /* bit length of the compressed data */ | 369 | ulg bits_sent; /* bit length of the compressed data */ |
372 | #endif | 370 | #endif |
373 | 371 | ||
374 | /*uint32_t *crc_32_tab;*/ | 372 | /*uint32_t *crc_32_tab;*/ |
@@ -662,6 +660,12 @@ static void fill_window(void) | |||
662 | } | 660 | } |
663 | } | 661 | } |
664 | } | 662 | } |
663 | /* Both users fill window with the same loop: */ | ||
664 | static void fill_window_if_needed(void) | ||
665 | { | ||
666 | while (G1.lookahead < MIN_LOOKAHEAD && !G1.eofile) | ||
667 | fill_window(); | ||
668 | } | ||
665 | 669 | ||
666 | 670 | ||
667 | /* =========================================================================== | 671 | /* =========================================================================== |
@@ -1894,8 +1898,7 @@ static NOINLINE ulg deflate(void) | |||
1894 | * for the next match, plus MIN_MATCH bytes to insert the | 1898 | * for the next match, plus MIN_MATCH bytes to insert the |
1895 | * string following the next match. | 1899 | * string following the next match. |
1896 | */ | 1900 | */ |
1897 | while (G1.lookahead < MIN_LOOKAHEAD && !G1.eofile) | 1901 | fill_window_if_needed(); |
1898 | fill_window(); | ||
1899 | } | 1902 | } |
1900 | if (match_available) | 1903 | if (match_available) |
1901 | ct_tally(0, G1.window[G1.strstart - 1]); | 1904 | ct_tally(0, G1.window[G1.strstart - 1]); |
@@ -1948,8 +1951,7 @@ static void lm_init(ush * flagsp) | |||
1948 | /* Make sure that we always have enough lookahead. This is important | 1951 | /* Make sure that we always have enough lookahead. This is important |
1949 | * if input comes from a device such as a tty. | 1952 | * if input comes from a device such as a tty. |
1950 | */ | 1953 | */ |
1951 | while (G1.lookahead < MIN_LOOKAHEAD && !G1.eofile) | 1954 | fill_window_if_needed(); |
1952 | fill_window(); | ||
1953 | 1955 | ||
1954 | //G1.ins_h = 0; // globals are zeroed in pack_gzip() | 1956 | //G1.ins_h = 0; // globals are zeroed in pack_gzip() |
1955 | for (j = 0; j < MIN_MATCH - 1; j++) | 1957 | for (j = 0; j < MIN_MATCH - 1; j++) |