=========================================================================== * Same as above, but achieves better compression. We use a lazy * evaluation for matches: a match is finally adopted only if there is * no better match at the next window position. */
(s, flush)
| 1552 | * no better match at the next window position. |
| 1553 | */ |
| 1554 | local block_state deflate_slow(s, flush) |
| 1555 | deflate_state *s; |
| 1556 | int flush; |
| 1557 | { |
| 1558 | IPos hash_head = NIL; /* head of hash chain */ |
| 1559 | int bflush; /* set if current block must be flushed */ |
| 1560 | |
| 1561 | /* Process the input block. */ |
| 1562 | for (;;) { |
| 1563 | /* Make sure that we always have enough lookahead, except |
| 1564 | * at the end of the input file. We need MAX_MATCH bytes |
| 1565 | * for the next match, plus MIN_MATCH bytes to insert the |
| 1566 | * string following the next match. |
| 1567 | */ |
| 1568 | if (s->lookahead < MIN_LOOKAHEAD) { |
| 1569 | fill_window(s); |
| 1570 | if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) { |
| 1571 | return need_more; |
| 1572 | } |
| 1573 | if (s->lookahead == 0) break; /* flush the current block */ |
| 1574 | } |
| 1575 | |
| 1576 | /* Insert the string window[strstart .. strstart+2] in the |
| 1577 | * dictionary, and set hash_head to the head of the hash chain: |
| 1578 | */ |
| 1579 | if (s->lookahead >= MIN_MATCH) { |
| 1580 | INSERT_STRING(s, s->strstart, hash_head); |
| 1581 | } |
| 1582 | |
| 1583 | /* Find the longest match, discarding those <= prev_length. |
| 1584 | */ |
| 1585 | s->prev_length = s->match_length, s->prev_match = s->match_start; |
| 1586 | s->match_length = MIN_MATCH-1; |
| 1587 | |
| 1588 | if (hash_head != NIL && s->prev_length < s->max_lazy_match && |
| 1589 | s->strstart - hash_head <= MAX_DIST(s)) { |
| 1590 | /* To simplify the code, we prevent matches with the string |
| 1591 | * of window index 0 (in particular we have to avoid a match |
| 1592 | * of the string with itself at the start of the input file). |
| 1593 | */ |
| 1594 | if (s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) { |
| 1595 | s->match_length = longest_match (s, hash_head); |
| 1596 | } else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) { |
| 1597 | s->match_length = longest_match_fast (s, hash_head); |
| 1598 | } |
| 1599 | /* longest_match() or longest_match_fast() sets match_start */ |
| 1600 | |
| 1601 | if (s->match_length <= 5 && (s->strategy == Z_FILTERED |
| 1602 | #if TOO_FAR <= 32767 |
| 1603 | || (s->match_length == MIN_MATCH && |
| 1604 | s->strstart - s->match_start > TOO_FAR) |
| 1605 | #endif |
| 1606 | )) { |
| 1607 | |
| 1608 | /* If prev_match is also MIN_MATCH, match_start is garbage |
| 1609 | * but we will ignore the current match anyway. |
| 1610 | */ |
| 1611 | s->match_length = MIN_MATCH-1; |
nothing calls this directly
no test coverage detected