From 96e163a79f15c47663a9505f25b3d9ca0b30f71c Mon Sep 17 00:00:00 2001 From: Gareth Ellis Date: Mon, 21 Mar 2016 09:46:42 +0000 Subject: [PATCH] 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 Reviewed-By: Michael Dawson Reviewed-By: Jeremiah Senkpiel Reviewed-By: Trevor Norris Reviewed-By: Myles Borins Ref: http://github.com/nodejs/benchmarking/issues/38 --- lib/buffer.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/buffer.js b/lib/buffer.js index f8ab2b22282338..a24bdd0e006f9f 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -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; } @@ -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.'); @@ -216,7 +217,7 @@ 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; @@ -224,7 +225,7 @@ Buffer.concat = function(list, length) { 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;