ComponentAce.Compression.Libs.ZLib.Deflate._tr_tally C# (CSharp) Method

_tr_tally() private method

Save the match info and tally the frequency counts. Return true if the current block must be flushed.
private _tr_tally ( int dist, int lc ) : bool
dist int
lc int
return bool
        private bool _tr_tally(int dist, int lc)
        {

            Pending_buf[d_buf + last_lit * 2] = (byte)(ZLibUtil.URShift(dist, 8));
            Pending_buf[d_buf + last_lit * 2 + 1] = (byte)dist;

            Pending_buf[l_buf + last_lit] = (byte)lc; last_lit++;

            if (dist == 0)
            {
                // lc is the unmatched char
                dyn_ltree[lc * 2]++;
            }
            else
            {
                matches++;
                // Here, lc is the match length - MIN_MATCH
                dist--; // dist = match distance - 1
                dyn_ltree[(ZLibUtil._length_code[lc] + LITERALS + 1) * 2]++;
                dyn_dtree[Tree.d_code(dist) * 2]++;
            }

            if ((last_lit & 0x1fff) == 0 && level > 2)
            {
                // Compute an upper bound for the compressed length
                int out_length = last_lit * 8;
                int in_length = strstart - block_start;
                int dcode;
                for (dcode = 0; dcode < D_CODES; dcode++)
                {
                    out_length = (int)(out_length + (int)dyn_dtree[dcode * 2] * (5L + ZLibUtil.extra_dbits[dcode]));
                }
                out_length = ZLibUtil.URShift(out_length, 3);
                if ((matches < (last_lit / 2)) && out_length < in_length / 2)
                    return true;
            }

            return (last_lit == lit_bufsize - 1);
            // We avoid equality with lit_bufsize because of wraparound at 64K
            // on 16 bit machines and because stored blocks are restricted to
            // 64K-1 bytes.
        }