stream: avoid unnecessary concat of a single buffer.
authorCalvin Metcalf <cmetcalf@appgeo.com>
Fri, 9 Oct 2015 18:50:11 +0000 (14:50 -0400)
committerJames M Snell <jasnell@gmail.com>
Thu, 29 Oct 2015 15:38:40 +0000 (08:38 -0700)
Avoids doing a buffer.concat on the internal buffer
when that array has only a single thing in it.

Reviewed-By: Chris Dickinson <chris@neversaw.us>
Reviewed-By: James M Snell <jasnell@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/3300

lib/_stream_readable.js

index 5a37532..ab47830 100644 (file)
@@ -836,6 +836,8 @@ function fromList(n, state) {
     // read it all, truncate the array.
     if (stringMode)
       ret = list.join('');
+    else if (list.length === 1)
+      ret = list[0];
     else
       ret = Buffer.concat(list, length);
     list.length = 0;