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>
This commit is contained in:
Brian White authored and Rich Trott committed 2019-08-21 21:42:21 -07:00
1 parent d937b029a9
commit f0c8898fb5
3 files changed
+28 -1

No files matched your search

+5 -1
View File
@@ -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;