mirror of
https://github.com/0x5eal/rbxts-pako.git
synced 2025-04-16 09:53:47 +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.)
|
zlib, so we don't care about this pathological case.)
|
||||||
*/
|
*/
|
||||||
n = s.hash_size;
|
n = s.hash_size;
|
||||||
p = s.head[n];
|
p = n;
|
||||||
do {
|
do {
|
||||||
m = s.head[--p];
|
m = s.head[--p];
|
||||||
s.head[p] = m >= wsize ? m - wsize : 0;
|
s.head[p] = m >= wsize ? m - wsize : 0;
|
||||||
|
@ -179,7 +179,7 @@ function fill_window(s) {
|
||||||
|
|
||||||
n = wsize;
|
n = wsize;
|
||||||
if (FASTEST) {
|
if (FASTEST) {
|
||||||
p = s.prev[n];
|
p = n;
|
||||||
do {
|
do {
|
||||||
m = s.head[--p];
|
m = s.head[--p];
|
||||||
s.head[p] = m >= wsize ? m - wsize : 0;
|
s.head[p] = m >= wsize ? m - wsize : 0;
|
||||||
|
@ -499,13 +499,13 @@ function DeflateState() {
|
||||||
* is directly used as sliding window.
|
* 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
|
/* 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.
|
* 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.
|
* 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. */
|
/* Heads of the hash chains or NIL. */
|
||||||
|
|
||||||
this.ins_h = 0;
|
this.ins_h = 0;
|
||||||
|
@ -659,6 +659,12 @@ function deflateInit2(strm, level, method, windowBits, memLevel, strategy) {
|
||||||
s.strategy = strategy;
|
s.strategy = strategy;
|
||||||
s.method = method;
|
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);
|
return deflateReset(strm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
exports.assign = function(obj /*from1, from2, from3, ...*/) {
|
exports.assign = function (obj /*from1, from2, from3, ...*/) {
|
||||||
var sources = Array.prototype.slice.call(arguments, 1);
|
var sources = Array.prototype.slice.call(arguments, 1);
|
||||||
while (sources.length) {
|
while (sources.length) {
|
||||||
var source = sources.shift();
|
var source = sources.shift();
|
||||||
|
@ -21,7 +21,7 @@ exports.assign = function(obj /*from1, from2, from3, ...*/) {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
exports.arraySet = function(dest, src, src_offs, len, dest_offs) {
|
exports.arraySet = function (dest, src, src_offs, len, dest_offs) {
|
||||||
|
|
||||||
// Suppose, that with typed array support destination is
|
// Suppose, that with typed array support destination is
|
||||||
// always typed - don't check it
|
// always typed - don't check it
|
||||||
|
@ -45,7 +45,7 @@ exports.arraySet = function(dest, src, src_offs, len, dest_offs) {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
exports.arrayCreate = function(length) {
|
exports.arrayCreate = function (length) {
|
||||||
|
|
||||||
if ((typeof Uint8Array !== 'undefined')) {
|
if ((typeof Uint8Array !== 'undefined')) {
|
||||||
return new Uint8Array(length);
|
return new Uint8Array(length);
|
||||||
|
@ -54,3 +54,12 @@ exports.arrayCreate = function(length) {
|
||||||
// Fallback to ordinary array
|
// Fallback to ordinary array
|
||||||
return new Array(length);
|
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