From d61cb9c799db4698b58c37bc61f3a99606cdda0b Mon Sep 17 00:00:00 2001 From: zhenweijin Date: Wed, 8 Nov 2023 12:40:33 +0800 Subject: [PATCH] buffer: improve Buffer.equals performance --- lib/buffer.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/buffer.js b/lib/buffer.js index ee30c69cc9611c..ee8b87a191ddbd 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -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;