=========================================================================== * 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. */
(s, flush)
| 1959 | * matches. It is used only for the fast compression options. |
| 1960 | */ |
| 1961 | local block_state deflate_fast(s, flush) |
| 1962 | deflate_state* s; |
| 1963 | |
| 1964 | int flush; |
| 1965 | { |
| 1966 | IPos hash_head; /* head of the hash chain */ |
| 1967 | int bflush; /* set if current block must be flushed */ |
| 1968 | |
| 1969 | for (;;) |
| 1970 | { |
| 1971 | /* Make sure that we always have enough lookahead, except |
| 1972 | * at the end of the input file. We need MAX_MATCH bytes |
| 1973 | * for the next match, plus MIN_MATCH bytes to insert the |
| 1974 | * string following the next match. |
| 1975 | */ |
| 1976 | if (s->lookahead < MIN_LOOKAHEAD) |
| 1977 | { |
| 1978 | fill_window(s); |
| 1979 | if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) |
| 1980 | { |
| 1981 | return need_more; |
| 1982 | } |
| 1983 | if (s->lookahead == 0) break; /* flush the current block */ |
| 1984 | } |
| 1985 | |
| 1986 | /* Insert the string window[strstart .. strstart+2] in the |
| 1987 | * dictionary, and set hash_head to the head of the hash chain: |
| 1988 | */ |
| 1989 | hash_head = NIL; |
| 1990 | if (s->lookahead >= MIN_MATCH) |
| 1991 | { |
| 1992 | INSERT_STRING(s, s->strstart, hash_head); |
| 1993 | } |
| 1994 | |
| 1995 | /* Find the longest match, discarding those <= prev_length. |
| 1996 | * At this point we have always match_length < MIN_MATCH |
| 1997 | */ |
| 1998 | if (hash_head != NIL && s->strstart - hash_head <= MAX_DIST(s)) |
| 1999 | { |
| 2000 | /* To simplify the code, we prevent matches with the string |
| 2001 | * of window index 0 (in particular we have to avoid a match |
| 2002 | * of the string with itself at the start of the input file). |
| 2003 | */ |
| 2004 | s->match_length = longest_match(s, hash_head); |
| 2005 | /* longest_match() sets match_start */ |
| 2006 | } |
| 2007 | if (s->match_length >= MIN_MATCH) |
| 2008 | { |
| 2009 | check_match(s, s->strstart, s->match_start, s->match_length); |
| 2010 | |
| 2011 | _tr_tally_dist(s, s->strstart - s->match_start, |
| 2012 | s->match_length - MIN_MATCH, bflush); |
| 2013 | |
| 2014 | s->lookahead -= s->match_length; |
| 2015 | |
| 2016 | /* Insert new strings in the hash table only if the match length |
| 2017 | * is not too large. This saves time but degrades compression. |
| 2018 | */ |
nothing calls this directly
no test coverage detected