aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaro Koskinen <aaro.koskinen@iki.fi>2015-04-26 14:22:05 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2015-04-26 14:22:37 +0200
commitbbd53216f80912944da0d4ca72bf3ed3188ca156 (patch)
tree381920f0258b329ef591d7b4408441322b116c74
parent93b98ff5726fd620e1f123d04072b956412c1b55 (diff)
downloadbusybox-w32-bbd53216f80912944da0d4ca72bf3ed3188ca156.tar.gz
busybox-w32-bbd53216f80912944da0d4ca72bf3ed3188ca156.tar.bz2
busybox-w32-bbd53216f80912944da0d4ca72bf3ed3188ca156.zip
gzip: add support for compression levels 4-9
function old new delta gzip_main 192 282 +90 static.gzip_level_config - 24 +24 packed_usage 30439 30459 +20 fill_window 216 220 +4 pack_gzip 1789 1729 -60 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 3/1 up/down: 138/-60) Total: 78 bytes Signed-off-by: Aaro Koskinen <aaro.koskinen@iki.fi> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--archival/gzip.c72
1 files changed, 62 insertions, 10 deletions
diff --git a/archival/gzip.c b/archival/gzip.c
index bc1f9c60b..42b2f0b2e 100644
--- a/archival/gzip.c
+++ b/archival/gzip.c
@@ -62,14 +62,27 @@ aa: 85.1% -- replaced with aa.gz
62//config: 1: larger buffers, larger hash-tables 62//config: 1: larger buffers, larger hash-tables
63//config: 2: larger buffers, largest hash-tables 63//config: 2: larger buffers, largest hash-tables
64//config: Larger models may give slightly better compression 64//config: Larger models may give slightly better compression
65//config:
66//config:config FEATURE_GZIP_LEVELS
67//config: bool "Enable compression levels"
68//config: default n
69//config: depends on GZIP
70//config: help
71//config: Enable support for compression levels 4-9. The default level
72//config: is 6. If levels 1-3 are specified, 4 is used.
73//config: If this option is not selected, -N options are ignored and -9
74//config: is used.
65 75
66//applet:IF_GZIP(APPLET(gzip, BB_DIR_BIN, BB_SUID_DROP)) 76//applet:IF_GZIP(APPLET(gzip, BB_DIR_BIN, BB_SUID_DROP))
67//kbuild:lib-$(CONFIG_GZIP) += gzip.o 77//kbuild:lib-$(CONFIG_GZIP) += gzip.o
68 78
69//usage:#define gzip_trivial_usage 79//usage:#define gzip_trivial_usage
70//usage: "[-cfd] [FILE]..." 80//usage: "[-cfd" IF_FEATURE_GZIP_LEVELS("123456789") "] [FILE]..."
71//usage:#define gzip_full_usage "\n\n" 81//usage:#define gzip_full_usage "\n\n"
72//usage: "Compress FILEs (or stdin)\n" 82//usage: "Compress FILEs (or stdin)\n"
83//usage: IF_FEATURE_GZIP_LEVELS(
84//usage: "\n -1..9 Compression level"
85//usage: )
73//usage: "\n -d Decompress" 86//usage: "\n -d Decompress"
74//usage: "\n -c Write to stdout" 87//usage: "\n -c Write to stdout"
75//usage: "\n -f Force" 88//usage: "\n -f Force"
@@ -252,6 +265,8 @@ enum {
252 * input file length plus MIN_LOOKAHEAD. 265 * input file length plus MIN_LOOKAHEAD.
253 */ 266 */
254 267
268#ifndef ENABLE_FEATURE_GZIP_LEVELS
269
255 max_chain_length = 4096, 270 max_chain_length = 4096,
256/* To speed up deflation, hash chains are never searched beyond this length. 271/* To speed up deflation, hash chains are never searched beyond this length.
257 * A higher limit improves compression ratio but degrades the speed. 272 * A higher limit improves compression ratio but degrades the speed.
@@ -283,11 +298,23 @@ enum {
283 * For deflate_fast() (levels <= 3) good is ignored and lazy has a different 298 * For deflate_fast() (levels <= 3) good is ignored and lazy has a different
284 * meaning. 299 * meaning.
285 */ 300 */
301#endif /* ENABLE_FEATURE_GZIP_LEVELS */
286}; 302};
287 303
288 304
289struct globals { 305struct globals {
290 306
307#ifdef ENABLE_FEATURE_GZIP_LEVELS
308 unsigned max_chain_length;
309 unsigned max_lazy_match;
310 unsigned good_match;
311 unsigned nice_match;
312#define max_chain_length (G1.max_chain_length)
313#define max_lazy_match (G1.max_lazy_match)
314#define good_match (G1.good_match)
315#define nice_match (G1.nice_match)
316#endif
317
291 lng block_start; 318 lng block_start;
292 319
293/* window position at the beginning of the current output block. Gets 320/* window position at the beginning of the current output block. Gets
@@ -2161,24 +2188,48 @@ int gzip_main(int argc UNUSED_PARAM, char **argv)
2161#endif 2188#endif
2162{ 2189{
2163 unsigned opt; 2190 unsigned opt;
2191#ifdef ENABLE_FEATURE_GZIP_LEVELS
2192 static const struct {
2193 uint8_t good;
2194 uint8_t chain_shift;
2195 uint8_t lazy2;
2196 uint8_t nice2;
2197 } gzip_level_config[6] = {
2198 {4, 4, 4/2, 16/2}, /* Level 4 */
2199 {8, 5, 16/2, 32/2}, /* Level 5 */
2200 {8, 7, 16/2, 128/2}, /* Level 6 */
2201 {8, 8, 32/2, 128/2}, /* Level 7 */
2202 {32, 10, 128/2, 258/2}, /* Level 8 */
2203 {32, 12, 258/2, 258/2}, /* Level 9 */
2204 };
2205#endif
2206
2207 SET_PTR_TO_GLOBALS((char *)xzalloc(sizeof(struct globals)+sizeof(struct globals2))
2208 + sizeof(struct globals));
2164 2209
2165#if ENABLE_FEATURE_GZIP_LONG_OPTIONS 2210#if ENABLE_FEATURE_GZIP_LONG_OPTIONS
2166 applet_long_options = gzip_longopts; 2211 applet_long_options = gzip_longopts;
2167#endif 2212#endif
2168 /* Must match bbunzip's constants OPT_STDOUT, OPT_FORCE! */ 2213 /* Must match bbunzip's constants OPT_STDOUT, OPT_FORCE! */
2169 opt = getopt32(argv, "cfv" IF_GUNZIP("dt") "q123456789n"); 2214 opt = getopt32(argv, "cfv" IF_GUNZIP("dt") "qn123456789");
2170#if ENABLE_GUNZIP /* gunzip_main may not be visible... */ 2215#if ENABLE_GUNZIP /* gunzip_main may not be visible... */
2171 if (opt & 0x18) // -d and/or -t 2216 if (opt & 0x18) // -d and/or -t
2172 return gunzip_main(argc, argv); 2217 return gunzip_main(argc, argv);
2173#endif 2218#endif
2174 option_mask32 &= 0x7; /* ignore -q, -0..9 */ 2219#ifdef ENABLE_FEATURE_GZIP_LEVELS
2175 //if (opt & 0x1) // -c 2220 opt >>= ENABLE_GUNZIP ? 7 : 5; /* drop cfv[dt]qn bits */
2176 //if (opt & 0x2) // -f 2221 if (opt == 0)
2177 //if (opt & 0x4) // -v 2222 opt = 1 << 6; /* default: 6 */
2178 argv += optind; 2223 /* Map 1..3 to 4 */
2179 2224 if (opt & 0x7)
2180 SET_PTR_TO_GLOBALS((char *)xzalloc(sizeof(struct globals)+sizeof(struct globals2)) 2225 opt |= 1 << 4;
2181 + sizeof(struct globals)); 2226 opt = ffs(opt >> 3);
2227 max_chain_length = 1 << gzip_level_config[opt].chain_shift;
2228 good_match = gzip_level_config[opt].good;
2229 max_lazy_match = gzip_level_config[opt].lazy2 * 2;
2230 nice_match = gzip_level_config[opt].nice2 * 2;
2231#endif
2232 option_mask32 &= 0x7; /* retain only -cfv */
2182 2233
2183 /* Allocate all global buffers (for DYN_ALLOC option) */ 2234 /* Allocate all global buffers (for DYN_ALLOC option) */
2184 ALLOC(uch, G1.l_buf, INBUFSIZ); 2235 ALLOC(uch, G1.l_buf, INBUFSIZ);
@@ -2190,5 +2241,6 @@ int gzip_main(int argc UNUSED_PARAM, char **argv)
2190 /* Initialize the CRC32 table */ 2241 /* Initialize the CRC32 table */
2191 global_crc32_table = crc32_filltable(NULL, 0); 2242 global_crc32_table = crc32_filltable(NULL, 0);
2192 2243
2244 argv += optind;
2193 return bbunpack(argv, pack_gzip, append_ext, "gz"); 2245 return bbunpack(argv, pack_gzip, append_ext, "gz");
2194} 2246}