Skip to content

Commit

Permalink
buffer: changing let in for loops back to var
Browse files Browse the repository at this point in the history
Using let in for loops showed a regression in 4.4.0. @ofrobots
suggested that we avoid using let in for loops until TurboFan becomes
the default optimiser.

The regression that was detected was when looking at how long it took
to create a new buffer from an array of data.

When using `for (let i=0; i<length; i++) ` we saw the operation take
almost 40% longer compared to `var i=0`.

PR-URL: #5819
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Michael Dawson <[email protected]>
Reviewed-By: Jeremiah Senkpiel <[email protected]>
Reviewed-By: Trevor Norris <[email protected]>
Reviewed-By: Myles Borins <[email protected]>
Ref: http://github.com/nodejs/benchmarking/issues/38
  • Loading branch information
gareth-ellis authored and Myles Borins committed Mar 30, 2016
1 parent 8c24bd2 commit 96e163a
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ function fromString(string, encoding) {
function fromArrayLike(obj) {
const length = obj.length;
const b = allocate(length);
for (let i = 0; i < length; i++)
for (var i = 0; i < length; i++)
b[i] = obj[i] & 255;
return b;
}
Expand Down Expand Up @@ -208,6 +208,7 @@ Buffer.isEncoding = function(encoding) {


Buffer.concat = function(list, length) {
var i;
if (!Array.isArray(list))
throw new TypeError('list argument must be an Array of Buffers.');

Expand All @@ -216,15 +217,15 @@ Buffer.concat = function(list, length) {

if (length === undefined) {
length = 0;
for (let i = 0; i < list.length; i++)
for (i = 0; i < list.length; i++)
length += list[i].length;
} else {
length = length >>> 0;
}

var buffer = new Buffer(length);
var pos = 0;
for (let i = 0; i < list.length; i++) {
for (i = 0; i < list.length; i++) {
var buf = list[i];
buf.copy(buffer, pos);
pos += buf.length;
Expand Down

0 comments on commit 96e163a

Please sign in to comment.