Skip to content

Commit

Permalink
don't compare same buffers
Browse files Browse the repository at this point in the history
Copied from iojs: nodejs/node#742
  • Loading branch information
itu2n1i8w authored and feross committed Feb 10, 2015
1 parent a404864 commit a704fcf
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ Buffer.compare = function (a, b) {
if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b))
throw new TypeError('Arguments must be Buffers')

if (a === b) return 0

var x = a.length
var y = b.length
for (var i = 0, len = Math.min(x, y); i < len && a[i] === b[i]; i++) {}
Expand Down Expand Up @@ -289,6 +291,7 @@ Buffer.prototype.toString = function (encoding, start, end) {

Buffer.prototype.equals = function (b) {
if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')
if (this === b) return true
return Buffer.compare(this, b) === 0
}

Expand All @@ -305,6 +308,7 @@ Buffer.prototype.inspect = function () {

Buffer.prototype.compare = function (b) {
if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')
if (this === b) return 0
return Buffer.compare(this, b)
}

Expand Down

0 comments on commit a704fcf

Please sign in to comment.