mirror of https://github.com/nodejs/node.git
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: https://github.com/iojs/io.js/pull/1437 Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: Brendan Ashworth <brendan.ashworth@me.com>pull/1464/merge
parent
bb254b533b
commit
3d3083b91f
|
@ -247,6 +247,11 @@ Buffer.concat = function(list, length) {
|
||||||
if (!Array.isArray(list))
|
if (!Array.isArray(list))
|
||||||
throw new TypeError('list argument must be an Array of Buffers.');
|
throw new TypeError('list argument must be an Array of Buffers.');
|
||||||
|
|
||||||
|
if (list.length === 0)
|
||||||
|
return new Buffer(0);
|
||||||
|
else if (list.length === 1)
|
||||||
|
return list[0];
|
||||||
|
|
||||||
if (length === undefined) {
|
if (length === undefined) {
|
||||||
length = 0;
|
length = 0;
|
||||||
for (var i = 0; i < list.length; i++)
|
for (var i = 0; i < list.length; i++)
|
||||||
|
@ -255,11 +260,6 @@ Buffer.concat = function(list, length) {
|
||||||
length = length >>> 0;
|
length = length >>> 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (list.length === 0)
|
|
||||||
return new Buffer(0);
|
|
||||||
else if (list.length === 1)
|
|
||||||
return list[0];
|
|
||||||
|
|
||||||
var buffer = new Buffer(length);
|
var buffer = new Buffer(length);
|
||||||
var pos = 0;
|
var pos = 0;
|
||||||
for (var i = 0; i < list.length; i++) {
|
for (var i = 0; i < list.length; i++) {
|
||||||
|
|
Loading…
Reference in New Issue