--- zlib-1.2.3/deflate.c.orig Tue Nov 8 05:34:40 2011 +++ zlib-1.2.3/deflate.c Tue Nov 8 06:58:40 2011 @@ -60,6 +60,8 @@ copyright string in the executable of your product. */ +int fastest=1; + /* =========================================================================== * Function prototypes. */ @@ -76,14 +78,11 @@ local void fill_window OF((deflate_state *s)); local block_state deflate_stored OF((deflate_state *s, int flush)); local block_state deflate_fast OF((deflate_state *s, int flush)); -#ifndef FASTEST local block_state deflate_slow OF((deflate_state *s, int flush)); -#endif local void lm_init OF((deflate_state *s)); local void putShortMSB OF((deflate_state *s, uInt b)); local void flush_pending OF((z_streamp strm)); local int read_buf OF((z_streamp strm, Bytef *buf, unsigned size)); -#ifndef FASTEST #ifdef ASMV void match_init OF((void)); /* asm code initialization */ uInt longest_match OF((deflate_state *s, IPos cur_match)); @@ -90,7 +89,6 @@ #else local uInt longest_match OF((deflate_state *s, IPos cur_match)); #endif -#endif local uInt longest_match_fast OF((deflate_state *s, IPos cur_match)); #ifdef DEBUG @@ -128,12 +126,6 @@ compress_func func; } config; -#ifdef FASTEST -local const config configuration_table[2] = { -/* good lazy nice chain */ -/* 0 */ {0, 0, 0, 0, deflate_stored}, /* store only */ -/* 1 */ {4, 4, 8, 4, deflate_fast}}; /* max speed, no lazy matches */ -#else local const config configuration_table[10] = { /* good lazy nice chain */ /* 0 */ {0, 0, 0, 0, deflate_stored}, /* store only */ @@ -147,7 +139,6 @@ /* 7 */ {8, 32, 128, 256, deflate_slow}, /* 8 */ {32, 128, 258, 1024, deflate_slow}, /* 9 */ {32, 258, 258, 4096, deflate_slow}}; /* max compression */ -#endif /* Note: the deflate() code requires max_lazy >= MIN_MATCH and max_chain >= 4 * For deflate_fast() (levels <= 3) good is ignored and lazy has a different @@ -174,23 +165,20 @@ * Insert string str in the dictionary and set match_head to the previous head * of the hash chain (the most recent string with same hash key). Return * the previous length of the hash chain. - * If this file is compiled with -DFASTEST, the compression level is forced + * If fastest mode is enabled, the compression level is forced * to 1, and no hash chains are maintained. * IN assertion: all calls to to INSERT_STRING are made with consecutive * input characters and the first MIN_MATCH bytes of str are valid * (except for the last MIN_MATCH-1 bytes of the input file). */ -#ifdef FASTEST -#define INSERT_STRING(s, str, match_head) \ +#define INSERT_STRING_FAST(s, str, match_head) \ (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \ match_head = s->head[s->ins_h], \ s->head[s->ins_h] = (Pos)(str)) -#else #define INSERT_STRING(s, str, match_head) \ (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \ match_head = s->prev[(str) & s->w_mask] = s->head[s->ins_h], \ s->head[s->ins_h] = (Pos)(str)) -#endif /* =========================================================================== * Initialize the hash table (avoiding 64K overflow for 16 bit systems). @@ -246,11 +234,11 @@ } if (strm->zfree == (free_func)0) strm->zfree = zcfree; -#ifdef FASTEST - if (level != 0) level = 1; -#else - if (level == Z_DEFAULT_COMPRESSION) level = 6; -#endif + if (fastest) { + if (level != 0) level = 1; + } else { + if (level == Z_DEFAULT_COMPRESSION) level = 6; + } if (windowBits < 0) { /* suppress zlib wrapper */ wrap = 0; @@ -346,8 +334,14 @@ */ s->ins_h = s->window[0]; UPDATE_HASH(s, s->ins_h, s->window[1]); - for (n = 0; n <= length - MIN_MATCH; n++) { - INSERT_STRING(s, n, hash_head); + if (fastest) { + for (n = 0; n <= length - MIN_MATCH; n++) { + INSERT_STRING_FAST(s, n, hash_head); + } + } else { + for (n = 0; n <= length - MIN_MATCH; n++) { + INSERT_STRING(s, n, hash_head); + } } if (hash_head) hash_head = 0; /* to make compiler happy */ return Z_OK; @@ -425,11 +419,12 @@ if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; s = strm->state; -#ifdef FASTEST - if (level != 0) level = 1; -#else - if (level == Z_DEFAULT_COMPRESSION) level = 6; -#endif + if (fastest) { + if (level != 0) level = 1; + } else { + if (level == Z_DEFAULT_COMPRESSION) level = 6; + } + if (level < 0 || level > 9 || strategy < 0 || strategy > Z_FIXED) { return Z_STREAM_ERROR; } @@ -1003,14 +998,11 @@ s->match_length = s->prev_length = MIN_MATCH-1; s->match_available = 0; s->ins_h = 0; -#ifndef FASTEST #ifdef ASMV match_init(); /* initialize the asm code */ #endif -#endif } -#ifndef FASTEST /* =========================================================================== * Set match_start to the longest match starting at the given string and * return its length. Matches shorter or equal to prev_length are discarded, @@ -1167,7 +1159,6 @@ return s->lookahead; } #endif /* ASMV */ -#endif /* FASTEST */ /* --------------------------------------------------------------------------- * Optimized version for level == 1 or strategy == Z_RLE only @@ -1312,16 +1303,16 @@ } while (--n); n = wsize; -#ifndef FASTEST - p = &s->prev[n]; - do { - m = *--p; - *p = (Pos)(m >= wsize ? m-wsize : NIL); - /* If n is not on any hash chain, prev[n] is garbage but - * its value will never be used. - */ - } while (--n); -#endif + if (!fastest) { + p = &s->prev[n]; + do { + m = *--p; + *p = (Pos)(m >= wsize ? m-wsize : NIL); + /* If n is not on any hash chain, prev[n] is garbage but + * its value will never be used. + */ + } while (--n); + } more += wsize; } if (s->strm->avail_in == 0) return; @@ -1470,7 +1461,10 @@ * dictionary, and set hash_head to the head of the hash chain: */ if (s->lookahead >= MIN_MATCH) { - INSERT_STRING(s, s->strstart, hash_head); + if (fastest) + INSERT_STRING_FAST(s, s->strstart, hash_head); + else + INSERT_STRING(s, s->strstart, hash_head); } /* Find the longest match, discarding those <= prev_length. @@ -1481,18 +1475,14 @@ * of window index 0 (in particular we have to avoid a match * of the string with itself at the start of the input file). */ -#ifdef FASTEST - if ((s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) || - (s->strategy == Z_RLE && s->strstart - hash_head == 1)) { - s->match_length = longest_match_fast (s, hash_head); - } -#else if (s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) { - s->match_length = longest_match (s, hash_head); + if (!fastest) + s->match_length = longest_match (s, hash_head); + else + s->match_length = longest_match_fast (s, hash_head); } else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) { s->match_length = longest_match_fast (s, hash_head); } -#endif /* longest_match() or longest_match_fast() sets match_start */ } if (s->match_length >= MIN_MATCH) { @@ -1506,8 +1496,7 @@ /* Insert new strings in the hash table only if the match length * is not too large. This saves time but degrades compression. */ -#ifndef FASTEST - if (s->match_length <= s->max_insert_length && + if (!fastest && s->match_length <= s->max_insert_length && s->lookahead >= MIN_MATCH) { s->match_length--; /* string at strstart already in table */ do { @@ -1519,7 +1508,6 @@ } while (--s->match_length != 0); s->strstart++; } else -#endif { s->strstart += s->match_length; s->match_length = 0; @@ -1545,7 +1533,6 @@ return flush == Z_FINISH ? finish_done : block_done; } -#ifndef FASTEST /* =========================================================================== * Same as above, but achieves better compression. We use a lazy * evaluation for matches: a match is finally adopted only if there is @@ -1672,7 +1659,6 @@ FLUSH_BLOCK(s, flush == Z_FINISH); return flush == Z_FINISH ? finish_done : block_done; } -#endif /* FASTEST */ #if 0 /* ===========================================================================