Avoid extraneous empty blocks when doing empty flushes.

Previously when doing an empty flush, a extra static or stored block
could be emitted before the requested empty static or stored block.
This patch prevents the emission of empty blocks by the deflate_*
functions.
This commit is contained in:
Mark Adler 2011-12-29 00:03:55 -08:00
parent f1ebdd6a9c
commit 9d55abc969

View File

@ -1571,8 +1571,13 @@ local block_state deflate_stored(s, flush)
FLUSH_BLOCK(s, 0); FLUSH_BLOCK(s, 0);
} }
} }
FLUSH_BLOCK(s, flush == Z_FINISH); if (flush == Z_FINISH) {
return flush == Z_FINISH ? finish_done : block_done; FLUSH_BLOCK(s, 1);
return finish_done;
}
if ((long)s->strstart > s->block_start)
FLUSH_BLOCK(s, 0);
return block_done;
} }
/* =========================================================================== /* ===========================================================================
@ -1668,8 +1673,13 @@ local block_state deflate_fast(s, flush)
} }
if (bflush) FLUSH_BLOCK(s, 0); if (bflush) FLUSH_BLOCK(s, 0);
} }
FLUSH_BLOCK(s, flush == Z_FINISH); if (flush == Z_FINISH) {
return flush == Z_FINISH ? finish_done : block_done; FLUSH_BLOCK(s, 1);
return finish_done;
}
if (s->last_lit)
FLUSH_BLOCK(s, 0);
return block_done;
} }
#ifndef FASTEST #ifndef FASTEST
@ -1793,8 +1803,13 @@ local block_state deflate_slow(s, flush)
_tr_tally_lit(s, s->window[s->strstart-1], bflush); _tr_tally_lit(s, s->window[s->strstart-1], bflush);
s->match_available = 0; s->match_available = 0;
} }
FLUSH_BLOCK(s, flush == Z_FINISH); if (flush == Z_FINISH) {
return flush == Z_FINISH ? finish_done : block_done; FLUSH_BLOCK(s, 1);
return finish_done;
}
if (s->last_lit)
FLUSH_BLOCK(s, 0);
return block_done;
} }
#endif /* FASTEST */ #endif /* FASTEST */
@ -1862,8 +1877,13 @@ local block_state deflate_rle(s, flush)
} }
if (bflush) FLUSH_BLOCK(s, 0); if (bflush) FLUSH_BLOCK(s, 0);
} }
FLUSH_BLOCK(s, flush == Z_FINISH); if (flush == Z_FINISH) {
return flush == Z_FINISH ? finish_done : block_done; FLUSH_BLOCK(s, 1);
return finish_done;
}
if (s->last_lit)
FLUSH_BLOCK(s, 0);
return block_done;
} }
/* =========================================================================== /* ===========================================================================
@ -1895,6 +1915,11 @@ local block_state deflate_huff(s, flush)
s->strstart++; s->strstart++;
if (bflush) FLUSH_BLOCK(s, 0); if (bflush) FLUSH_BLOCK(s, 0);
} }
FLUSH_BLOCK(s, flush == Z_FINISH); if (flush == Z_FINISH) {
return flush == Z_FINISH ? finish_done : block_done; FLUSH_BLOCK(s, 1);
return finish_done;
}
if (s->last_lit)
FLUSH_BLOCK(s, 0);
return block_done;
} }