mirror of
https://github.com/nodejs/node.git
synced 2026-10-14 10:26:26 -04:00
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:
1 parent
d937b029a9
commit
f0c8898fb5
3 files changed
+28
-1
No files matched your search
+5
-1
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user