]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Add block_open state for deflate_quick
authorPhil Vachon <pvachon@12sidedtech.com>
Mon, 30 Jan 2017 14:28:25 +0000 (15:28 +0100)
committerHans Kristian Rosbach <hk-git@circlestorm.org>
Mon, 13 Feb 2017 09:16:51 +0000 (10:16 +0100)
By storing whether or not a block has been opened (or terminated), the
static trees used for the block and the end block markers can be emitted
appropriately.

arch/x86/deflate_quick.c
deflate.h

index c7e805d702138e9f8da6472cdda4c7506c57ebd0..422c3250ed632b8a0bac42aa5fc3b35228dcfc99 100644 (file)
@@ -177,6 +177,7 @@ static void static_emit_end_block(deflate_state *const s, int last) {
 
     s->block_start = s->strstart;
     flush_pending(s->strm);
+    s->block_open = 0;
 }
 
 static inline Pos quick_insert_string(deflate_state *const s, const Pos str) {
@@ -203,8 +204,9 @@ ZLIB_INTERNAL block_state deflate_quick(deflate_state *s, int flush) {
     IPos hash_head;
     unsigned dist, match_len;
 
-    if (s->strm->total_out == 2) {
+    if (s->block_open == 0) {
         static_emit_tree(s, flush);
+        s->block_open = 1;
     }
 
     do {
index 75e14b1b7ddc5ddde2bdf9d8ec4116fcf28bcfda..c8381cbfbca5c280e1f30fc25c5013150bb00d83 100644 (file)
--- a/deflate.h
+++ b/deflate.h
@@ -281,6 +281,12 @@ typedef struct internal_state {
      * longest match routines access bytes past the input.  This is then
      * updated to the new high water mark.
      */
+    int block_open;
+    /* Whether or not a block is currently open for the QUICK deflation scheme.
+     * This is set to 1 if there is an active block, or 0 if the block was just
+     * closed.
+     */
+
 } deflate_state;
 
 typedef enum {