summaryrefslogtreecommitdiff
path: root/lib/buffer.js
diff options
context:
space:
mode:
authorBrian White <mscdex@mscdex.net>2019-08-19 01:43:29 -0400
committerRich Trott <rtrott@gmail.com>2019-08-21 21:42:21 -0700
commitf0c8898fb5e8b133001bbea42f1288805d4d4802 (patch)
tree121504acd9465e9fb9d336aea8efe3db85328603 /lib/buffer.js
parentd937b029a99064514965def31ef226dc959e1597 (diff)
downloadnode-new-f0c8898fb5e8b133001bbea42f1288805d4d4802.tar.gz
buffer: improve equals() performance
PR-URL: https://github.com/nodejs/node/pull/29199 Reviewed-By: Michaƫl Zasso <targos@protonmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'lib/buffer.js')
-rw-r--r--lib/buffer.js6
1 files changed, 5 insertions, 1 deletions
diff --git a/lib/buffer.js b/lib/buffer.js
index 7b656496e5..7f33bcab5e 100644
--- a/lib/buffer.js
+++ b/lib/buffer.js
@@ -716,10 +716,14 @@ Buffer.prototype.equals = function equals(otherBuffer) {
throw new ERR_INVALID_ARG_TYPE(
'otherBuffer', ['Buffer', 'Uint8Array'], otherBuffer);
}
+
if (this === otherBuffer)
return true;
- return _compare(this, otherBuffer) === 0;
+ if (this.byteLength !== otherBuffer.byteLength)
+ return false;
+
+ return this.byteLength === 0 || _compare(this, otherBuffer) === 0;
};
let INSPECT_MAX_BYTES = 50;