MCPcopy Create free account
hub / github.com/9chu/LuaSTGPlus / ZLIB_INTERNAL

Function ZLIB_INTERNAL

ZLib/trees.c:1010–1055  ·  view source on GitHub ↗

=========================================================================== * Save the match info and tally the frequency counts. Return true if * the current block must be flushed. */

(s, dist, lc)

Source from the content-addressed store, hash-verified

1008 * the current block must be flushed.
1009 */
1010int ZLIB_INTERNAL _tr_tally (s, dist, lc)
1011 deflate_state *s;
1012 unsigned dist; /* distance of matched string */
1013 unsigned lc; /* match length-MIN_MATCH or unmatched char (if dist==0) */
1014{
1015 s->d_buf[s->last_lit] = (ush)dist;
1016 s->l_buf[s->last_lit++] = (uch)lc;
1017 if (dist == 0) {
1018 /* lc is the unmatched char */
1019 s->dyn_ltree[lc].Freq++;
1020 } else {
1021 s->matches++;
1022 /* Here, lc is the match length - MIN_MATCH */
1023 dist--; /* dist = match distance - 1 */
1024 Assert((ush)dist < (ush)MAX_DIST(s) &&
1025 (ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) &&
1026 (ush)d_code(dist) < (ush)D_CODES, "_tr_tally: bad match");
1027
1028 s->dyn_ltree[_length_code[lc]+LITERALS+1].Freq++;
1029 s->dyn_dtree[d_code(dist)].Freq++;
1030 }
1031
1032#ifdef TRUNCATE_BLOCK
1033 /* Try to guess if it is profitable to stop the current block here */
1034 if ((s->last_lit & 0x1fff) == 0 && s->level > 2) {
1035 /* Compute an upper bound for the compressed length */
1036 ulg out_length = (ulg)s->last_lit*8L;
1037 ulg in_length = (ulg)((long)s->strstart - s->block_start);
1038 int dcode;
1039 for (dcode = 0; dcode < D_CODES; dcode++) {
1040 out_length += (ulg)s->dyn_dtree[dcode].Freq *
1041 (5L+extra_dbits[dcode]);
1042 }
1043 out_length >>= 3;
1044 Tracev((stderr,"\nlast_lit %u, in %ld, out ~%ld(%ld%%) ",
1045 s->last_lit, in_length, out_length,
1046 100L - out_length*100L/in_length));
1047 if (s->matches < s->last_lit/2 && out_length < in_length/2) return 1;
1048 }
1049#endif
1050 return (s->last_lit == s->lit_bufsize-1);
1051 /* We avoid equality with lit_bufsize because of wraparound at 64K
1052 * on 16 bit machines and because stored blocks are restricted to
1053 * 64K-1 bytes.
1054 */
1055}
1056
1057/* ===========================================================================
1058 * Send the block data compressed using the given Huffman trees

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected