From: Daniel Cousens Date: Wed, 22 Apr 2015 00:29:27 +0000 (+1000) Subject: index: use consistentyl |0 over >>>0 for asm X-Git-Url: https://zoso.dev/?a=commitdiff_plain;h=d20fb7390777449fe16c952e3cf0b699c00a35e5;p=buffer.git index: use consistentyl |0 over >>>0 for asm --- diff --git a/index.js b/index.js index 935ab99..a814f87 100644 --- a/index.js +++ b/index.js @@ -206,7 +206,7 @@ function checked (length) { throw new RangeError('Attempt to allocate Buffer larger than maximum ' + 'size: 0x' + kMaxLength.toString(16) + ' bytes') } - return length >>> 0 + return length | 0 } function SlowBuffer (subject, encoding) { @@ -322,8 +322,8 @@ Buffer.prototype.parent = undefined Buffer.prototype.toString = function toString (encoding, start, end) { var loweredCase = false - start = start >>> 0 - end = end === undefined || end === Infinity ? this.length : end >>> 0 + start = start | 0 + end = end === undefined || end === Infinity ? this.length : end | 0 if (!encoding) encoding = 'utf8' if (start < 0) start = 0 @@ -497,9 +497,9 @@ Buffer.prototype.write = function write (string, offset, length, encoding) { offset = 0 // Buffer#write(string, offset[, length][, encoding]) } else if (isFinite(offset)) { - offset = offset >>> 0 + offset = offset | 0 if (isFinite(length)) { - length = length >>> 0 + length = length | 0 if (encoding === undefined) encoding = 'utf8' } else { encoding = length @@ -509,7 +509,7 @@ Buffer.prototype.write = function write (string, offset, length, encoding) { } else { var swap = encoding encoding = offset - offset = length >>> 0 + offset = length | 0 length = swap } @@ -676,8 +676,8 @@ function checkOffset (offset, ext, length) { } Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) { - offset = offset >>> 0 - byteLength = byteLength >>> 0 + offset = offset | 0 + byteLength = byteLength | 0 if (!noAssert) checkOffset(offset, byteLength, this.length) var val = this[offset] @@ -691,8 +691,8 @@ Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) } Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) { - offset = offset >>> 0 - byteLength = byteLength >>> 0 + offset = offset | 0 + byteLength = byteLength | 0 if (!noAssert) { checkOffset(offset, byteLength, this.length) } @@ -740,8 +740,8 @@ Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) { } Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) { - offset = offset >>> 0 - byteLength = byteLength >>> 0 + offset = offset | 0 + byteLength = byteLength | 0 if (!noAssert) checkOffset(offset, byteLength, this.length) var val = this[offset] @@ -758,8 +758,8 @@ Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) { } Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) { - offset = offset >>> 0 - byteLength = byteLength >>> 0 + offset = offset | 0 + byteLength = byteLength | 0 if (!noAssert) checkOffset(offset, byteLength, this.length) var i = byteLength @@ -839,15 +839,15 @@ function checkInt (buf, value, offset, ext, max, min) { Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) { value = +value - offset = offset >>> 0 - byteLength = byteLength >>> 0 + offset = offset | 0 + byteLength = byteLength | 0 if (!noAssert) checkInt(this, value, offset, byteLength, Math.pow(2, 8 * byteLength), 0) var mul = 1 var i = 0 this[offset] = value & 0xFF while (++i < byteLength && (mul *= 0x100)) { - this[offset + i] = (value / mul) >>> 0 & 0xFF + this[offset + i] = (value / mul) & 0xFF } return offset + byteLength @@ -855,15 +855,15 @@ Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) { value = +value - offset = offset >>> 0 - byteLength = byteLength >>> 0 + offset = offset | 0 + byteLength = byteLength | 0 if (!noAssert) checkInt(this, value, offset, byteLength, Math.pow(2, 8 * byteLength), 0) var i = byteLength - 1 var mul = 1 this[offset + i] = value & 0xFF while (--i >= 0 && (mul *= 0x100)) { - this[offset + i] = (value / mul) >>> 0 & 0xFF + this[offset + i] = (value / mul) & 0xFF } return offset + byteLength @@ -871,7 +871,7 @@ Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) { value = +value - offset = offset >>> 0 + offset = offset | 0 if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0) if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value) this[offset] = value @@ -888,7 +888,7 @@ function objectWriteUInt16 (buf, value, offset, littleEndian) { Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) { value = +value - offset = offset >>> 0 + offset = offset | 0 if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0) if (Buffer.TYPED_ARRAY_SUPPORT) { this[offset] = value @@ -901,7 +901,7 @@ Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) { value = +value - offset = offset >>> 0 + offset = offset | 0 if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0) if (Buffer.TYPED_ARRAY_SUPPORT) { this[offset] = (value >>> 8) @@ -921,7 +921,7 @@ function objectWriteUInt32 (buf, value, offset, littleEndian) { Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) { value = +value - offset = offset >>> 0 + offset = offset | 0 if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0) if (Buffer.TYPED_ARRAY_SUPPORT) { this[offset + 3] = (value >>> 24) @@ -936,7 +936,7 @@ Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) { value = +value - offset = offset >>> 0 + offset = offset | 0 if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0) if (Buffer.TYPED_ARRAY_SUPPORT) { this[offset] = (value >>> 24) @@ -995,7 +995,7 @@ Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, no Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) { value = +value - offset = offset >>> 0 + offset = offset | 0 if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80) if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value) if (value < 0) value = 0xff + value + 1 @@ -1005,7 +1005,7 @@ Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) { Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) { value = +value - offset = offset >>> 0 + offset = offset | 0 if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000) if (Buffer.TYPED_ARRAY_SUPPORT) { this[offset] = value @@ -1018,7 +1018,7 @@ Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) { value = +value - offset = offset >>> 0 + offset = offset | 0 if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000) if (Buffer.TYPED_ARRAY_SUPPORT) { this[offset] = (value >>> 8) @@ -1031,7 +1031,7 @@ Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) { value = +value - offset = offset >>> 0 + offset = offset | 0 if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000) if (Buffer.TYPED_ARRAY_SUPPORT) { this[offset] = value @@ -1046,7 +1046,7 @@ Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) { value = +value - offset = offset >>> 0 + offset = offset | 0 if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000) if (value < 0) value = 0xffffffff + value + 1 if (Buffer.TYPED_ARRAY_SUPPORT) {