]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Move check to start block out of main loop for performance reasons.
authorNathan Moinvaziri <nathan@solidstatenetworks.com>
Tue, 16 Jun 2020 20:35:27 +0000 (13:35 -0700)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Thu, 18 Jun 2020 20:12:10 +0000 (22:12 +0200)
deflate_quick.c

index 5be963a445f03c661732b983446005c2ee345584..63793a38bbe0077b5d93688103f8dd124f061c0f 100644 (file)
@@ -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;