From: Feross Aboukhadijeh Date: Wed, 4 Nov 2020 21:17:24 +0000 (-1000) Subject: avoid unnecessary buffer copy X-Git-Url: https://zoso.dev/?a=commitdiff_plain;h=411bd9a88158c488c99b624882c563f777442c63;p=buffer.git avoid unnecessary buffer copy --- 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,