mirror of
https://github.com/0x5eal/rbxts-pako.git
synced 2025-04-08 21:01:00 +01:00
More speed boost: use typed array for hash tables
This commit is contained in:
parent
f4c1a86ed9
commit
a9c5e58eea
2 changed files with 16 additions and 4 deletions
|
@ -660,8 +660,8 @@ function deflateInit2(strm, level, method, windowBits, memLevel, 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);
|
||||
s.head = utils.array16Create(s.hash_size);
|
||||
s.prev = utils.array16Create(s.w_size);
|
||||
utils.fill(s.head, 0);
|
||||
utils.fill(s.prev, 0);
|
||||
|
||||
|
@ -804,6 +804,7 @@ function deflate(strm, flush) {
|
|||
*/
|
||||
if (flush === c.Z_FULL_FLUSH) {
|
||||
//CLEAR_HASH(s); /* forget history */
|
||||
// !!!! seems to be bug -> 0 in original
|
||||
s.head[s.hash_size - 1] = -1;
|
||||
|
||||
if (s.lookahead === 0) {
|
||||
|
|
|
@ -56,10 +56,21 @@ exports.arrayCreate = function (length) {
|
|||
};
|
||||
|
||||
|
||||
exports.array16Create = function (length) {
|
||||
|
||||
if ((typeof Uint16Array !== 'undefined')) {
|
||||
return new Uint16Array(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}
|
||||
}
|
||||
while (--len) { buf[len] = val; }
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue