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: https://github.com/nodejs/node/pull/5819
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Trevor Norris <trevnorris@gmail.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
Ref: http://github.com/nodejs/benchmarking/issues/38
This commit is contained in:
Gareth Ellis 2016-03-21 09:46:42 +00:00 committed by Benjamin Gruenbaum
parent 387b6b4973
commit 443c2d5442

View File

@ -185,7 +185,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;
}
@ -276,6 +276,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');
@ -284,7 +285,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;
@ -292,7 +293,7 @@ Buffer.concat = function(list, length) {
var buffer = Buffer.allocUnsafe(length);
var pos = 0;
for (let i = 0; i < list.length; i++) {
for (i = 0; i < list.length; i++) {
var buf = list[i];
if (!Buffer.isBuffer(buf))
throw new TypeError('"list" argument must be an Array of Buffers');