Shrink untyped arrays more effectively

This commit is contained in:
Vitaly Puzrin 2014-03-12 03:09:11 +04:00
parent 6b5edb3b34
commit aa281b06ed
2 changed files with 6 additions and 4 deletions

View file

@ -28,8 +28,9 @@ var Z_DEFLATED = 8;
// return sliced buffer, trying to avoid new objects creation and mem copy // return sliced buffer, trying to avoid new objects creation and mem copy
function sliceBuf(buf, size) { function sliceBuf(buf, size) {
if (buf.length === size) { return buf; } if (buf.length === size) { return buf; }
if (utils.typedOk()) { return buf.subarray(0, size); }
return utils.typedOk() ? buf.subarray(0, size) : buf.slice(0, size); buf.length = size;
return buf;
} }
/** /**

View file

@ -10,8 +10,9 @@ var zstream = require('./zlib/zstream');
// return sliced buffer, trying to avoid new objects creation and mem copy // return sliced buffer, trying to avoid new objects creation and mem copy
function sliceBuf(buf, size) { function sliceBuf(buf, size) {
if (buf.length === size) { return buf; } if (buf.length === size) { return buf; }
if (utils.typedOk()) { return buf.subarray(0, size); }
return utils.typedOk() ? buf.subarray(0, size) : buf.slice(0, size); buf.length = size;
return buf;
} }
/** /**