MCPcopy Create free account
hub / github.com/ObEngine/ObEngine / deflate_slow

Function deflate_slow

extlibs/minizip/src/deflate.c:2078–2218  ·  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

2076 * no better match at the next window position.
2077 */
2078local block_state deflate_slow(s, flush)
2079deflate_state* s;
2080
2081int flush;
2082{
2083 IPos hash_head; /* head of hash chain */
2084 int bflush; /* set if current block must be flushed */
2085
2086 /* Process the input block. */
2087 for (;;)
2088 {
2089 /* Make sure that we always have enough lookahead, except
2090 * at the end of the input file. We need MAX_MATCH bytes
2091 * for the next match, plus MIN_MATCH bytes to insert the
2092 * string following the next match.
2093 */
2094 if (s->lookahead < MIN_LOOKAHEAD)
2095 {
2096 fill_window(s);
2097 if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH)
2098 {
2099 return need_more;
2100 }
2101 if (s->lookahead == 0) break; /* flush the current block */
2102 }
2103
2104 /* Insert the string window[strstart .. strstart+2] in the
2105 * dictionary, and set hash_head to the head of the hash chain:
2106 */
2107 hash_head = NIL;
2108 if (s->lookahead >= MIN_MATCH)
2109 {
2110 INSERT_STRING(s, s->strstart, hash_head);
2111 }
2112
2113 /* Find the longest match, discarding those <= prev_length.
2114 */
2115 s->prev_length = s->match_length , s->prev_match = s->match_start;
2116 s->match_length = MIN_MATCH - 1;
2117
2118 if (hash_head != NIL && s->prev_length < s->max_lazy_match &&
2119 s->strstart - hash_head <= MAX_DIST(s))
2120 {
2121 /* To simplify the code, we prevent matches with the string
2122 * of window index 0 (in particular we have to avoid a match
2123 * of the string with itself at the start of the input file).
2124 */
2125 s->match_length = longest_match(s, hash_head);
2126 /* longest_match() sets match_start */
2127
2128 if (s->match_length <= 5 && (s->strategy == Z_FILTERED
2129#if TOO_FAR <= 32767
2130 || (s->match_length == MIN_MATCH &&
2131 s->strstart - s->match_start > TOO_FAR)
2132#endif
2133 ))
2134 {
2135 /* If prev_match is also MIN_MATCH, match_start is garbage

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