aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Adler <madler@alumni.caltech.edu>2012-01-07 11:00:37 -0800
committerMark Adler <madler@alumni.caltech.edu>2012-01-07 14:03:07 -0800
commit8f5eceefe8b384d7c18813519cb337efef21a0f3 (patch)
treeb78f56b0a617615a378f14742e0484ebaa29226c
parent263b1a05b04e442896d7941f87d022a2f35a9220 (diff)
downloadzlib-8f5eceefe8b384d7c18813519cb337efef21a0f3.tar.gz
zlib-8f5eceefe8b384d7c18813519cb337efef21a0f3.tar.bz2
zlib-8f5eceefe8b384d7c18813519cb337efef21a0f3.zip
Remove second empty static block for Z_PARTIAL_FLUSH.
Z_PARTIAL_FLUSH would sometimes emit two empty static blocks instead of one in order to provide enough lookahead for inflate to be able to decode what was last compressed. inflate no longer needs that much lookahead, so this removes the possibility of emitting the second empty static block. Z_PARTIAL_FLUSH will now emit only one empty static block.
-rw-r--r--deflate.h1
-rw-r--r--trees.c24
2 files changed, 0 insertions, 25 deletions
diff --git a/deflate.h b/deflate.h
index 9284329..3590e4d 100644
--- a/deflate.h
+++ b/deflate.h
@@ -247,7 +247,6 @@ typedef struct internal_state {
247 ulg opt_len; /* bit length of current block with optimal trees */ 247 ulg opt_len; /* bit length of current block with optimal trees */
248 ulg static_len; /* bit length of current block with static trees */ 248 ulg static_len; /* bit length of current block with static trees */
249 uInt matches; /* number of string matches in current block */ 249 uInt matches; /* number of string matches in current block */
250 int last_eob_len; /* bit length of EOB code for last block */
251 250
252#ifdef DEBUG 251#ifdef DEBUG
253 ulg compressed_len; /* total bit length of compressed file mod 2^32 */ 252 ulg compressed_len; /* total bit length of compressed file mod 2^32 */
diff --git a/trees.c b/trees.c
index 23156ab..d5e1a56 100644
--- a/trees.c
+++ b/trees.c
@@ -394,7 +394,6 @@ void ZLIB_INTERNAL _tr_init(s)
394 394
395 s->bi_buf = 0; 395 s->bi_buf = 0;
396 s->bi_valid = 0; 396 s->bi_valid = 0;
397 s->last_eob_len = 8; /* enough lookahead for inflate */
398#ifdef DEBUG 397#ifdef DEBUG
399 s->compressed_len = 0L; 398 s->compressed_len = 0L;
400 s->bits_sent = 0L; 399 s->bits_sent = 0L;
@@ -880,13 +879,6 @@ void ZLIB_INTERNAL _tr_stored_block(s, buf, stored_len, last)
880/* =========================================================================== 879/* ===========================================================================
881 * Send one empty static block to give enough lookahead for inflate. 880 * Send one empty static block to give enough lookahead for inflate.
882 * This takes 10 bits, of which 7 may remain in the bit buffer. 881 * This takes 10 bits, of which 7 may remain in the bit buffer.
883 * The current inflate code requires 9 bits of lookahead. If the
884 * last two codes for the previous block (real code plus EOB) were coded
885 * on 5 bits or less, inflate may have only 5+3 bits of lookahead to decode
886 * the last real code. In this case we send two empty static blocks instead
887 * of one. (There are no problems if the previous block is stored or fixed.)
888 * To simplify the code, we assume the worst case of last real code encoded
889 * on one bit only.
890 */ 882 */
891void ZLIB_INTERNAL _tr_align(s) 883void ZLIB_INTERNAL _tr_align(s)
892 deflate_state *s; 884 deflate_state *s;
@@ -897,20 +889,6 @@ void ZLIB_INTERNAL _tr_align(s)
897 s->compressed_len += 10L; /* 3 for block type, 7 for EOB */ 889 s->compressed_len += 10L; /* 3 for block type, 7 for EOB */
898#endif 890#endif
899 bi_flush(s); 891 bi_flush(s);
900 /* Of the 10 bits for the empty block, we have already sent
901 * (10 - bi_valid) bits. The lookahead for the last real code (before
902 * the EOB of the previous block) was thus at least one plus the length
903 * of the EOB plus what we have just sent of the empty static block.
904 */
905 if (1 + s->last_eob_len + 10 - s->bi_valid < 9) {
906 send_bits(s, STATIC_TREES<<1, 3);
907 send_code(s, END_BLOCK, static_ltree);
908#ifdef DEBUG
909 s->compressed_len += 10L;
910#endif
911 bi_flush(s);
912 }
913 s->last_eob_len = 7;
914} 892}
915 893
916/* =========================================================================== 894/* ===========================================================================
@@ -1113,7 +1091,6 @@ local void compress_block(s, ltree, dtree)
1113 } while (lx < s->last_lit); 1091 } while (lx < s->last_lit);
1114 1092
1115 send_code(s, END_BLOCK, ltree); 1093 send_code(s, END_BLOCK, ltree);
1116 s->last_eob_len = ltree[END_BLOCK].Len;
1117} 1094}
1118 1095
1119/* =========================================================================== 1096/* ===========================================================================
@@ -1221,7 +1198,6 @@ local void copy_block(s, buf, len, header)
1221 int header; /* true if block header must be written */ 1198 int header; /* true if block header must be written */
1222{ 1199{
1223 bi_windup(s); /* align on byte boundary */ 1200 bi_windup(s); /* align on byte boundary */
1224 s->last_eob_len = 8; /* enough lookahead for inflate */
1225 1201
1226 if (header) { 1202 if (header) {
1227 put_short(s, (ush)len); 1203 put_short(s, (ush)len);