Skip to content

Commit bdf933b

Browse files
gareth-ellisevanlucas
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 2cbbaaf commit bdf933b

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

lib/buffer.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ function fromString(string, encoding) {
165165
function fromArrayLike(obj) {
166166
const length = obj.length;
167167
const b = allocate(length);
168-
for (let i = 0; i < length; i++)
168+
for (var i = 0; i < length; i++)
169169
b[i] = obj[i] & 255;
170170
return b;
171171
}
@@ -256,6 +256,7 @@ Buffer.isEncoding = function(encoding) {
256256

257257

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

@@ -264,15 +265,15 @@ Buffer.concat = function(list, length) {
264265

265266
if (length === undefined) {
266267
length = 0;
267-
for (let i = 0; i < list.length; i++)
268+
for (i = 0; i < list.length; i++)
268269
length += list[i].length;
269270
} else {
270271
length = length >>> 0;
271272
}
272273

273274
var buffer = Buffer.allocUnsafe(length);
274275
var pos = 0;
275-
for (let i = 0; i < list.length; i++) {
276+
for (i = 0; i < list.length; i++) {
276277
var buf = list[i];
277278
if (!Buffer.isBuffer(buf))
278279
throw new TypeError('list argument must be an Array of Buffers');

0 commit comments

Comments
 (0)