MCPcopy Create free account
hub / github.com/TruthHun/BookStack / deflate_slow

Function deflate_slow

static/word2md/mammoth.browser.js:18949–19103  ·  view source on GitHub ↗
(s, flush)

Source from the content-addressed store, hash-verified

18947 * no better match at the next window position.
18948 */
18949function deflate_slow(s, flush) {
18950 var hash_head; /* head of hash chain */
18951 var bflush; /* set if current block must be flushed */
18952
18953 var max_insert;
18954
18955 /* Process the input block. */
18956 for (;;) {
18957 /* Make sure that we always have enough lookahead, except
18958 * at the end of the input file. We need MAX_MATCH bytes
18959 * for the next match, plus MIN_MATCH bytes to insert the
18960 * string following the next match.
18961 */
18962 if (s.lookahead < MIN_LOOKAHEAD) {
18963 fill_window(s);
18964 if (s.lookahead < MIN_LOOKAHEAD && flush === Z_NO_FLUSH) {
18965 return BS_NEED_MORE;
18966 }
18967 if (s.lookahead === 0) { break; } /* flush the current block */
18968 }
18969
18970 /* Insert the string window[strstart .. strstart+2] in the
18971 * dictionary, and set hash_head to the head of the hash chain:
18972 */
18973 hash_head = 0/*NIL*/;
18974 if (s.lookahead >= MIN_MATCH) {
18975 /*** INSERT_STRING(s, s.strstart, hash_head); ***/
18976 s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[s.strstart + MIN_MATCH - 1]) & s.hash_mask;
18977 hash_head = s.prev[s.strstart & s.w_mask] = s.head[s.ins_h];
18978 s.head[s.ins_h] = s.strstart;
18979 /***/
18980 }
18981
18982 /* Find the longest match, discarding those <= prev_length.
18983 */
18984 s.prev_length = s.match_length;
18985 s.prev_match = s.match_start;
18986 s.match_length = MIN_MATCH - 1;
18987
18988 if (hash_head !== 0/*NIL*/ && s.prev_length < s.max_lazy_match &&
18989 s.strstart - hash_head <= (s.w_size - MIN_LOOKAHEAD)/*MAX_DIST(s)*/) {
18990 /* To simplify the code, we prevent matches with the string
18991 * of window index 0 (in particular we have to avoid a match
18992 * of the string with itself at the start of the input file).
18993 */
18994 s.match_length = longest_match(s, hash_head);
18995 /* longest_match() sets match_start */
18996
18997 if (s.match_length <= 5 &&
18998 (s.strategy === Z_FILTERED || (s.match_length === MIN_MATCH && s.strstart - s.match_start > 4096/*TOO_FAR*/))) {
18999
19000 /* If prev_match is also MIN_MATCH, match_start is garbage
19001 * but we will ignore the current match anyway.
19002 */
19003 s.match_length = MIN_MATCH - 1;
19004 }
19005 }
19006 /* If there was a match at the previous step and the current

Callers

nothing calls this directly

Calls 3

fill_windowFunction · 0.70
longest_matchFunction · 0.70
flush_block_onlyFunction · 0.70

Tested by

no test coverage detected