=========================================================================== * Compress as much as possible from the input stream, return the current * block state. * This function does not perform lazy evaluation of matches and inserts * new strings in the dictionary only for unmatched strings or for short * matches. It is used only for the fast compression options. */
| 1809 | * matches. It is used only for the fast compression options. |
| 1810 | */ |
| 1811 | local block_state deflate_fast(deflate_state *s, int flush) { |
| 1812 | IPos hash_head; /* head of the hash chain */ |
| 1813 | int bflush; /* set if current block must be flushed */ |
| 1814 | |
| 1815 | for (;;) { |
| 1816 | /* Make sure that we always have enough lookahead, except |
| 1817 | * at the end of the input file. We need MAX_MATCH bytes |
| 1818 | * for the next match, plus MIN_MATCH bytes to insert the |
| 1819 | * string following the next match. |
| 1820 | */ |
| 1821 | if (s->lookahead < MIN_LOOKAHEAD) { |
| 1822 | fill_window(s); |
| 1823 | if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) { |
| 1824 | return need_more; |
| 1825 | } |
| 1826 | if (s->lookahead == 0) break; /* flush the current block */ |
| 1827 | } |
| 1828 | |
| 1829 | /* Insert the string window[strstart .. strstart + 2] in the |
| 1830 | * dictionary, and set hash_head to the head of the hash chain: |
| 1831 | */ |
| 1832 | hash_head = NIL; |
| 1833 | if (s->lookahead >= MIN_MATCH) { |
| 1834 | INSERT_STRING(s, s->strstart, hash_head); |
| 1835 | } |
| 1836 | |
| 1837 | /* Find the longest match, discarding those <= prev_length. |
| 1838 | * At this point we have always match_length < MIN_MATCH |
| 1839 | */ |
| 1840 | if (hash_head != NIL && s->strstart - hash_head <= MAX_DIST(s)) { |
| 1841 | /* To simplify the code, we prevent matches with the string |
| 1842 | * of window index 0 (in particular we have to avoid a match |
| 1843 | * of the string with itself at the start of the input file). |
| 1844 | */ |
| 1845 | s->match_length = longest_match (s, hash_head); |
| 1846 | /* longest_match() sets match_start */ |
| 1847 | } |
| 1848 | if (s->match_length >= MIN_MATCH) { |
| 1849 | check_match(s, s->strstart, s->match_start, s->match_length); |
| 1850 | |
| 1851 | _tr_tally_dist(s, s->strstart - s->match_start, |
| 1852 | s->match_length - MIN_MATCH, bflush); |
| 1853 | |
| 1854 | s->lookahead -= s->match_length; |
| 1855 | |
| 1856 | /* Insert new strings in the hash table only if the match length |
| 1857 | * is not too large. This saves time but degrades compression. |
| 1858 | */ |
| 1859 | #ifndef FASTEST |
| 1860 | if (s->match_length <= s->max_insert_length && |
| 1861 | s->lookahead >= MIN_MATCH) { |
| 1862 | s->match_length--; /* string at strstart already in table */ |
| 1863 | do { |
| 1864 | s->strstart++; |
| 1865 | INSERT_STRING(s, s->strstart, hash_head); |
| 1866 | /* strstart never exceeds WSIZE-MAX_MATCH, so there are |
| 1867 | * always MIN_MATCH bytes ahead. |
| 1868 | */ |
nothing calls this directly
no test coverage detected