| 23491 | * the current block must be flushed. |
| 23492 | */ |
| 23493 | function _tr_tally(s, dist, lc) |
| 23494 | // deflate_state *s; |
| 23495 | // unsigned dist; /* distance of matched string */ |
| 23496 | // unsigned lc; /* match length-MIN_MATCH or unmatched char (if dist==0) */ |
| 23497 | { |
| 23498 | //var out_length, in_length, dcode; |
| 23499 | |
| 23500 | s.pending_buf[s.d_buf + s.last_lit * 2] = (dist >>> 8) & 0xff; |
| 23501 | s.pending_buf[s.d_buf + s.last_lit * 2 + 1] = dist & 0xff; |
| 23502 | |
| 23503 | s.pending_buf[s.l_buf + s.last_lit] = lc & 0xff; |
| 23504 | s.last_lit++; |
| 23505 | |
| 23506 | if (dist === 0) { |
| 23507 | /* lc is the unmatched char */ |
| 23508 | s.dyn_ltree[lc * 2]/*.Freq*/++; |
| 23509 | } else { |
| 23510 | s.matches++; |
| 23511 | /* Here, lc is the match length - MIN_MATCH */ |
| 23512 | dist--; /* dist = match distance - 1 */ |
| 23513 | //Assert((ush)dist < (ush)MAX_DIST(s) && |
| 23514 | // (ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) && |
| 23515 | // (ush)d_code(dist) < (ush)D_CODES, "_tr_tally: bad match"); |
| 23516 | |
| 23517 | s.dyn_ltree[(_length_code[lc] + LITERALS + 1) * 2]/*.Freq*/++; |
| 23518 | s.dyn_dtree[d_code(dist) * 2]/*.Freq*/++; |
| 23519 | } |
| 23520 | |
| 23521 | // (!) This block is disabled in zlib defailts, |
| 23522 | // don't enable it for binary compatibility |
| 23523 | |
| 23524 | //#ifdef TRUNCATE_BLOCK |
| 23525 | // /* Try to guess if it is profitable to stop the current block here */ |
| 23526 | // if ((s.last_lit & 0x1fff) === 0 && s.level > 2) { |
| 23527 | // /* Compute an upper bound for the compressed length */ |
| 23528 | // out_length = s.last_lit*8; |
| 23529 | // in_length = s.strstart - s.block_start; |
| 23530 | // |
| 23531 | // for (dcode = 0; dcode < D_CODES; dcode++) { |
| 23532 | // out_length += s.dyn_dtree[dcode*2]/*.Freq*/ * (5 + extra_dbits[dcode]); |
| 23533 | // } |
| 23534 | // out_length >>>= 3; |
| 23535 | // //Tracev((stderr,"\nlast_lit %u, in %ld, out ~%ld(%ld%%) ", |
| 23536 | // // s->last_lit, in_length, out_length, |
| 23537 | // // 100L - out_length*100L/in_length)); |
| 23538 | // if (s.matches < (s.last_lit>>1)/*int /2*/ && out_length < (in_length>>1)/*int /2*/) { |
| 23539 | // return true; |
| 23540 | // } |
| 23541 | // } |
| 23542 | //#endif |
| 23543 | |
| 23544 | return (s.last_lit === s.lit_bufsize - 1); |
| 23545 | /* We avoid equality with lit_bufsize because of wraparound at 64K |
| 23546 | * on 16 bit machines and because stored blocks are restricted to |
| 23547 | * 64K-1 bytes. |
| 23548 | */ |
| 23549 | } |
| 23550 | |