]> zoso.dev Git - buffer.git/commitdiff
avoid unnecessary buffer copy
authorFeross Aboukhadijeh <feross@feross.org>
Wed, 4 Nov 2020 21:17:24 +0000 (11:17 -1000)
committerFeross Aboukhadijeh <feross@feross.org>
Wed, 4 Nov 2020 21:17:24 +0000 (11:17 -1000)
index.js

index 96a4acb23d7a89e1337677576bb437d05b306374..7a0e9c2a123bc9d26c20bb3de4a3c4e49b24ee40 100644 (file)
--- 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,