Fixed spped degradation: set arrays sizes & data types

master
Vitaly Puzrin 2014-02-14 02:51:38 +04:00
rodzic 8341b4cf5c
commit f4c1a86ed9
2 zmienionych plików z 22 dodań i 7 usunięć

Wyświetl plik

@ -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);
}

Wyświetl plik

@ -1,6 +1,6 @@
'use strict';
exports.assign = function(obj /*from1, from2, from3, ...*/) {
exports.assign = function (obj /*from1, from2, from3, ...*/) {
var sources = Array.prototype.slice.call(arguments, 1);
while (sources.length) {
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
// 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')) {
return new Uint8Array(length);
@ -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}
}