Also ensure all deflate methods use local window variable.
deflate_medium now passes local window to its static functions.
s->strstart++;
}
if (UNLIKELY(bflush))
- FLUSH_BLOCK(s, 0);
+ FLUSH_BLOCK(s, window, 0);
}
s->insert = s->strstart < (STD_MIN_MATCH - 1) ? s->strstart : (STD_MIN_MATCH - 1);
if (UNLIKELY(flush == Z_FINISH)) {
- FLUSH_BLOCK(s, 1);
+ FLUSH_BLOCK(s, window, 1);
return finish_done;
}
if (UNLIKELY(s->sym_next))
- FLUSH_BLOCK(s, 0);
+ FLUSH_BLOCK(s, window, 0);
return block_done;
}
* (It will be regenerated if this run of deflate switches away from Huffman.)
*/
Z_INTERNAL block_state deflate_huff(deflate_state *s, int flush) {
+ unsigned char *window = s->window;
int bflush = 0; /* set if current block must be flushed */
for (;;) {
}
/* Output a literal byte */
- bflush = zng_tr_tally_lit(s, s->window[s->strstart]);
+ bflush = zng_tr_tally_lit(s, window[s->strstart]);
s->lookahead--;
s->strstart++;
if (bflush)
- FLUSH_BLOCK(s, 0);
+ FLUSH_BLOCK(s, window, 0);
}
s->insert = 0;
if (flush == Z_FINISH) {
- FLUSH_BLOCK(s, 1);
+ FLUSH_BLOCK(s, window, 1);
return finish_done;
}
if (s->sym_next)
- FLUSH_BLOCK(s, 0);
+ FLUSH_BLOCK(s, window, 0);
return block_done;
}
uint16_t orgstart;
};
-static int emit_match(deflate_state *s, struct match match) {
+static int emit_match(deflate_state *s, unsigned char *window, struct match match) {
int bflush = 0;
uint32_t match_len = match.match_length;
/* matches that are not long enough we need to emit as literals */
if (match_len < WANT_MIN_MATCH) {
while (match_len) {
- bflush += zng_tr_tally_lit(s, s->window[match.strstart]);
+ bflush += zng_tr_tally_lit(s, window[match.strstart]);
match_len--;
match.strstart++;
}
* - (current->match_length - 1) <= next->match_start
* - (current->match_length - 1) <= next->strstart
*/
-static void fizzle_matches(deflate_state *s, struct match *current, struct match *next) {
- unsigned char *window = s->window;
+static void fizzle_matches(deflate_state *s, unsigned char *window, struct match *current, struct match *next) {
unsigned char *match, *orig;
struct match c, n;
int changed = 0;
/* Align the first struct to start on a new cacheline, this allows us to fit both structs in one cacheline */
ALIGNED_(16) struct match current_match = {0};
struct match next_match = {0};
+ unsigned char *window = s->window;
/* For levels below 5, don't check the next position for a better match */
int early_exit = s->level < 5;
&& next_match.match_length >= WANT_MIN_MATCH
&& tmp_cmatch_len_sub <= next_match.match_start
&& tmp_cmatch_len_sub <= next_match.strstart) {
- fizzle_matches(s, ¤t_match, &next_match);
+ fizzle_matches(s, window, ¤t_match, &next_match);
}
s->strstart = current_match.strstart;
}
/* now emit the current match */
- bflush = emit_match(s, current_match);
+ bflush = emit_match(s, window, current_match);
/* move the "cursor" forward */
s->strstart += current_match.match_length;
if (UNLIKELY(bflush))
- FLUSH_BLOCK(s, 0);
+ FLUSH_BLOCK(s, window, 0);
}
s->insert = s->strstart < (STD_MIN_MATCH - 1) ? s->strstart : (STD_MIN_MATCH - 1);
if (flush == Z_FINISH) {
- FLUSH_BLOCK(s, 1);
+ FLUSH_BLOCK(s, window, 1);
return finish_done;
}
if (UNLIKELY(s->sym_next))
- FLUSH_BLOCK(s, 0);
+ FLUSH_BLOCK(s, window, 0);
return block_done;
}
* Flush the current block, with given end-of-file flag.
* IN assertion: strstart is set to the end of the current match.
*/
-#define FLUSH_BLOCK_ONLY(s, last) { \
- zng_tr_flush_block(s, (s->block_start >= 0 ? \
- &s->window[(unsigned)s->block_start] : \
+#define FLUSH_BLOCK_ONLY(s, window, last) { \
+ int block_start = s->block_start; \
+ zng_tr_flush_block(s, (block_start >= 0 ? \
+ &window[(unsigned)block_start] : \
NULL), \
- (uint32_t)((int)s->strstart - s->block_start), \
+ (uint32_t)((int)s->strstart - block_start), \
(last)); \
s->block_start = (int)s->strstart; \
PREFIX(flush_pending)(s->strm); \
}
/* Same but force premature exit if necessary. */
-#define FLUSH_BLOCK(s, last) { \
- FLUSH_BLOCK_ONLY(s, last); \
+#define FLUSH_BLOCK(s, window, last) { \
+ FLUSH_BLOCK_ONLY(s, window, last); \
if (s->strm->avail_out == 0) return (last) ? finish_started : need_more; \
}
* deflate switches away from Z_RLE.)
*/
Z_INTERNAL block_state deflate_rle(deflate_state *s, int flush) {
- int bflush = 0; /* set if current block must be flushed */
+ unsigned char *window = s->window;
unsigned char *scan; /* scan goes up to strend for length of run */
+ int bflush = 0; /* set if current block must be flushed */
uint32_t match_len = 0;
for (;;) {
/* See how many times the previous byte repeats */
if (s->lookahead >= STD_MIN_MATCH && s->strstart > 0) {
- scan = s->window + s->strstart - 1;
+ scan = window + s->strstart - 1;
if (scan[0] == scan[1] && scan[1] == scan[2]) {
match_len = compare256_rle(scan, scan+3)+2;
match_len = MIN(match_len, s->lookahead);
}
- Assert(scan+match_len <= s->window + s->window_size - 1, "wild scan");
+ Assert(scan+match_len <= window + s->window_size - 1, "wild scan");
}
/* Emit match if have run of STD_MIN_MATCH or longer, else emit literal */
match_len = 0;
} else {
/* No match, output a literal byte */
- bflush = zng_tr_tally_lit(s, s->window[s->strstart]);
+ bflush = zng_tr_tally_lit(s, window[s->strstart]);
s->lookahead--;
s->strstart++;
}
if (bflush)
- FLUSH_BLOCK(s, 0);
+ FLUSH_BLOCK(s, window, 0);
}
s->insert = 0;
if (flush == Z_FINISH) {
- FLUSH_BLOCK(s, 1);
+ FLUSH_BLOCK(s, window, 1);
return finish_done;
}
if (s->sym_next)
- FLUSH_BLOCK(s, 0);
+ FLUSH_BLOCK(s, window, 0);
return block_done;
}
s->strstart += mov_fwd + 1;
if (UNLIKELY(bflush))
- FLUSH_BLOCK(s, 0);
+ FLUSH_BLOCK(s, window, 0);
} else if (s->match_available) {
/* If there was no match at the previous position, output a
*/
bflush = zng_tr_tally_lit(s, window[s->strstart-1]);
if (UNLIKELY(bflush))
- FLUSH_BLOCK_ONLY(s, 0);
+ FLUSH_BLOCK_ONLY(s, window, 0);
s->prev_length = match_len;
s->strstart++;
s->lookahead--;
}
s->insert = s->strstart < (STD_MIN_MATCH - 1) ? s->strstart : (STD_MIN_MATCH - 1);
if (UNLIKELY(flush == Z_FINISH)) {
- FLUSH_BLOCK(s, 1);
+ FLUSH_BLOCK(s, window, 1);
return finish_done;
}
if (UNLIKELY(s->sym_next))
- FLUSH_BLOCK(s, 0);
+ FLUSH_BLOCK(s, window, 0);
return block_done;
}
* maximizes the opportunities to have a single copy from next_in to next_out.
*/
Z_INTERNAL block_state deflate_stored(deflate_state *s, int flush) {
+ unsigned char *window = s->window;
/* Smallest worthy block size when not flushing or finishing. By default
* this is 32K. This can be as small as 507 bytes for memLevel == 1. For
* large input and output buffers, the stored block size will be larger.
/* Copy uncompressed bytes from the window to next_out. */
if (left) {
left = MIN(left, len);
- memcpy(s->strm->next_out, s->window + s->block_start, left);
+ memcpy(s->strm->next_out, window + s->block_start, left);
s->strm->next_out += left;
s->strm->avail_out -= left;
s->strm->total_out += left;
*/
if (used >= w_size) { /* supplant the previous history */
s->matches = 2; /* clear hash */
- memcpy(s->window, s->strm->next_in - w_size, w_size);
+ memcpy(window, s->strm->next_in - w_size, w_size);
s->strstart = w_size;
s->insert = s->strstart;
} else {
if (s->window_size - s->strstart <= used) {
/* Slide the window down. */
s->strstart -= w_size;
- memcpy(s->window, s->window + w_size, s->strstart);
+ memcpy(window, window + w_size, s->strstart);
if (s->matches < 2)
s->matches++; /* add a pending slide_hash() */
s->insert = MIN(s->insert, s->strstart);
}
- memcpy(s->window + s->strstart, s->strm->next_in - used, used);
+ memcpy(window + s->strstart, s->strm->next_in - used, used);
s->strstart += used;
s->insert += MIN(used, w_size - s->insert);
}
/* Slide the window down. */
s->block_start -= (int)w_size;
s->strstart -= w_size;
- memcpy(s->window, s->window + w_size, s->strstart);
+ memcpy(window, window + w_size, s->strstart);
if (s->matches < 2)
s->matches++; /* add a pending slide_hash() */
have += w_size; /* more space now */
have = MIN(have, s->strm->avail_in);
if (have) {
- read_buf(s->strm, s->window + s->strstart, have);
+ read_buf(s->strm, window + s->strstart, have);
s->strstart += have;
s->insert += MIN(have, w_size - s->insert);
}
if (left >= min_block || ((left || flush == Z_FINISH) && flush != Z_NO_FLUSH && s->strm->avail_in == 0 && left <= have)) {
len = MIN(left, have);
last = flush == Z_FINISH && s->strm->avail_in == 0 && len == left ? 1 : 0;
- zng_tr_stored_block(s, s->window + s->block_start, len, last);
+ zng_tr_stored_block(s, window + s->block_start, len, last);
s->block_start += (int)len;
PREFIX(flush_pending)(s->strm);
}