MCPcopy Create free account
hub / github.com/F-Stack/f-stack / deflate_slow

Function deflate_slow

freebsd/contrib/zlib/deflate.c:1931–2054  ·  view source on GitHub ↗

=========================================================================== * 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. */

(s, flush)

Source from the content-addressed store, hash-verified

1929 * no better match at the next window position.
1930 */
1931local block_state deflate_slow(s, flush)
1932 deflate_state *s;
1933 int flush;
1934{
1935 IPos hash_head; /* head of hash chain */
1936 int bflush; /* set if current block must be flushed */
1937
1938 /* Process the input block. */
1939 for (;;) {
1940 /* Make sure that we always have enough lookahead, except
1941 * at the end of the input file. We need MAX_MATCH bytes
1942 * for the next match, plus MIN_MATCH bytes to insert the
1943 * string following the next match.
1944 */
1945 if (s->lookahead < MIN_LOOKAHEAD) {
1946 fill_window(s);
1947 if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
1948 return need_more;
1949 }
1950 if (s->lookahead == 0) break; /* flush the current block */
1951 }
1952
1953 /* Insert the string window[strstart .. strstart+2] in the
1954 * dictionary, and set hash_head to the head of the hash chain:
1955 */
1956 hash_head = NIL;
1957 if (s->lookahead >= MIN_MATCH) {
1958 INSERT_STRING(s, s->strstart, hash_head);
1959 }
1960
1961 /* Find the longest match, discarding those <= prev_length.
1962 */
1963 s->prev_length = s->match_length, s->prev_match = s->match_start;
1964 s->match_length = MIN_MATCH-1;
1965
1966 if (hash_head != NIL && s->prev_length < s->max_lazy_match &&
1967 s->strstart - hash_head <= MAX_DIST(s)) {
1968 /* To simplify the code, we prevent matches with the string
1969 * of window index 0 (in particular we have to avoid a match
1970 * of the string with itself at the start of the input file).
1971 */
1972 s->match_length = longest_match (s, hash_head);
1973 /* longest_match() sets match_start */
1974
1975 if (s->match_length <= 5 && (s->strategy == Z_FILTERED
1976#if TOO_FAR <= 32767
1977 || (s->match_length == MIN_MATCH &&
1978 s->strstart - s->match_start > TOO_FAR)
1979#endif
1980 )) {
1981
1982 /* If prev_match is also MIN_MATCH, match_start is garbage
1983 * but we will ignore the current match anyway.
1984 */
1985 s->match_length = MIN_MATCH-1;
1986 }
1987 }
1988 /* If there was a match at the previous step and the current

Callers

nothing calls this directly

Calls 3

fill_windowFunction · 0.85
longest_matchFunction · 0.85
check_matchFunction · 0.70

Tested by

no test coverage detected