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

Function longest_match

static/word2md/mammoth.browser.js:18454–18554  ·  view source on GitHub ↗
(s, cur_match)

Source from the content-addressed store, hash-verified

18452 * OUT assertion: the match length is not greater than s->lookahead.
18453 */
18454function longest_match(s, cur_match) {
18455 var chain_length = s.max_chain_length; /* max hash chain length */
18456 var scan = s.strstart; /* current string */
18457 var match; /* matched string */
18458 var len; /* length of current match */
18459 var best_len = s.prev_length; /* best match length so far */
18460 var nice_match = s.nice_match; /* stop if match long enough */
18461 var limit = (s.strstart > (s.w_size - MIN_LOOKAHEAD)) ?
18462 s.strstart - (s.w_size - MIN_LOOKAHEAD) : 0/*NIL*/;
18463
18464 var _win = s.window; // shortcut
18465
18466 var wmask = s.w_mask;
18467 var prev = s.prev;
18468
18469 /* Stop when cur_match becomes <= limit. To simplify the code,
18470 * we prevent matches with the string of window index 0.
18471 */
18472
18473 var strend = s.strstart + MAX_MATCH;
18474 var scan_end1 = _win[scan + best_len - 1];
18475 var scan_end = _win[scan + best_len];
18476
18477 /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16.
18478 * It is easy to get rid of this optimization if necessary.
18479 */
18480 // Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
18481
18482 /* Do not waste too much time if we already have a good match: */
18483 if (s.prev_length >= s.good_match) {
18484 chain_length >>= 2;
18485 }
18486 /* Do not look for matches beyond the end of the input. This is necessary
18487 * to make deflate deterministic.
18488 */
18489 if (nice_match > s.lookahead) { nice_match = s.lookahead; }
18490
18491 // Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
18492
18493 do {
18494 // Assert(cur_match < s->strstart, "no future");
18495 match = cur_match;
18496
18497 /* Skip to next match if the match length cannot increase
18498 * or if the match length is less than 2. Note that the checks below
18499 * for insufficient lookahead only occur occasionally for performance
18500 * reasons. Therefore uninitialized memory will be accessed, and
18501 * conditional jumps will be made that depend on those values.
18502 * However the length of the match is limited to the lookahead, so
18503 * the output of deflate is not affected by the uninitialized values.
18504 */
18505
18506 if (_win[match + best_len] !== scan_end ||
18507 _win[match + best_len - 1] !== scan_end1 ||
18508 _win[match] !== _win[scan] ||
18509 _win[++match] !== _win[scan + 1]) {
18510 continue;
18511 }

Callers 2

deflate_fastFunction · 0.70
deflate_slowFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected