From 0f7ca4ee9c9f6d2fc4dac09dde45a0be12054dbc Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Wed, 22 Apr 2015 10:40:33 +1000 Subject: [PATCH] index: avoid double-up of Math.pow --- index.js | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/index.js b/index.js index a814f87..c03eecd 100644 --- a/index.js +++ b/index.js @@ -951,13 +951,11 @@ Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) { value = +value - offset = offset >>> 0 + offset = offset | 0 if (!noAssert) { - checkInt( - this, value, offset, byteLength, - Math.pow(2, 8 * byteLength - 1) - 1, - -Math.pow(2, 8 * byteLength - 1) - ) + var limit = Math.pow(2, 8 * byteLength - 1) + + checkInt(this, value, offset, byteLength, limit - 1, -limit) } var i = 0 @@ -973,13 +971,11 @@ Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, no Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) { value = +value - offset = offset >>> 0 + offset = offset | 0 if (!noAssert) { - checkInt( - this, value, offset, byteLength, - Math.pow(2, 8 * byteLength - 1) - 1, - -Math.pow(2, 8 * byteLength - 1) - ) + var limit = Math.pow(2, 8 * byteLength - 1) + + checkInt(this, value, offset, byteLength, limit - 1, -limit) } var i = byteLength - 1 -- 2.34.1