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

Function deflate_fast

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

Source from the content-addressed store, hash-verified

18819 * matches. It is used only for the fast compression options.
18820 */
18821function deflate_fast(s, flush) {
18822 var hash_head; /* head of the hash chain */
18823 var bflush; /* set if current block must be flushed */
18824
18825 for (;;) {
18826 /* Make sure that we always have enough lookahead, except
18827 * at the end of the input file. We need MAX_MATCH bytes
18828 * for the next match, plus MIN_MATCH bytes to insert the
18829 * string following the next match.
18830 */
18831 if (s.lookahead < MIN_LOOKAHEAD) {
18832 fill_window(s);
18833 if (s.lookahead < MIN_LOOKAHEAD && flush === Z_NO_FLUSH) {
18834 return BS_NEED_MORE;
18835 }
18836 if (s.lookahead === 0) {
18837 break; /* flush the current block */
18838 }
18839 }
18840
18841 /* Insert the string window[strstart .. strstart+2] in the
18842 * dictionary, and set hash_head to the head of the hash chain:
18843 */
18844 hash_head = 0/*NIL*/;
18845 if (s.lookahead >= MIN_MATCH) {
18846 /*** INSERT_STRING(s, s.strstart, hash_head); ***/
18847 s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[s.strstart + MIN_MATCH - 1]) & s.hash_mask;
18848 hash_head = s.prev[s.strstart & s.w_mask] = s.head[s.ins_h];
18849 s.head[s.ins_h] = s.strstart;
18850 /***/
18851 }
18852
18853 /* Find the longest match, discarding those <= prev_length.
18854 * At this point we have always match_length < MIN_MATCH
18855 */
18856 if (hash_head !== 0/*NIL*/ && ((s.strstart - hash_head) <= (s.w_size - MIN_LOOKAHEAD))) {
18857 /* To simplify the code, we prevent matches with the string
18858 * of window index 0 (in particular we have to avoid a match
18859 * of the string with itself at the start of the input file).
18860 */
18861 s.match_length = longest_match(s, hash_head);
18862 /* longest_match() sets match_start */
18863 }
18864 if (s.match_length >= MIN_MATCH) {
18865 // check_match(s, s.strstart, s.match_start, s.match_length); // for debug only
18866
18867 /*** _tr_tally_dist(s, s.strstart - s.match_start,
18868 s.match_length - MIN_MATCH, bflush); ***/
18869 bflush = trees._tr_tally(s, s.strstart - s.match_start, s.match_length - MIN_MATCH);
18870
18871 s.lookahead -= s.match_length;
18872
18873 /* Insert new strings in the hash table only if the match length
18874 * is not too large. This saves time but degrades compression.
18875 */
18876 if (s.match_length <= s.max_lazy_match/*max_insert_length*/ && s.lookahead >= MIN_MATCH) {
18877 s.match_length--; /* string at strstart already in table */
18878 do {

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