diff options
| author | Mark Adler <madler@alumni.caltech.edu> | 2011-12-29 00:03:55 -0800 |
|---|---|---|
| committer | Mark Adler <madler@alumni.caltech.edu> | 2011-12-29 00:03:55 -0800 |
| commit | 9d55abc96968db80749df5ebf412d36e2d66de26 (patch) | |
| tree | 2b422f40b006d947ce8f690641129bc8c95aef2b | |
| parent | f1ebdd6a9c495a5db9a22aa80dd7d54ae7db42e9 (diff) | |
| download | zlib-9d55abc96968db80749df5ebf412d36e2d66de26.tar.gz zlib-9d55abc96968db80749df5ebf412d36e2d66de26.tar.bz2 zlib-9d55abc96968db80749df5ebf412d36e2d66de26.zip | |
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.
| -rw-r--r-- | deflate.c | 45 |
1 files changed, 35 insertions, 10 deletions
| @@ -1571,8 +1571,13 @@ local block_state deflate_stored(s, flush) | |||
| 1571 | FLUSH_BLOCK(s, 0); | 1571 | FLUSH_BLOCK(s, 0); |
| 1572 | } | 1572 | } |
| 1573 | } | 1573 | } |
| 1574 | FLUSH_BLOCK(s, flush == Z_FINISH); | 1574 | if (flush == Z_FINISH) { |
| 1575 | return flush == Z_FINISH ? finish_done : block_done; | 1575 | FLUSH_BLOCK(s, 1); |
| 1576 | return finish_done; | ||
| 1577 | } | ||
| 1578 | if ((long)s->strstart > s->block_start) | ||
| 1579 | FLUSH_BLOCK(s, 0); | ||
| 1580 | return block_done; | ||
| 1576 | } | 1581 | } |
| 1577 | 1582 | ||
| 1578 | /* =========================================================================== | 1583 | /* =========================================================================== |
| @@ -1668,8 +1673,13 @@ local block_state deflate_fast(s, flush) | |||
| 1668 | } | 1673 | } |
| 1669 | if (bflush) FLUSH_BLOCK(s, 0); | 1674 | if (bflush) FLUSH_BLOCK(s, 0); |
| 1670 | } | 1675 | } |
| 1671 | FLUSH_BLOCK(s, flush == Z_FINISH); | 1676 | if (flush == Z_FINISH) { |
| 1672 | return flush == Z_FINISH ? finish_done : block_done; | 1677 | FLUSH_BLOCK(s, 1); |
| 1678 | return finish_done; | ||
| 1679 | } | ||
| 1680 | if (s->last_lit) | ||
| 1681 | FLUSH_BLOCK(s, 0); | ||
| 1682 | return block_done; | ||
| 1673 | } | 1683 | } |
| 1674 | 1684 | ||
| 1675 | #ifndef FASTEST | 1685 | #ifndef FASTEST |
| @@ -1793,8 +1803,13 @@ local block_state deflate_slow(s, flush) | |||
| 1793 | _tr_tally_lit(s, s->window[s->strstart-1], bflush); | 1803 | _tr_tally_lit(s, s->window[s->strstart-1], bflush); |
| 1794 | s->match_available = 0; | 1804 | s->match_available = 0; |
| 1795 | } | 1805 | } |
| 1796 | FLUSH_BLOCK(s, flush == Z_FINISH); | 1806 | if (flush == Z_FINISH) { |
| 1797 | return flush == Z_FINISH ? finish_done : block_done; | 1807 | FLUSH_BLOCK(s, 1); |
| 1808 | return finish_done; | ||
| 1809 | } | ||
| 1810 | if (s->last_lit) | ||
| 1811 | FLUSH_BLOCK(s, 0); | ||
| 1812 | return block_done; | ||
| 1798 | } | 1813 | } |
| 1799 | #endif /* FASTEST */ | 1814 | #endif /* FASTEST */ |
| 1800 | 1815 | ||
| @@ -1862,8 +1877,13 @@ local block_state deflate_rle(s, flush) | |||
| 1862 | } | 1877 | } |
| 1863 | if (bflush) FLUSH_BLOCK(s, 0); | 1878 | if (bflush) FLUSH_BLOCK(s, 0); |
| 1864 | } | 1879 | } |
| 1865 | FLUSH_BLOCK(s, flush == Z_FINISH); | 1880 | if (flush == Z_FINISH) { |
| 1866 | return flush == Z_FINISH ? finish_done : block_done; | 1881 | FLUSH_BLOCK(s, 1); |
| 1882 | return finish_done; | ||
| 1883 | } | ||
| 1884 | if (s->last_lit) | ||
| 1885 | FLUSH_BLOCK(s, 0); | ||
| 1886 | return block_done; | ||
| 1867 | } | 1887 | } |
| 1868 | 1888 | ||
| 1869 | /* =========================================================================== | 1889 | /* =========================================================================== |
| @@ -1895,6 +1915,11 @@ local block_state deflate_huff(s, flush) | |||
| 1895 | s->strstart++; | 1915 | s->strstart++; |
| 1896 | if (bflush) FLUSH_BLOCK(s, 0); | 1916 | if (bflush) FLUSH_BLOCK(s, 0); |
| 1897 | } | 1917 | } |
| 1898 | FLUSH_BLOCK(s, flush == Z_FINISH); | 1918 | if (flush == Z_FINISH) { |
| 1899 | return flush == Z_FINISH ? finish_done : block_done; | 1919 | FLUSH_BLOCK(s, 1); |
| 1920 | return finish_done; | ||
| 1921 | } | ||
| 1922 | if (s->last_lit) | ||
| 1923 | FLUSH_BLOCK(s, 0); | ||
| 1924 | return block_done; | ||
| 1900 | } | 1925 | } |
