(s, cur_match)
| 6362 | * OUT assertion: the match length is not greater than s->lookahead. |
| 6363 | */ |
| 6364 | function longest_match(s, cur_match) { |
| 6365 | var chain_length = s.max_chain_length; /* max hash chain length */ |
| 6366 | var scan = s.strstart; /* current string */ |
| 6367 | var match; /* matched string */ |
| 6368 | var len; /* length of current match */ |
| 6369 | var best_len = s.prev_length; /* best match length so far */ |
| 6370 | var nice_match = s.nice_match; /* stop if match long enough */ |
| 6371 | var limit = (s.strstart > (s.w_size - MIN_LOOKAHEAD)) ? |
| 6372 | s.strstart - (s.w_size - MIN_LOOKAHEAD) : 0/*NIL*/; |
| 6373 | |
| 6374 | var _win = s.window; // shortcut |
| 6375 | |
| 6376 | var wmask = s.w_mask; |
| 6377 | var prev = s.prev; |
| 6378 | |
| 6379 | /* Stop when cur_match becomes <= limit. To simplify the code, |
| 6380 | * we prevent matches with the string of window index 0. |
| 6381 | */ |
| 6382 | |
| 6383 | var strend = s.strstart + MAX_MATCH; |
| 6384 | var scan_end1 = _win[scan + best_len - 1]; |
| 6385 | var scan_end = _win[scan + best_len]; |
| 6386 | |
| 6387 | /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16. |
| 6388 | * It is easy to get rid of this optimization if necessary. |
| 6389 | */ |
| 6390 | // Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever"); |
| 6391 | |
| 6392 | /* Do not waste too much time if we already have a good match: */ |
| 6393 | if (s.prev_length >= s.good_match) { |
| 6394 | chain_length >>= 2; |
| 6395 | } |
| 6396 | /* Do not look for matches beyond the end of the input. This is necessary |
| 6397 | * to make deflate deterministic. |
| 6398 | */ |
| 6399 | if (nice_match > s.lookahead) { nice_match = s.lookahead; } |
| 6400 | |
| 6401 | // Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead"); |
| 6402 | |
| 6403 | do { |
| 6404 | // Assert(cur_match < s->strstart, "no future"); |
| 6405 | match = cur_match; |
| 6406 | |
| 6407 | /* Skip to next match if the match length cannot increase |
| 6408 | * or if the match length is less than 2. Note that the checks below |
| 6409 | * for insufficient lookahead only occur occasionally for performance |
| 6410 | * reasons. Therefore uninitialized memory will be accessed, and |
| 6411 | * conditional jumps will be made that depend on those values. |
| 6412 | * However the length of the match is limited to the lookahead, so |
| 6413 | * the output of deflate is not affected by the uninitialized values. |
| 6414 | */ |
| 6415 | |
| 6416 | if (_win[match + best_len] !== scan_end || |
| 6417 | _win[match + best_len - 1] !== scan_end1 || |
| 6418 | _win[match] !== _win[scan] || |
| 6419 | _win[++match] !== _win[scan + 1]) { |
| 6420 | continue; |
| 6421 | } |
no outgoing calls
no test coverage detected