From 55501c4cdf07e729a100e4ad152ab8970bd4d5df Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Sun, 12 Aug 2018 08:47:50 -0400 Subject: [PATCH] code review of pure-js implementation of lz4 --- src/lib/lz4/lz4-block-codec-js.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/lib/lz4/lz4-block-codec-js.js b/src/lib/lz4/lz4-block-codec-js.js index c2696a714..0fa36b7fe 100644 --- a/src/lib/lz4/lz4-block-codec-js.js +++ b/src/lib/lz4/lz4-block-codec-js.js @@ -59,7 +59,7 @@ let growOutputBuffer = function(instance, size) { let encodeBound = function(size) { return size > 0x7E000000 ? 0 : - size + size / 255 + 16; + size + (size / 255 | 0) + 16; }; let encodeBlock = function(instance, iBuf, oOffset) { @@ -81,9 +81,8 @@ let encodeBlock = function(instance, iBuf, oOffset) { iBuf = new Uint8Array(iBuf); } - let oBuf = new Uint8Array( - growOutputBuffer(instance, oOffset + encodeBound(iLen)) - ); + let oLen = oOffset + encodeBound(iLen); + let oBuf = new Uint8Array(growOutputBuffer(instance, oLen), 0, oLen); let iPos = 0; let oPos = oOffset; let anchorPos = 0; @@ -186,7 +185,7 @@ let encodeBlock = function(instance, iBuf, oOffset) { let decodeBlock = function(instance, iBuf, iOffset, oLen) { let iLen = iBuf.byteLength; - let oBuf = new Uint8Array(growOutputBuffer(instance, oLen)); + let oBuf = new Uint8Array(growOutputBuffer(instance, oLen), 0, oLen); let iPos = iOffset, oPos = 0; while ( iPos < iLen ) {