From ffccb1a5daf3c4bca0bf8cba66d7947bd2805767 Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Mon, 9 Feb 2015 18:21:08 -0800 Subject: [PATCH] don't compare same buffers Copied from iojs: https://github.com/iojs/io.js/pull/742 --- index.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/index.js b/index.js index 78f74f2..21c8a09 100644 --- a/index.js +++ b/index.js @@ -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++) {} @@ -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 } @@ -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) } -- 2.34.1