diff --git a/lib/zlib/inflate.js b/lib/zlib/inflate.js index b082dc8..9c8d951 100644 --- a/lib/zlib/inflate.js +++ b/lib/zlib/inflate.js @@ -106,14 +106,6 @@ function Code() { this.val = 0; /* offset in table or code value */ } -Code.prototype.clone = function() { - var new_code = new Code(); - new_code.op = this.op; - new_code.bits = this.bits; - new_code.val = this.val; - return new_code; -}; - function CodeTable(length) { // Packed data: [ bits, op, value], 1byte + 1byte +2 bytes this.data = utils.array32Create(length); @@ -126,12 +118,8 @@ CodeTable.prototype.fill = function(idx, code) { code.val = packed & 0xffff; }; -CodeTable.prototype.set = function(idx, code) { - this.data[idx] = (code.bits << 24) | (code.op << 16) | code.val; -}; - CodeTable.prototype.copy = function(table) { - utils.arraySet(this.data,table.data,0,table.data.length,0); + utils.arraySet(this.data, table.data, 0, table.data.length, 0); }; function InflateState() { @@ -188,8 +176,6 @@ function InflateState() { this.sane = 0; /* if false, allow invalid distance too far */ this.back = 0; /* bits back of last unprocessed length/lit */ this.was = 0; /* initial length of match */ - - this.here = new Code(); } function InfTableOptions(type, lens, lens_index, codes, table, table_index, bits, work) { @@ -201,7 +187,6 @@ function InfTableOptions(type, lens, lens_index, codes, table, table_index, bits this.table_index = table_index; this.bits = bits; this.work = work; - this.here = new Code(); } function inflateResetKeep(strm) { @@ -442,7 +427,8 @@ function inflate(strm, flush) { var from; /* where to copy match bytes from */ var from_source; var here = new Code(); /* current decoding table entry */ - var last; /* parent table entry */ + //var last; /* parent table entry */ + var last_bits, last_op, last_val; // paked "last" denormalized var len; /* length to copy for repeats, bits to drop */ var ret; /* return code */ var hbuf = utils.arrayCreate(4); /* buffer for gzip header crc calculation */ @@ -1165,11 +1151,13 @@ function inflate(strm, flush) { //---// } if (here.op && (here.op & 0xf0) === 0) { - last = here.clone(); + last_bits = here.bits; + last_op = here.op; + last_val = here.val; for (;;) { - state.lencode.fill(last.val + - ((hold & ((1 << (last.bits + last.op)) -1))/*BITS(last.bits + last.op)*/ >> last.bits), here); - if ((last.bits + here.bits) <= bits) { break; } + state.lencode.fill(last_val + + ((hold & ((1 << (last_bits + last_op)) -1))/*BITS(last.bits + last.op)*/ >> last_bits), here); + if ((last_bits + here.bits) <= bits) { break; } //--- PULLBYTE() ---// if (have === 0) { break inf_leave; } have--; @@ -1178,10 +1166,10 @@ function inflate(strm, flush) { //---// } //--- DROPBITS(last.bits) ---// - hold >>>= last.bits; - bits -= last.bits; + hold >>>= last_bits; + bits -= last_bits; //---// - state.back += last.bits; + state.back += last_bits; } //--- DROPBITS(here.bits) ---// hold >>>= here.bits; @@ -1244,11 +1232,13 @@ function inflate(strm, flush) { //---// } if ((here.op & 0xf0) === 0) { - last = here.clone(); + last_bits = here.bits; + last_op = here.op; + last_val = here.val; for (;;) { - state.distcode.fill(last.val + - ((hold & ((1 << (last.bits + last.op)) -1))/*BITS(last.bits + last.op)*/ >> last.bits), here); - if ((last.bits + here.bits) <= bits) { break; } + state.distcode.fill(last_val + + ((hold & ((1 << (last_bits + last_op)) -1))/*BITS(last.bits + last.op)*/ >> last_bits), here); + if ((last_bits + here.bits) <= bits) { break; } //--- PULLBYTE() ---// if (have === 0) { break inf_leave; } have--; @@ -1257,10 +1247,10 @@ function inflate(strm, flush) { //---// } //--- DROPBITS(last.bits) ---// - hold >>>= last.bits; - bits -= last.bits; + hold >>>= last_bits; + bits -= last_bits; //---// - state.back += last.bits; + state.back += last_bits; } //--- DROPBITS(here.bits) ---// hold >>>= here.bits; diff --git a/lib/zlib/inftrees.js b/lib/zlib/inftrees.js index ba8e032..c40e289 100644 --- a/lib/zlib/inftrees.js +++ b/lib/zlib/inftrees.js @@ -41,8 +41,8 @@ module.exports = function inflate_table(opts) codes = opts.codes, table = opts.table, bits = opts.bits, - work = opts.work, - here = opts.here; /* table entry for duplication */ + work = opts.work; + //here = opts.here; /* table entry for duplication */ var len = 0; /* a code's length in bits */ var sym = 0; /* index of code symbols */ @@ -67,6 +67,7 @@ module.exports = function inflate_table(opts) var extra = null; var extra_index = 0; + var here_bits, here_op, here_val; /* Process a set of code lengths to create a canonical Huffman code. The @@ -235,18 +236,18 @@ module.exports = function inflate_table(opts) for (;;) { i++; /* create table entry */ - here.bits = len - drop; + here_bits = len - drop; if (work[sym] < end) { - here.op = 0; - here.val = work[sym]; + here_op = 0; + here_val = work[sym]; } else if (work[sym] > end) { - here.op = extra[extra_index + work[sym]]; - here.val = base[base_index + work[sym]]; + here_op = extra[extra_index + work[sym]]; + here_val = base[base_index + work[sym]]; } else { - here.op = 32 + 64; /* end of block */ - here.val = 0; + here_op = 32 + 64; /* end of block */ + here_val = 0; } /* replicate for those indices with low len bits equal to huff */ @@ -255,7 +256,7 @@ module.exports = function inflate_table(opts) min = fill; /* save offset to next table */ do { fill -= incr; - table.set(next + (huff >> drop) + fill, here); + table.data[next + (huff >> drop) + fill] = (here_bits << 24) | (here_op << 16) | here_val |0; } while (fill !== 0); /* backwards increment the len-bit code huff */