Skip to content

Commit 96e163a

Browse files
gareth-ellisMyles Borins
authored andcommitted
buffer: changing let in for loops back to var
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
1 parent 8c24bd2 commit 96e163a

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

lib/buffer.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ function fromString(string, encoding) {
120120
function fromArrayLike(obj) {
121121
const length = obj.length;
122122
const b = allocate(length);
123-
for (let i = 0; i < length; i++)
123+
for (var i = 0; i < length; i++)
124124
b[i] = obj[i] & 255;
125125
return b;
126126
}
@@ -208,6 +208,7 @@ Buffer.isEncoding = function(encoding) {
208208

209209

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

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

217218
if (length === undefined) {
218219
length = 0;
219-
for (let i = 0; i < list.length; i++)
220+
for (i = 0; i < list.length; i++)
220221
length += list[i].length;
221222
} else {
222223
length = length >>> 0;
223224
}
224225

225226
var buffer = new Buffer(length);
226227
var pos = 0;
227-
for (let i = 0; i < list.length; i++) {
228+
for (i = 0; i < list.length; i++) {
228229
var buf = list[i];
229230
buf.copy(buffer, pos);
230231
pos += buf.length;

0 commit comments

Comments
 (0)