mirror of
https://github.com/0x5eal/rbxts-pako.git
synced 2025-04-04 10:50:59 +01:00
Store tables data in compact form
This commit is contained in:
parent
63ffa3baae
commit
f09d27bc1e
3 changed files with 43 additions and 26 deletions
|
@ -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() {
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue