diff --git a/lib/zlib/inflate.js b/lib/zlib/inflate.js index 0c26cf6..b082dc8 100644 --- a/lib/zlib/inflate.js +++ b/lib/zlib/inflate.js @@ -115,27 +115,23 @@ Code.prototype.clone = function() { }; function CodeTable(length) { - this.op = length ? utils.arrayCreate(length) : null; - this.val = length ? utils.array16Create(length): null; - this.bits = length ? utils.arrayCreate(length) : null; + // Packed data: [ bits, op, value], 1byte + 1byte +2 bytes + this.data = utils.array32Create(length); } CodeTable.prototype.fill = function(idx, code) { - code.bits = this.bits[idx]; - code.op = this.op[idx]; - code.val = this.val[idx]; + var packed = this.data[idx]; + code.bits = packed >>> 24; + code.op = (packed >>> 16) & 0xff; + code.val = packed & 0xffff; }; CodeTable.prototype.set = function(idx, code) { - this.bits[idx] = code.bits; - this.op[idx] = code.op; - this.val[idx] = code.val; + this.data[idx] = (code.bits << 24) | (code.op << 16) | code.val; }; CodeTable.prototype.copy = function(table) { - utils.arraySet(this.bits,table.bits,0,table.bits.length,0); - utils.arraySet(this.op,table.op,0,table.op.length,0); - utils.arraySet(this.val,table.val,0,table.val.length,0); + utils.arraySet(this.data,table.data,0,table.data.length,0); }; function InflateState() { diff --git a/lib/zlib/inftrees.js b/lib/zlib/inftrees.js index 7bc191e..ba8e032 100644 --- a/lib/zlib/inftrees.js +++ b/lib/zlib/inftrees.js @@ -116,13 +116,17 @@ module.exports = function inflate_table(opts) root = max; } if (max === 0) { /* no symbols to code at all */ - table.op[opts.table_index] = 64; //here.op = (var char)64; /* invalid code marker */ - table.bits[opts.table_index] = 1; //here.bits = (var char)1; - table.val[opts.table_index++] = 0; //here.val = (var short)0; + //table.op[opts.table_index] = 64; //here.op = (var char)64; /* invalid code marker */ + //table.bits[opts.table_index] = 1; //here.bits = (var char)1; + //table.val[opts.table_index++] = 0; //here.val = (var short)0; + table.data[opts.table_index++] = (1 << 24) | (64 << 16) | 0; + + + //table.op[opts.table_index] = 64; + //table.bits[opts.table_index] = 1; + //table.val[opts.table_index++] = 0; + table.data[opts.table_index++] = (1 << 24) | (64 << 16) | 0; - table.op[opts.table_index] = 64; - table.bits[opts.table_index] = 1; - table.val[opts.table_index++] = 0; opts.bits = 1; return 0; /* no symbols, but wait for decoding to report error */ } @@ -302,9 +306,10 @@ module.exports = function inflate_table(opts) /* point entry in root table to sub-table */ low = huff & mask; - table.op[low] = curr; + /*table.op[low] = curr; table.bits[low] = root; - table.val[low] = next - opts.table_index; + table.val[low] = next - opts.table_index;*/ + table.data[low] = (root << 24) | (curr << 16) | (next - opts.table_index); } } @@ -312,9 +317,10 @@ module.exports = function inflate_table(opts) at most one remaining entry, since if the code is incomplete, the maximum code length that was allowed to get this far is one bit) */ if (huff !== 0) { - table.op[next + huff] = 64; /* invalid code marker */ - table.bits[next + huff] = len - drop; - table.val[next + huff] = 0; + //table.op[next + huff] = 64; /* invalid code marker */ + //table.bits[next + huff] = len - drop; + //table.val[next + huff] = 0; + table.data[next + huff] = ((len - drop) << 24) | (64 << 16) | 0; } /* set return parameters */ diff --git a/lib/zlib/utils.js b/lib/zlib/utils.js index 1496ef4..0e62165 100644 --- a/lib/zlib/utils.js +++ b/lib/zlib/utils.js @@ -62,22 +62,37 @@ exports.arraySet = function (dest, src, src_offs, len, dest_offs) { exports.arrayCreate = function (length) { - if (typedOk()) { return new Uint8Array(length); } - // Fallback to ordinary array return new Array(length); }; exports.array16Create = function (length) { - if (typedOk()) { return new Uint16Array(length); } + // Fallback to ordinary array + return new Array(length); +}; + +exports.array16Create = function (length) { + if (typedOk()) { + return new Uint16Array(length); + } + // Fallback to ordinary array + return new Array(length); +}; + + +// (!) use signed ints for 32 bits, to avoid boxing +exports.array32Create = function (length) { + if (typedOk()) { + return new Int32Array(length); + } // Fallback to ordinary array return new Array(length); };