diff options
author | Nathan Moinvaziri <nathan@solidstatenetworks.com> | 2020-06-16 13:35:27 -0700 |
---|---|---|
committer | Hans Kristian Rosbach <hk-github@circlestorm.org> | 2020-06-18 22:12:10 +0200 |
commit | e617236ab3f5f8bc59bcde16ea44a44420fe8a7f (patch) | |
tree | 5db11dd89ddb4669751ad954a6acf49375c032be /deflate_quick.c | |
parent | 1631b5cf3a14969df54c6dd2473085d0ec748388 (diff) |
Move check to start block out of main loop for performance reasons.
Diffstat (limited to 'deflate_quick.c')
-rw-r--r-- | deflate_quick.c | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/deflate_quick.c b/deflate_quick.c index 5be963a..63793a3 100644 --- a/deflate_quick.c +++ b/deflate_quick.c @@ -44,7 +44,23 @@ ZLIB_INTERNAL block_state deflate_quick(deflate_state *s, int flush) { Pos hash_head; unsigned dist, match_len, last; + + if (s->block_open == 0 && s->lookahead > 0) { + /* Start new block only when we have lookahead data, so that if no + input data is given an empty block will not be written */ + last = (flush == Z_FINISH) ? 1 : 0; + QUICK_START_BLOCK(s, last); + } + do { + if (s->pending + ((BIT_BUF_SIZE + 7) >> 3) >= s->pending_buf_size) { + flush_pending(s->strm); + if (s->strm->avail_out == 0 && flush != Z_FINISH) { + /* Break to emit end block and return need_more */ + break; + } + } + if (s->lookahead < MIN_LOOKAHEAD) { fill_window(s); if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) { @@ -55,23 +71,15 @@ ZLIB_INTERNAL block_state deflate_quick(deflate_state *s, int flush) { } if (s->lookahead == 0) break; - } - if (s->pending + ((BIT_BUF_SIZE + 7) >> 3) >= s->pending_buf_size) { - flush_pending(s->strm); - if (s->strm->avail_out == 0 && flush != Z_FINISH) { - /* Break to emit end block and return need_more */ - break; + if (s->block_open == 0) { + /* Start new block when we have lookahead data, so that if no + input data is given an empty block will not be written */ + last = (flush == Z_FINISH) ? 1 : 0; + QUICK_START_BLOCK(s, last); } } - if (s->block_open == 0) { - /* Start new block when we have lookahead data, so that if no - input data is given an empty block will not be written */ - last = (flush == Z_FINISH) ? 1 : 0; - QUICK_START_BLOCK(s, last); - } - if (s->lookahead >= MIN_MATCH) { hash_head = functable.quick_insert_string(s, s->strstart); dist = s->strstart - hash_head; |