buffer: improve Buffer.equals performance

PR-URL: https://github.com/nodejs/node/pull/50621
Refs: https://github.com/nodejs/node/issues/50620
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Debadree Chatterjee <debadree333@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
This commit is contained in:
kylo5aby 2023-11-10 17:45:14 +08:00 committed by GitHub
parent f662c9b63f
commit 89c66ae1eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -860,11 +860,11 @@ Buffer.prototype.equals = function equals(otherBuffer) {
if (this === otherBuffer)
return true;
if (this.byteLength !== otherBuffer.byteLength)
const len = TypedArrayPrototypeGetByteLength(this);
if (len !== TypedArrayPrototypeGetByteLength(otherBuffer))
return false;
return this.byteLength === 0 || _compare(this, otherBuffer) === 0;
return len === 0 || _compare(this, otherBuffer) === 0;
};
let INSPECT_MAX_BYTES = 50;