mirror of
https://github.com/0x5eal/rbxts-pako.git
synced 2025-05-04 10:33:48 +01:00
Shrink untyped arrays more effectively
This commit is contained in:
parent
6b5edb3b34
commit
aa281b06ed
2 changed files with 6 additions and 4 deletions
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Reference in a new issue