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 authored and UlisesGascon committed Dec 11, 2023
1 parent ea61261 commit 32d65c0
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/buffer.js
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 32d65c0

Please sign in to comment.