MCPcopy Create free account
hub / github.com/RsyncProject/rsync / deflate_fast

Function deflate_fast

zlib/deflate.c:1619–1721  ·  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. */

Source from the content-addressed store, hash-verified

1617 * matches. It is used only for the fast compression options.
1618 */
1619local block_state deflate_fast(deflate_state *s, int flush)
1620{
1621 IPos hash_head; /* head of the hash chain */
1622 int bflush; /* set if current block must be flushed */
1623
1624 for (;;) {
1625 /* Make sure that we always have enough lookahead, except
1626 * at the end of the input file. We need MAX_MATCH bytes
1627 * for the next match, plus MIN_MATCH bytes to insert the
1628 * string following the next match.
1629 */
1630 if (s->lookahead < MIN_LOOKAHEAD) {
1631 fill_window(s);
1632 if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
1633 return need_more;
1634 }
1635 if (s->lookahead == 0) break; /* flush the current block */
1636 }
1637
1638 /* Insert the string window[strstart .. strstart+2] in the
1639 * dictionary, and set hash_head to the head of the hash chain:
1640 */
1641 hash_head = NIL;
1642 if (s->lookahead >= MIN_MATCH) {
1643 INSERT_STRING(s, s->strstart, hash_head);
1644 }
1645
1646 if (flush == Z_INSERT_ONLY) {
1647 s->strstart++;
1648 s->lookahead--;
1649 continue;
1650 }
1651
1652 /* Find the longest match, discarding those <= prev_length.
1653 * At this point we have always match_length < MIN_MATCH
1654 */
1655 if (hash_head != NIL && s->strstart - hash_head <= MAX_DIST(s)) {
1656 /* To simplify the code, we prevent matches with the string
1657 * of window index 0 (in particular we have to avoid a match
1658 * of the string with itself at the start of the input file).
1659 */
1660 s->match_length = longest_match (s, hash_head);
1661 /* longest_match() sets match_start */
1662 }
1663 if (s->match_length >= MIN_MATCH) {
1664 check_match(s, s->strstart, s->match_start, s->match_length);
1665
1666 _tr_tally_dist(s, s->strstart - s->match_start,
1667 s->match_length - MIN_MATCH, bflush);
1668
1669 s->lookahead -= s->match_length;
1670
1671 /* Insert new strings in the hash table only if the match length
1672 * is not too large. This saves time but degrades compression.
1673 */
1674#ifndef FASTEST
1675 if (s->match_length <= s->max_insert_length &&
1676 s->lookahead >= MIN_MATCH) {

Callers

nothing calls this directly

Calls 3

fill_windowFunction · 0.85
longest_matchFunction · 0.85
check_matchFunction · 0.85

Tested by

no test coverage detected