MCPcopy Create free account
hub / github.com/Meituan-Dianping/SQLAdvisor / longest_match_fast

Function longest_match_fast

zlib/deflate.c:1175–1226  ·  view source on GitHub ↗

--------------------------------------------------------------------------- * Optimized version for level == 1 or strategy == Z_RLE only */

(s, cur_match)

Source from the content-addressed store, hash-verified

1173 * Optimized version for level == 1 or strategy == Z_RLE only
1174 */
1175local uInt longest_match_fast(s, cur_match)
1176 deflate_state *s;
1177 IPos cur_match; /* current match */
1178{
1179 register Bytef *scan = s->window + s->strstart; /* current string */
1180 register Bytef *match; /* matched string */
1181 register int len; /* length of current match */
1182 register Bytef *strend = s->window + s->strstart + MAX_MATCH;
1183
1184 /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16.
1185 * It is easy to get rid of this optimization if necessary.
1186 */
1187 Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
1188
1189 Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
1190
1191 Assert(cur_match < s->strstart, "no future");
1192
1193 match = s->window + cur_match;
1194
1195 /* Return failure if the match length is less than 2:
1196 */
1197 if (match[0] != scan[0] || match[1] != scan[1]) return MIN_MATCH-1;
1198
1199 /* The check at best_len-1 can be removed because it will be made
1200 * again later. (This heuristic is not always a win.)
1201 * It is not necessary to compare scan[2] and match[2] since they
1202 * are always equal when the other bytes match, given that
1203 * the hash keys are equal and that HASH_BITS >= 8.
1204 */
1205 scan += 2, match += 2;
1206 Assert(*scan == *match, "match[2]?");
1207
1208 /* We check for insufficient lookahead only every 8th comparison;
1209 * the 256th check will be made at strstart+258.
1210 */
1211 do {
1212 } while (*++scan == *++match && *++scan == *++match &&
1213 *++scan == *++match && *++scan == *++match &&
1214 *++scan == *++match && *++scan == *++match &&
1215 *++scan == *++match && *++scan == *++match &&
1216 scan < strend);
1217
1218 Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
1219
1220 len = MAX_MATCH - (int)(strend - scan);
1221
1222 if (len < MIN_MATCH) return MIN_MATCH - 1;
1223
1224 s->match_start = cur_match;
1225 return (uInt)len <= s->lookahead ? (uInt)len : s->lookahead;
1226}
1227
1228#ifdef DEBUG
1229/* ===========================================================================

Callers 2

deflate_fastFunction · 0.85
deflate_slowFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected