=========================================================================== * Same as above, but achieves better compression. We use a lazy * evaluation for matches: a match is finally adopted only if there is * no better match at the next window position. */
| 1727 | * no better match at the next window position. |
| 1728 | */ |
| 1729 | local block_state deflate_slow(deflate_state *s, int flush) |
| 1730 | { |
| 1731 | IPos hash_head; /* head of hash chain */ |
| 1732 | int bflush; /* set if current block must be flushed */ |
| 1733 | |
| 1734 | /* Process the input block. */ |
| 1735 | for (;;) { |
| 1736 | /* Make sure that we always have enough lookahead, except |
| 1737 | * at the end of the input file. We need MAX_MATCH bytes |
| 1738 | * for the next match, plus MIN_MATCH bytes to insert the |
| 1739 | * string following the next match. |
| 1740 | */ |
| 1741 | if (s->lookahead < MIN_LOOKAHEAD) { |
| 1742 | fill_window(s); |
| 1743 | if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) { |
| 1744 | return need_more; |
| 1745 | } |
| 1746 | if (s->lookahead == 0) break; /* flush the current block */ |
| 1747 | } |
| 1748 | |
| 1749 | /* Insert the string window[strstart .. strstart+2] in the |
| 1750 | * dictionary, and set hash_head to the head of the hash chain: |
| 1751 | */ |
| 1752 | hash_head = NIL; |
| 1753 | if (s->lookahead >= MIN_MATCH) { |
| 1754 | INSERT_STRING(s, s->strstart, hash_head); |
| 1755 | } |
| 1756 | |
| 1757 | if (flush == Z_INSERT_ONLY) { |
| 1758 | s->strstart++; |
| 1759 | s->lookahead--; |
| 1760 | continue; |
| 1761 | } |
| 1762 | |
| 1763 | /* Find the longest match, discarding those <= prev_length. |
| 1764 | */ |
| 1765 | s->prev_length = s->match_length, s->prev_match = s->match_start; |
| 1766 | s->match_length = MIN_MATCH-1; |
| 1767 | |
| 1768 | if (hash_head != NIL && s->prev_length < s->max_lazy_match && |
| 1769 | s->strstart - hash_head <= MAX_DIST(s)) { |
| 1770 | /* To simplify the code, we prevent matches with the string |
| 1771 | * of window index 0 (in particular we have to avoid a match |
| 1772 | * of the string with itself at the start of the input file). |
| 1773 | */ |
| 1774 | s->match_length = longest_match (s, hash_head); |
| 1775 | /* longest_match() sets match_start */ |
| 1776 | |
| 1777 | if (s->match_length <= 5 && (s->strategy == Z_FILTERED |
| 1778 | #if TOO_FAR <= 32767 |
| 1779 | || (s->match_length == MIN_MATCH && |
| 1780 | s->strstart - s->match_start > TOO_FAR) |
| 1781 | #endif |
| 1782 | )) { |
| 1783 | |
| 1784 | /* If prev_match is also MIN_MATCH, match_start is garbage |
| 1785 | * but we will ignore the current match anyway. |
| 1786 | */ |
nothing calls this directly
no test coverage detected