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

Function deflate_fast

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

Source from the content-addressed store, hash-verified

6729 * matches. It is used only for the fast compression options.
6730 */
6731function deflate_fast(s, flush) {
6732 var hash_head; /* head of the hash chain */
6733 var bflush; /* set if current block must be flushed */
6734
6735 for (;;) {
6736 /* Make sure that we always have enough lookahead, except
6737 * at the end of the input file. We need MAX_MATCH bytes
6738 * for the next match, plus MIN_MATCH bytes to insert the
6739 * string following the next match.
6740 */
6741 if (s.lookahead < MIN_LOOKAHEAD) {
6742 fill_window(s);
6743 if (s.lookahead < MIN_LOOKAHEAD && flush === Z_NO_FLUSH) {
6744 return BS_NEED_MORE;
6745 }
6746 if (s.lookahead === 0) {
6747 break; /* flush the current block */
6748 }
6749 }
6750
6751 /* Insert the string window[strstart .. strstart+2] in the
6752 * dictionary, and set hash_head to the head of the hash chain:
6753 */
6754 hash_head = 0/*NIL*/;
6755 if (s.lookahead >= MIN_MATCH) {
6756 /*** INSERT_STRING(s, s.strstart, hash_head); ***/
6757 s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[s.strstart + MIN_MATCH - 1]) & s.hash_mask;
6758 hash_head = s.prev[s.strstart & s.w_mask] = s.head[s.ins_h];
6759 s.head[s.ins_h] = s.strstart;
6760 /***/
6761 }
6762
6763 /* Find the longest match, discarding those <= prev_length.
6764 * At this point we have always match_length < MIN_MATCH
6765 */
6766 if (hash_head !== 0/*NIL*/ && ((s.strstart - hash_head) <= (s.w_size - MIN_LOOKAHEAD))) {
6767 /* To simplify the code, we prevent matches with the string
6768 * of window index 0 (in particular we have to avoid a match
6769 * of the string with itself at the start of the input file).
6770 */
6771 s.match_length = longest_match(s, hash_head);
6772 /* longest_match() sets match_start */
6773 }
6774 if (s.match_length >= MIN_MATCH) {
6775 // check_match(s, s.strstart, s.match_start, s.match_length); // for debug only
6776
6777 /*** _tr_tally_dist(s, s.strstart - s.match_start,
6778 s.match_length - MIN_MATCH, bflush); ***/
6779 bflush = trees._tr_tally(s, s.strstart - s.match_start, s.match_length - MIN_MATCH);
6780
6781 s.lookahead -= s.match_length;
6782
6783 /* Insert new strings in the hash table only if the match length
6784 * is not too large. This saves time but degrades compression.
6785 */
6786 if (s.match_length <= s.max_lazy_match/*max_insert_length*/ && s.lookahead >= MIN_MATCH) {
6787 s.match_length--; /* string at strstart already in table */
6788 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