function longest_match(s, cur_match) {
  let chain_length = s.max_chain_length; /* max hash chain length */
  let scan = s.strstart; /* current string */
  let match; /* matched string */
  let len; /* length of current match */
  let best_len = s.prev_length; /* best match length so far */
  let nice_match = s.nice_match; /* stop if match long enough */
  let limit = s.strstart > s.w_size - MIN_LOOKAHEAD
    ? s.strstart - (s.w_size - MIN_LOOKAHEAD)
    : 0 /*NIL*/;
  let _win = s.window; // shortcut
  let wmask = s.w_mask;
  let prev = s.prev;
  /* Stop when cur_match becomes <= limit. To simplify the code,
   * we prevent matches with the string of window index 0.
   */ let strend = s.strstart + MAX_MATCH;
  let scan_end1 = _win[scan + best_len - 1];
  let scan_end = _win[scan + best_len];
  /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16.
   * It is easy to get rid of this optimization if necessary.
   */
  // Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
  /* Do not waste too much time if we already have a good match: */ if (
    s.prev_length >= s.good_match
  ) {
    chain_length >>= 2;
  }
  /* Do not look for matches beyond the end of the input. This is necessary
   * to make deflate deterministic.
   */ if (nice_match > s.lookahead) nice_match = s.lookahead;
  // Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
  do {
    // Assert(cur_match < s->strstart, "no future");
    match = cur_match;
    /* Skip to next match if the match length cannot increase
     * or if the match length is less than 2.  Note that the checks below
     * for insufficient lookahead only occur occasionally for performance
     * reasons.  Therefore uninitialized memory will be accessed, and
     * conditional jumps will be made that depend on those values.
     * However the length of the match is limited to the lookahead, so
     * the output of deflate is not affected by the uninitialized values.
     */ if (
      _win[match + best_len] !== scan_end ||
      _win[match + best_len - 1] !== scan_end1 || _win[match] !== _win[scan] ||
      _win[++match] !== _win[scan + 1]
    ) {
      continue;
    }
    /* The check at best_len-1 can be removed because it will be made
     * again later. (This heuristic is not always a win.)
     * It is not necessary to compare scan[2] and match[2] since they
     * are always equal when the other bytes match, given that
     * the hash keys are equal and that HASH_BITS >= 8.
     */ scan += 2;
    match++;
    // Assert(*scan == *match, "match[2]?");
    /* We check for insufficient lookahead only every 8th comparison;
     * the 256th check will be made at strstart+258.
     */ do {
      /*jshint noempty:false*/
    } while (
      _win[++scan] === _win[++match] && _win[++scan] === _win[++match] &&
      _win[++scan] === _win[++match] && _win[++scan] === _win[++match] &&
      _win[++scan] === _win[++match] && _win[++scan] === _win[++match] &&
      _win[++scan] === _win[++match] && _win[++scan] === _win[++match] &&
      scan < strend
    );
    // Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
    len = MAX_MATCH - (strend - scan);
    scan = strend - MAX_MATCH;
    if (len > best_len) {
      s.match_start = cur_match;
      best_len = len;
      if (len >= nice_match) {
        break;
      }
      scan_end1 = _win[scan + best_len - 1];
      scan_end = _win[scan + best_len];
    }
  } while (
    (cur_match = prev[cur_match & wmask]) > limit && (--chain_length) !== 0
  );
  if (best_len <= s.lookahead) {
    return best_len;
  }
  return s.lookahead;
}
/* ===========================================================================
 * Set match_start to the longest match starting at the given string and
 * return its length. Matches shorter or equal to prev_length are discarded,
 * in which case the result is equal to prev_length and match_start is
 * garbage.
 * IN assertions: cur_match is the head of the hash chain for the current
 *   string (strstart) and its distance is <= MAX_DIST, and prev_length >= 1
 * OUT assertion: the match length is not greater than s->lookahead.
 */
Set match_start to the longest match starting at the given string and
return its length. Matches shorter or equal to prev_length are discarded,
in which case the result is equal to prev_length and match_start is
garbage.
IN assertions: cur_match is the head of the hash chain for the current
string (strstart) and its distance is <= MAX_DIST, and prev_length >= 1
OUT assertion: the match length is not greater than s->lookahead.
Set match_start to the longest match starting at the given string and return its length . Matches shorter or equal to prev_length are discarded in which case the result is equal to prev_length and match_start is garbage . IN assertions : cur_match is the head of the hash chain for the current string ( strstart ) and its distance is < = MAX_DIST and prev_length > = 1 OUT assertion : the match length is not greater than s - > lookahead .
function longest_match(s, cur_match) {
  let chain_length = s.max_chain_length; 
  let scan = s.strstart; 
  let match; 
  let len; 
  let best_len = s.prev_length; 
  let nice_match = s.nice_match; 
  let limit = s.strstart > s.w_size - MIN_LOOKAHEAD
    ? s.strstart - (s.w_size - MIN_LOOKAHEAD)
    : 0 ;
  let _win = s.window; 
  let wmask = s.w_mask;
  let prev = s.prev;
   let strend = s.strstart + MAX_MATCH;
  let scan_end1 = _win[scan + best_len - 1];
  let scan_end = _win[scan + best_len];
   if (
    s.prev_length >= s.good_match
  ) {
    chain_length >>= 2;
  }
   if (nice_match > s.lookahead) nice_match = s.lookahead;
  do {
    match = cur_match;
     if (
      _win[match + best_len] !== scan_end ||
      _win[match + best_len - 1] !== scan_end1 || _win[match] !== _win[scan] ||
      _win[++match] !== _win[scan + 1]
    ) {
      continue;
    }
     scan += 2;
    match++;
     do {
    } while (
      _win[++scan] === _win[++match] && _win[++scan] === _win[++match] &&
      _win[++scan] === _win[++match] && _win[++scan] === _win[++match] &&
      _win[++scan] === _win[++match] && _win[++scan] === _win[++match] &&
      _win[++scan] === _win[++match] && _win[++scan] === _win[++match] &&
      scan < strend
    );
    len = MAX_MATCH - (strend - scan);
    scan = strend - MAX_MATCH;
    if (len > best_len) {
      s.match_start = cur_match;
      best_len = len;
      if (len >= nice_match) {
        break;
      }
      scan_end1 = _win[scan + best_len - 1];
      scan_end = _win[scan + best_len];
    }
  } while (
    (cur_match = prev[cur_match & wmask]) > limit && (--chain_length) !== 0
  );
  if (best_len <= s.lookahead) {
    return best_len;
  }
  return s.lookahead;
}
function longest_match ( s , cur_match ) { let chain_length = s . max_chain_length ; let scan = s . strstart ; let match ; let len ; let best_len = s . prev_length ; let nice_match = s . nice_match ; let limit = s . strstart > s . w_size - MIN_LOOKAHEAD ? s . strstart - ( s . w_size - MIN_LOOKAHEAD ) : 0 ; let _win = s . window ; let wmask = s . w_mask ; let prev = s . prev ; let strend = s . strstart + MAX_MATCH ; let scan_end1 = _win [ scan + best_len - 1 ] ; let scan_end = _win [ scan + best_len ] ; if ( s . prev_length >= s . good_match ) { chain_length >>= 2 ; } if ( nice_match > s . lookahead ) nice_match = s . lookahead ; do { match = cur_match ; if ( _win [ match + best_len ] !== scan_end || _win [ match + best_len - 1 ] !== scan_end1 || _win [ match ] !== _win [ scan ] || _win [ ++ match ] !== _win [ scan + 1 ] ) { continue ; } scan += 2 ; match ++ ; do { } while ( _win [ ++ scan ] === _win [ ++ match ] && _win [ ++ scan ] === _win [ ++ match ] && _win [ ++ scan ] === _win [ ++ match ] && _win [ ++ scan ] === _win [ ++ match ] && _win [ ++ scan ] === _win [ ++ match ] && _win [ ++ scan ] === _win [ ++ match ] && _win [ ++ scan ] === _win [ ++ match ] && _win [ ++ scan ] === _win [ ++ match ] && scan < strend ) ; len = MAX_MATCH - ( strend - scan ) ; scan = strend - MAX_MATCH ; if ( len > best_len ) { s . match_start = cur_match ; best_len = len ; if ( len >= nice_match ) { break ; } scan_end1 = _win [ scan + best_len - 1 ] ; scan_end = _win [ scan + best_len ] ; } } while ( ( cur_match = prev [ cur_match & wmask ] ) > limit && ( -- chain_length ) !== 0 ) ; if ( best_len <= s . lookahead ) { return best_len ; } return s . lookahead ; }
Set match_start to the longest match starting at the given string and
 return its length.
Set match_start to the longest match starting at the given string and return its length .
/* max hash chain length */ /* current string */ /* matched string */ /* length of current match */ /* best match length so far */ /* stop if match long enough */ /*NIL*/ // shortcut /* Stop when cur_match becomes <= limit. To simplify the code,
   * we prevent matches with the string of window index 0.
   */ /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16.
   * It is easy to get rid of this optimization if necessary.
   */ // Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever"); /* Do not waste too much time if we already have a good match: */ /* Do not look for matches beyond the end of the input. This is necessary
   * to make deflate deterministic.
   */ // Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead"); // Assert(cur_match < s->strstart, "no future"); /* Skip to next match if the match length cannot increase
     * or if the match length is less than 2.  Note that the checks below
     * for insufficient lookahead only occur occasionally for performance
     * reasons.  Therefore uninitialized memory will be accessed, and
     * conditional jumps will be made that depend on those values.
     * However the length of the match is limited to the lookahead, so
     * the output of deflate is not affected by the uninitialized values.
     */ /* The check at best_len-1 can be removed because it will be made
     * again later. (This heuristic is not always a win.)
     * It is not necessary to compare scan[2] and match[2] since they
     * are always equal when the other bytes match, given that
     * the hash keys are equal and that HASH_BITS >= 8.
     */ // Assert(*scan == *match, "match[2]?"); /* We check for insufficient lookahead only every 8th comparison;
     * the 256th check will be made at strstart+258.
     */ /*jshint noempty:false*/ // Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");