diff --git a/lib/zlib/deflate.js b/lib/zlib/deflate.js index 7691a91..33e3a6f 100644 --- a/lib/zlib/deflate.js +++ b/lib/zlib/deflate.js @@ -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) { diff --git a/lib/zlib/utils.js b/lib/zlib/utils.js index f1546f5..0f3fd9f 100644 --- a/lib/zlib/utils.js +++ b/lib/zlib/utils.js @@ -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} -} \ No newline at end of file + while (--len) { buf[len] = val; } +};