Skip to content

Commit 8459a48

Browse files
kylo5abytargos
authored andcommitted
buffer: improve Buffer.equals performance
PR-URL: #50621 Refs: #50620 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Debadree Chatterjee <[email protected]> Reviewed-By: Darshan Sen <[email protected]>
1 parent 924b331 commit 8459a48

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

lib/buffer.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -860,11 +860,11 @@ Buffer.prototype.equals = function equals(otherBuffer) {
860860

861861
if (this === otherBuffer)
862862
return true;
863-
864-
if (this.byteLength !== otherBuffer.byteLength)
863+
const len = TypedArrayPrototypeGetByteLength(this);
864+
if (len !== TypedArrayPrototypeGetByteLength(otherBuffer))
865865
return false;
866866

867-
return this.byteLength === 0 || _compare(this, otherBuffer) === 0;
867+
return len === 0 || _compare(this, otherBuffer) === 0;
868868
};
869869

870870
let INSPECT_MAX_BYTES = 50;

0 commit comments

Comments
 (0)