mirror of
https://github.com/0x5eal/rbxts-pako.git
synced 2025-04-10 22:00:58 +01:00
Fixed spped degradation: set arrays sizes & data types
This commit is contained in:
parent
8341b4cf5c
commit
f4c1a86ed9
2 changed files with 22 additions and 7 deletions
|
@ -171,7 +171,7 @@ function fill_window(s) {
|
|||
zlib, so we don't care about this pathological case.)
|
||||
*/
|
||||
n = s.hash_size;
|
||||
p = s.head[n];
|
||||
p = n;
|
||||
do {
|
||||
m = s.head[--p];
|
||||
s.head[p] = m >= wsize ? m - wsize : 0;
|
||||
|
@ -179,7 +179,7 @@ function fill_window(s) {
|
|||
|
||||
n = wsize;
|
||||
if (FASTEST) {
|
||||
p = s.prev[n];
|
||||
p = n;
|
||||
do {
|
||||
m = s.head[--p];
|
||||
s.head[p] = m >= wsize ? m - wsize : 0;
|
||||
|
@ -499,13 +499,13 @@ function DeflateState() {
|
|||
* is directly used as sliding window.
|
||||
*/
|
||||
|
||||
this.prev = Z_NULL;
|
||||
this.prev = null;
|
||||
/* Link to older string with same hash index. To limit the size of this
|
||||
* array to 64K, this link is maintained only for the last 32K strings.
|
||||
* An index in this array is thus a window index modulo 32K.
|
||||
*/
|
||||
|
||||
this.head = Z_NULL;
|
||||
this.head = null;
|
||||
/* Heads of the hash chains or NIL. */
|
||||
|
||||
this.ins_h = 0;
|
||||
|
@ -659,6 +659,12 @@ function deflateInit2(strm, level, method, windowBits, memLevel, strategy) {
|
|||
s.strategy = strategy;
|
||||
s.method = method;
|
||||
|
||||
// precreate & prefill head/prev arrays to optimize v8 types
|
||||
s.head = new Array(s.hash_size);
|
||||
s.prev = new Array(s.w_size);
|
||||
utils.fill(s.head, 0);
|
||||
utils.fill(s.prev, 0);
|
||||
|
||||
return deflateReset(strm);
|
||||
}
|
||||
|
||||
|
|
|
@ -54,3 +54,12 @@ exports.arrayCreate = function(length) {
|
|||
// Fallback to ordinary array
|
||||
return new Array(length);
|
||||
};
|
||||
|
||||
|
||||
exports.fill = function (buf, val) {
|
||||
var len = buf.length;
|
||||
|
||||
if (!len) { return;}
|
||||
|
||||
while (--len) { buf[len] = val}
|
||||
}
|
Loading…
Add table
Reference in a new issue