MCPcopy Create free account
hub / github.com/ObEngine/ObEngine / longest_match

Function longest_match

extlibs/minizip/src/deflate.c:1343–1492  ·  view source on GitHub ↗

For 80x86 and 680x0, an optimized version will be provided in match.asm or * match.S. The code will be functionally equivalent. */

(s, cur_match)

Source from the content-addressed store, hash-verified

1341 * match.S. The code will be functionally equivalent.
1342 */
1343local uInt longest_match(s, cur_match)
1344deflate_state* s;
1345
1346IPos cur_match; /* current match */
1347{
1348 unsigned chain_length = s->max_chain_length;/* max hash chain length */
1349 register Bytef* scan = s->window + s->strstart; /* current string */
1350 register Bytef* match; /* matched string */
1351 register int len; /* length of current match */
1352 int best_len = (int)s->prev_length; /* best match length so far */
1353 int nice_match = s->nice_match; /* stop if match long enough */
1354 IPos limit = s->strstart > (IPos)MAX_DIST(s) ?
1355 s->strstart - (IPos)MAX_DIST(s) : NIL;
1356 /* Stop when cur_match becomes <= limit. To simplify the code,
1357 * we prevent matches with the string of window index 0.
1358 */
1359 Posf* prev = s->prev;
1360 uInt wmask = s->w_mask;
1361
1362#ifdef UNALIGNED_OK
1363 /* Compare two bytes at a time. Note: this is not always beneficial.
1364 * Try with and without -DUNALIGNED_OK to check.
1365 */
1366 register Bytef *strend = s->window + s->strstart + MAX_MATCH - 1;
1367 register ush scan_start = *(ushf*)scan;
1368 register ush scan_end = *(ushf*)(scan+best_len-1);
1369#else
1370 register Bytef* strend = s->window + s->strstart + MAX_MATCH;
1371 register Byte scan_end1 = scan[best_len - 1];
1372 register Byte scan_end = scan[best_len];
1373#endif
1374
1375 /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16.
1376 * It is easy to get rid of this optimization if necessary.
1377 */
1378 Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
1379
1380 /* Do not waste too much time if we already have a good match: */
1381 if (s->prev_length >= s->good_match)
1382 {
1383 chain_length >>= 2;
1384 }
1385 /* Do not look for matches beyond the end of the input. This is necessary
1386 * to make deflate deterministic.
1387 */
1388 if ((uInt)nice_match > s->lookahead) nice_match = (int)s->lookahead;
1389
1390 Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
1391
1392 do
1393 {
1394 Assert(cur_match < s->strstart, "no future");
1395 match = s->window + cur_match;
1396
1397 /* Skip to next match if the match length cannot increase
1398 * or if the match length is less than 2. Note that the checks below
1399 * for insufficient lookahead only occur occasionally for performance
1400 * reasons. Therefore uninitialized memory will be accessed, and

Callers 2

deflate_fastFunction · 0.85
deflate_slowFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected