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

Function deflate_fast

zlib/deflate.c:1448–1546  ·  view source on GitHub ↗

=========================================================================== * Compress as much as possible from the input stream, return the current * block state. * This function does not perform lazy evaluation of matches and inserts * new strings in the dictionary only for unmatched strings or for short * matches. It is used only for the fast compression options. */

(s, flush)

Source from the content-addressed store, hash-verified

1446 * matches. It is used only for the fast compression options.
1447 */
1448local block_state deflate_fast(s, flush)
1449 deflate_state *s;
1450 int flush;
1451{
1452 IPos hash_head = NIL; /* head of the hash chain */
1453 int bflush; /* set if current block must be flushed */
1454
1455 for (;;) {
1456 /* Make sure that we always have enough lookahead, except
1457 * at the end of the input file. We need MAX_MATCH bytes
1458 * for the next match, plus MIN_MATCH bytes to insert the
1459 * string following the next match.
1460 */
1461 if (s->lookahead < MIN_LOOKAHEAD) {
1462 fill_window(s);
1463 if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
1464 return need_more;
1465 }
1466 if (s->lookahead == 0) break; /* flush the current block */
1467 }
1468
1469 /* Insert the string window[strstart .. strstart+2] in the
1470 * dictionary, and set hash_head to the head of the hash chain:
1471 */
1472 if (s->lookahead >= MIN_MATCH) {
1473 INSERT_STRING(s, s->strstart, hash_head);
1474 }
1475
1476 /* Find the longest match, discarding those <= prev_length.
1477 * At this point we have always match_length < MIN_MATCH
1478 */
1479 if (hash_head != NIL && s->strstart - hash_head <= MAX_DIST(s)) {
1480 /* To simplify the code, we prevent matches with the string
1481 * of window index 0 (in particular we have to avoid a match
1482 * of the string with itself at the start of the input file).
1483 */
1484#ifdef FASTEST
1485 if ((s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) ||
1486 (s->strategy == Z_RLE && s->strstart - hash_head == 1)) {
1487 s->match_length = longest_match_fast (s, hash_head);
1488 }
1489#else
1490 if (s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) {
1491 s->match_length = longest_match (s, hash_head);
1492 } else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) {
1493 s->match_length = longest_match_fast (s, hash_head);
1494 }
1495#endif
1496 /* longest_match() or longest_match_fast() sets match_start */
1497 }
1498 if (s->match_length >= MIN_MATCH) {
1499 check_match(s, s->strstart, s->match_start, s->match_length);
1500
1501 _tr_tally_dist(s, s->strstart - s->match_start,
1502 s->match_length - MIN_MATCH, bflush);
1503
1504 s->lookahead -= s->match_length;
1505

Callers

nothing calls this directly

Calls 4

fill_windowFunction · 0.85
longest_match_fastFunction · 0.85
longest_matchFunction · 0.85
check_matchFunction · 0.85

Tested by

no test coverage detected