diff options
author | Jackson Tian <puling.tyq@alibaba-inc.com> | 2015-04-16 11:29:02 +0800 |
---|---|---|
committer | Brendan Ashworth <brendan.ashworth@me.com> | 2015-04-23 14:12:32 -0700 |
commit | 3d3083b91f02ca14acddde97612cec98e97ffe38 (patch) | |
tree | 88e50144aa6885c3b6d03ca25336542f621704c2 /lib | |
parent | bb254b533b1bfced8e39661485488f4a3f8969cc (diff) | |
download | node-new-3d3083b91f02ca14acddde97612cec98e97ffe38.tar.gz |
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>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/buffer.js | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/lib/buffer.js b/lib/buffer.js index 8f4e34d289..dc2b656d7a 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -247,6 +247,11 @@ Buffer.concat = function(list, length) { if (!Array.isArray(list)) 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) { length = 0; for (var i = 0; i < list.length; i++) @@ -255,11 +260,6 @@ Buffer.concat = function(list, length) { 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 pos = 0; for (var i = 0; i < list.length; i++) { |