lib/ruby/truffle/pr-zlib/lib/pr/rbzlib.rb
# 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 .
def longest_match(s,cur_match)
    chain_length = s.max_chain_length
    scan = s.strstart
    best_len = s.prev_length
    nice_match = s.nice_match
    _MAX_DIST = s.w_size - MIN_LOOKAHEAD
    if s.strstart > (_MAX_DIST)
      limit = s.strstart - (_MAX_DIST)
    else
      limit = ZNIL
    end
    prev = s.prev
    wmask = s.w_mask
    strend = s.strstart + MAX_MATCH
    scan_end1  = s.window[scan + best_len-1]
    scan_end   = s.window[scan + best_len]
    if s.prev_length >= s.good_match
      chain_length >>= 2
    end
    if nice_match > s.lookahead
      nice_match = s.lookahead
    end
    begin
        match = cur_match
        if (s.window[match + best_len] != scan_end) ||
           (s.window[match + best_len-1] != scan_end1) ||
           (s.window[match] != s.window[scan])
        then
           cur_match = prev[cur_match & wmask]
           chain_length -= 1
           next
        end
        match += 1
        if s.window[match] != s.window[scan+1]
           cur_match = prev[cur_match & wmask]
           chain_length -= 1
           next
        end
        scan += 2
        match += 1
        loop do
          break if s.window[scan+=1] != s.window[match+=1]
          break if s.window[scan+=1] != s.window[match+=1]
          break if s.window[scan+=1] != s.window[match+=1]
          break if s.window[scan+=1] != s.window[match+=1]
          break if s.window[scan+=1] != s.window[match+=1]
          break if s.window[scan+=1] != s.window[match+=1]
          break if s.window[scan+=1] != s.window[match+=1]
          break if s.window[scan+=1] != s.window[match+=1]
          break if scan >= strend
        end
        len = MAX_MATCH - (strend - scan)
        scan = strend
        scan -= MAX_MATCH
        if len > best_len
          s.match_start = cur_match
          best_len = len
          break if (len >= nice_match)
          scan_end1 = s.window[scan+best_len-1]
          scan_end  = s.window[scan+best_len]
        end
        cur_match = prev[cur_match & wmask]
        chain_length -= 1
    end until (cur_match <= limit) || chain_length == 0
    if best_len <= s.lookahead
      return best_len
    else
      return s.lookahead
    end
  end
def longest_match ( s , cur_match ) chain_length = s . max_chain_length scan = s . strstart best_len = s . prev_length nice_match = s . nice_match _MAX_DIST = s . w_size - MIN_LOOKAHEAD if s . strstart > ( _MAX_DIST ) limit = s . strstart - ( _MAX_DIST ) else limit = ZNIL end prev = s . prev wmask = s . w_mask strend = s . strstart + MAX_MATCH scan_end1 = s . window [ scan + best_len - 1 ] scan_end = s . window [ scan + best_len ] if s . prev_length >= s . good_match chain_length >>= 2 end if nice_match > s . lookahead nice_match = s . lookahead end begin match = cur_match if ( s . window [ match + best_len ] != scan_end ) || ( s . window [ match + best_len - 1 ] != scan_end1 ) || ( s . window [ match ] != s . window [ scan ] ) then cur_match = prev [ cur_match & wmask ] chain_length -= 1 next end match += 1 if s . window [ match ] != s . window [ scan + 1 ] cur_match = prev [ cur_match & wmask ] chain_length -= 1 next end scan += 2 match += 1 loop do break if s . window [ scan += 1 ] != s . window [ match += 1 ] break if s . window [ scan += 1 ] != s . window [ match += 1 ] break if s . window [ scan += 1 ] != s . window [ match += 1 ] break if s . window [ scan += 1 ] != s . window [ match += 1 ] break if s . window [ scan += 1 ] != s . window [ match += 1 ] break if s . window [ scan += 1 ] != s . window [ match += 1 ] break if s . window [ scan += 1 ] != s . window [ match += 1 ] break if s . window [ scan += 1 ] != s . window [ match += 1 ] break if scan >= strend end len = MAX_MATCH - ( strend - scan ) scan = strend scan -= MAX_MATCH if len > best_len s . match_start = cur_match best_len = len break if ( len >= nice_match ) scan_end1 = s . window [ scan + best_len - 1 ] scan_end = s . window [ scan + best_len ] end cur_match = prev [ cur_match & wmask ] chain_length -= 1 end until ( cur_match <= limit ) || chain_length == 0 if best_len <= s . lookahead return best_len else return s . lookahead end end
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 .
# Seems redundant, but mimics the C code
s
<not_specific>
cur_match
<not_specific>