From 411bd9a88158c488c99b624882c563f777442c63 Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Wed, 4 Nov 2020 11:17:24 -1000 Subject: [PATCH] avoid unnecessary buffer copy --- index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 96a4acb..7a0e9c2 100644 --- a/index.js +++ b/index.js @@ -407,10 +407,11 @@ Buffer.concat = function concat (list, length) { const buffer = Buffer.allocUnsafe(length) let pos = 0 for (i = 0; i < list.length; ++i) { - const buf = list[i] + let buf = list[i] if (isInstance(buf, Uint8Array)) { if (pos + buf.length > buffer.length) { - Buffer.from(buf).copy(buffer, pos) + if (!Buffer.isBuffer(buf)) buf = Buffer.from(buf) + buf.copy(buffer, pos) } else { Uint8Array.prototype.set.call( buffer, -- 2.34.1