| 11509 | * the current block must be flushed. |
| 11510 | */ |
| 11511 | function _tr_tally(s, dist, lc) |
| 11512 | // deflate_state *s; |
| 11513 | // unsigned dist; /* distance of matched string */ |
| 11514 | // unsigned lc; /* match length-MIN_MATCH or unmatched char (if dist==0) */ |
| 11515 | { |
| 11516 | //var out_length, in_length, dcode; |
| 11517 | |
| 11518 | s.pending_buf[s.d_buf + s.last_lit * 2] = (dist >>> 8) & 0xff; |
| 11519 | s.pending_buf[s.d_buf + s.last_lit * 2 + 1] = dist & 0xff; |
| 11520 | |
| 11521 | s.pending_buf[s.l_buf + s.last_lit] = lc & 0xff; |
| 11522 | s.last_lit++; |
| 11523 | |
| 11524 | if (dist === 0) { |
| 11525 | /* lc is the unmatched char */ |
| 11526 | s.dyn_ltree[lc * 2]/*.Freq*/++; |
| 11527 | } else { |
| 11528 | s.matches++; |
| 11529 | /* Here, lc is the match length - MIN_MATCH */ |
| 11530 | dist--; /* dist = match distance - 1 */ |
| 11531 | //Assert((ush)dist < (ush)MAX_DIST(s) && |
| 11532 | // (ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) && |
| 11533 | // (ush)d_code(dist) < (ush)D_CODES, "_tr_tally: bad match"); |
| 11534 | |
| 11535 | s.dyn_ltree[(_length_code[lc] + LITERALS + 1) * 2]/*.Freq*/++; |
| 11536 | s.dyn_dtree[d_code(dist) * 2]/*.Freq*/++; |
| 11537 | } |
| 11538 | |
| 11539 | // (!) This block is disabled in zlib defailts, |
| 11540 | // don't enable it for binary compatibility |
| 11541 | |
| 11542 | //#ifdef TRUNCATE_BLOCK |
| 11543 | // /* Try to guess if it is profitable to stop the current block here */ |
| 11544 | // if ((s.last_lit & 0x1fff) === 0 && s.level > 2) { |
| 11545 | // /* Compute an upper bound for the compressed length */ |
| 11546 | // out_length = s.last_lit*8; |
| 11547 | // in_length = s.strstart - s.block_start; |
| 11548 | // |
| 11549 | // for (dcode = 0; dcode < D_CODES; dcode++) { |
| 11550 | // out_length += s.dyn_dtree[dcode*2]/*.Freq*/ * (5 + extra_dbits[dcode]); |
| 11551 | // } |
| 11552 | // out_length >>>= 3; |
| 11553 | // //Tracev((stderr,"\nlast_lit %u, in %ld, out ~%ld(%ld%%) ", |
| 11554 | // // s->last_lit, in_length, out_length, |
| 11555 | // // 100L - out_length*100L/in_length)); |
| 11556 | // if (s.matches < (s.last_lit>>1)/*int /2*/ && out_length < (in_length>>1)/*int /2*/) { |
| 11557 | // return true; |
| 11558 | // } |
| 11559 | // } |
| 11560 | //#endif |
| 11561 | |
| 11562 | return (s.last_lit === s.lit_bufsize - 1); |
| 11563 | /* We avoid equality with lit_bufsize because of wraparound at 64K |
| 11564 | * on 16 bit machines and because stored blocks are restricted to |
| 11565 | * 64K-1 bytes. |
| 11566 | */ |
| 11567 | } |
| 11568 | |