Skip to content

Commit 3d3083b

Browse files
JacksonTianbrendanashworth
authored andcommitted
buffer: little improve for Buffer.concat method
When buffer list less than 2, no need to calculate the length. The change's benchmark result is here: https://gist.github.com/JacksonTian/2c9e2bdec00018e010e6 It improve 15% ~ 25% speed when list only have one buffer, to other cases no effect. PR-URL: #1437 Reviewed-By: Trevor Norris <[email protected]> Reviewed-By: Brendan Ashworth <[email protected]>
1 parent bb254b5 commit 3d3083b

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

lib/buffer.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,11 @@ Buffer.concat = function(list, length) {
247247
if (!Array.isArray(list))
248248
throw new TypeError('list argument must be an Array of Buffers.');
249249

250+
if (list.length === 0)
251+
return new Buffer(0);
252+
else if (list.length === 1)
253+
return list[0];
254+
250255
if (length === undefined) {
251256
length = 0;
252257
for (var i = 0; i < list.length; i++)
@@ -255,11 +260,6 @@ Buffer.concat = function(list, length) {
255260
length = length >>> 0;
256261
}
257262

258-
if (list.length === 0)
259-
return new Buffer(0);
260-
else if (list.length === 1)
261-
return list[0];
262-
263263
var buffer = new Buffer(length);
264264
var pos = 0;
265265
for (var i = 0; i < list.length; i++) {

0 commit comments

Comments
 (0)