From 34756ac3d43e71233953736206bf8af00d5cc2d1 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Fri, 4 Dec 2020 15:15:06 +0100 Subject: [PATCH] buffer: refactor to use primordials instead of Array#reduce MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/36392 Reviewed-By: Michaƫl Zasso Reviewed-By: Minwoo Jung --- lib/buffer.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/buffer.js b/lib/buffer.js index e902ad8d00bf14..b84078e04b3a57 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -24,6 +24,7 @@ const { Array, ArrayIsArray, + ArrayPrototypeForEach, Error, MathFloor, MathMin, @@ -825,11 +826,12 @@ Buffer.prototype[customInspectSymbol] = function inspect(recurseTimes, ctx) { if (ctx) { let extras = false; const filter = ctx.showHidden ? ALL_PROPERTIES : ONLY_ENUMERABLE; - const obj = getOwnNonIndexProperties(this, filter).reduce((obj, key) => { - extras = true; - obj[key] = this[key]; - return obj; - }, ObjectCreate(null)); + const obj = ObjectCreate(null); + ArrayPrototypeForEach(getOwnNonIndexProperties(this, filter), + (key) => { + extras = true; + obj[key] = this[key]; + }); if (extras) { if (this.length !== 0) str += ', ';