| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
#include "zbuild.h" |
| 8 |
#include "deflate.h" |
| 9 |
#include "deflate_p.h" |
| 10 |
#include "functable.h" |
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
Z_INTERNAL block_state deflate_fast(deflate_state *s, int flush) { |
| 20 |
Pos hash_head; |
| 21 |
int bflush = 0; |
| 22 |
int64_t dist; |
| 23 |
uint32_t match_len = 0; |
| 24 |
|
| 25 |
for (;;) { |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
if (s->lookahead < MIN_LOOKAHEAD) { |
| 32 |
fill_window(s); |
| 33 |
if (UNLIKELY(s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH)) { |
| 34 |
return need_more; |
| 35 |
} |
| 36 |
if (UNLIKELY(s->lookahead == 0)) |
| 37 |
break; |
| 38 |
} |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
if (s->lookahead >= WANT_MIN_MATCH) { |
| 44 |
hash_head = functable.quick_insert_string(s, s->strstart); |
| 45 |
dist = (int64_t)s->strstart - hash_head; |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
if (dist <= MAX_DIST(s) && dist > 0 && hash_head != 0) { |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
match_len = functable.longest_match(s, hash_head); |
| 56 |
|
| 57 |
} |
| 58 |
} |
| 59 |
|
| 60 |
if (match_len >= WANT_MIN_MATCH) { |
| 61 |
check_match(s, s->strstart, s->match_start, match_len); |
| 62 |
|
| 63 |
bflush = zng_tr_tally_dist(s, s->strstart - s->match_start, match_len - STD_MIN_MATCH); |
| 64 |
|
| 65 |
s->lookahead -= match_len; |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
if (match_len <= s->max_insert_length && s->lookahead >= WANT_MIN_MATCH) { |
| 71 |
match_len--; |
| 72 |
s->strstart++; |
| 73 |
|
| 74 |
functable.insert_string(s, s->strstart, match_len); |
| 75 |
s->strstart += match_len; |
| 76 |
} else { |
| 77 |
s->strstart += match_len; |
| 78 |
functable.quick_insert_string(s, s->strstart + 2 - STD_MIN_MATCH); |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
} |
| 84 |
match_len = 0; |
| 85 |
} else { |
| 86 |
|
| 87 |
bflush = zng_tr_tally_lit(s, s->window[s->strstart]); |
| 88 |
s->lookahead--; |
| 89 |
s->strstart++; |
| 90 |
} |
| 91 |
if (UNLIKELY(bflush)) |
| 92 |
FLUSH_BLOCK(s, 0); |
| 93 |
} |
| 94 |
s->insert = s->strstart < (STD_MIN_MATCH - 1) ? s->strstart : (STD_MIN_MATCH - 1); |
| 95 |
if (UNLIKELY(flush == Z_FINISH)) { |
| 96 |
FLUSH_BLOCK(s, 1); |
| 97 |
return finish_done; |
| 98 |
} |
| 99 |
if (UNLIKELY(s->sym_next)) |
| 100 |
FLUSH_BLOCK(s, 0); |
| 101 |
return block_done; |
| 102 |
} |