MCPcopy Create free account
hub / github.com/hoothin/UserScripts / deflate_slow

Function deflate_slow

Picviewer CE+/dist.user.js:6859–7013  ·  view source on GitHub ↗
(s, flush)

Source from the content-addressed store, hash-verified

6857 * no better match at the next window position.
6858 */
6859function deflate_slow(s, flush) {
6860 var hash_head; /* head of hash chain */
6861 var bflush; /* set if current block must be flushed */
6862
6863 var max_insert;
6864
6865 /* Process the input block. */
6866 for (;;) {
6867 /* Make sure that we always have enough lookahead, except
6868 * at the end of the input file. We need MAX_MATCH bytes
6869 * for the next match, plus MIN_MATCH bytes to insert the
6870 * string following the next match.
6871 */
6872 if (s.lookahead < MIN_LOOKAHEAD) {
6873 fill_window(s);
6874 if (s.lookahead < MIN_LOOKAHEAD && flush === Z_NO_FLUSH) {
6875 return BS_NEED_MORE;
6876 }
6877 if (s.lookahead === 0) { break; } /* flush the current block */
6878 }
6879
6880 /* Insert the string window[strstart .. strstart+2] in the
6881 * dictionary, and set hash_head to the head of the hash chain:
6882 */
6883 hash_head = 0/*NIL*/;
6884 if (s.lookahead >= MIN_MATCH) {
6885 /*** INSERT_STRING(s, s.strstart, hash_head); ***/
6886 s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[s.strstart + MIN_MATCH - 1]) & s.hash_mask;
6887 hash_head = s.prev[s.strstart & s.w_mask] = s.head[s.ins_h];
6888 s.head[s.ins_h] = s.strstart;
6889 /***/
6890 }
6891
6892 /* Find the longest match, discarding those <= prev_length.
6893 */
6894 s.prev_length = s.match_length;
6895 s.prev_match = s.match_start;
6896 s.match_length = MIN_MATCH - 1;
6897
6898 if (hash_head !== 0/*NIL*/ && s.prev_length < s.max_lazy_match &&
6899 s.strstart - hash_head <= (s.w_size - MIN_LOOKAHEAD)/*MAX_DIST(s)*/) {
6900 /* To simplify the code, we prevent matches with the string
6901 * of window index 0 (in particular we have to avoid a match
6902 * of the string with itself at the start of the input file).
6903 */
6904 s.match_length = longest_match(s, hash_head);
6905 /* longest_match() sets match_start */
6906
6907 if (s.match_length <= 5 &&
6908 (s.strategy === Z_FILTERED || (s.match_length === MIN_MATCH && s.strstart - s.match_start > 4096/*TOO_FAR*/))) {
6909
6910 /* If prev_match is also MIN_MATCH, match_start is garbage
6911 * but we will ignore the current match anyway.
6912 */
6913 s.match_length = MIN_MATCH - 1;
6914 }
6915 }
6916 /* 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