Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit bdf933b

Browse filesBrowse 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 <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
1 parent 2cbbaaf commit bdf933b
Copy full SHA for bdf933b

File tree

Expand file treeCollapse file tree

1 file changed

+4
-3
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+4
-3
lines changed
Open diff view settings
Collapse file

‎lib/buffer.js‎

Copy file name to clipboardExpand all lines: lib/buffer.js
+4-3Lines changed: 4 additions & 3 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.