Cache s->ins_h in a scalar while looping. This makes a big difference on long repeated inputs.

This commit is contained in:
Michael Chastain 2016-01-26 15:27:21 -08:00 committed by Xin Li
parent 6cef1de740
commit 1a7549b1ee
1 changed files with 17 additions and 12 deletions

View File

@ -178,15 +178,15 @@ struct static_tree_desc_s {int dummy;}; /* for buggy compilers */
* (except for the last MIN_MATCH-1 bytes of the input file).
*/
#ifdef FASTEST
#define INSERT_STRING(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))
#define INSERT_STRING(s, h, str, match_head) \
(UPDATE_HASH(s, h, s->window[(str) + (MIN_MATCH-1)]), \
match_head = s->head[h], \
s->head[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))
#define INSERT_STRING(s, h, str, match_head) \
(UPDATE_HASH(s, h, s->window[(str) + (MIN_MATCH-1)]), \
match_head = s->prev[(str) & s->w_mask] = s->head[h], \
s->head[h] = (Pos)(str))
#endif
/* ===========================================================================
@ -1650,7 +1650,7 @@ local block_state deflate_fast(s, flush)
*/
hash_head = NIL;
if (s->lookahead >= MIN_MATCH) {
INSERT_STRING(s, s->strstart, hash_head);
INSERT_STRING(s, s->ins_h, s->strstart, hash_head);
}
/* Find the longest match, discarding those <= prev_length.
@ -1678,14 +1678,16 @@ local block_state deflate_fast(s, flush)
#ifndef FASTEST
if (s->match_length <= s->max_insert_length &&
s->lookahead >= MIN_MATCH) {
uInt t_ins_h = s->ins_h;
s->match_length--; /* string at strstart already in table */
do {
s->strstart++;
INSERT_STRING(s, s->strstart, hash_head);
INSERT_STRING(s, t_ins_h, s->strstart, hash_head);
/* strstart never exceeds WSIZE-MAX_MATCH, so there are
* always MIN_MATCH bytes ahead.
*/
} while (--s->match_length != 0);
s->ins_h = t_ins_h;
s->strstart++;
} else
#endif
@ -1753,7 +1755,7 @@ local block_state deflate_slow(s, flush)
*/
hash_head = NIL;
if (s->lookahead >= MIN_MATCH) {
INSERT_STRING(s, s->strstart, hash_head);
INSERT_STRING(s, s->ins_h, s->strstart, hash_head);
}
/* Find the longest match, discarding those <= prev_length.
@ -1788,6 +1790,7 @@ local block_state deflate_slow(s, flush)
*/
if (s->prev_length >= MIN_MATCH && s->match_length <= s->prev_length) {
uInt max_insert = s->strstart + s->lookahead - MIN_MATCH;
uInt t_ins_h;
/* Do not insert strings in hash table beyond this. */
check_match(s, s->strstart-1, s->prev_match, s->prev_length);
@ -1802,11 +1805,13 @@ local block_state deflate_slow(s, flush)
*/
s->lookahead -= s->prev_length-1;
s->prev_length -= 2;
t_ins_h = s->ins_h;
do {
if (++s->strstart <= max_insert) {
INSERT_STRING(s, s->strstart, hash_head);
INSERT_STRING(s, t_ins_h, s->strstart, hash_head);
}
} while (--s->prev_length != 0);
s->ins_h = t_ins_h;
s->match_available = 0;
s->match_length = MIN_MATCH-1;
s->strstart++;