Skip to content

Commit

Permalink
buffer: improve Buffer.equals performance
Browse files Browse the repository at this point in the history
PR-URL: #50621
Refs: #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>
  • Loading branch information
kylo5aby committed Nov 10, 2023
1 parent f662c9b commit 89c66ae
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 89c66ae

Please sign in to comment.