Skip to content

Commit

Permalink
lib: remove let from for loops
Browse files Browse the repository at this point in the history
This is a known de-opt. It may not be 100% necessary in all cases but it
seems like a decent enough idea to avoid it.

Ref: nodejs#9553
PR-URL: nodejs#8873
Reviewed-By: Brian White <mscdex@mscdex.net>
Reviewed-By: Ilkka Myller <ilkka.myller@nodefield.com>
Reviewed-By: Johan Bergström <bugs@bergstroem.nu>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
  • Loading branch information
Myles Borins committed Nov 11, 2016
1 parent 9a192a9 commit d7b9f36
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 15 deletions.
6 changes: 3 additions & 3 deletions lib/_stream_readable.js
Original file line number Diff line number Diff line change
Expand Up @@ -654,14 +654,14 @@ Readable.prototype.unpipe = function(dest) {
state.pipesCount = 0;
state.flowing = false;

for (let i = 0; i < len; i++)
for (var i = 0; i < len; i++)
dests[i].emit('unpipe', this);
return this;
}

// try to find the right one.
const i = state.pipes.indexOf(dest);
if (i === -1)
const index = state.pipes.indexOf(dest);
if (index === -1)
return this;

state.pipes.splice(i, 1);
Expand Down
10 changes: 6 additions & 4 deletions lib/_tls_common.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ exports.SecureContext = SecureContext;

exports.createSecureContext = function createSecureContext(options, context) {
if (!options) options = {};
var i;
var len;

var secureOptions = options.secureOptions;
if (options.honorCipherOrder)
Expand All @@ -47,7 +49,7 @@ exports.createSecureContext = function createSecureContext(options, context) {
// cert's issuer in C++ code.
if (options.ca) {
if (Array.isArray(options.ca)) {
for (let i = 0, len = options.ca.length; i < len; i++) {
for (i = 0, len = options.ca.length; i < len; i++) {
c.context.addCACert(options.ca[i]);
}
} else {
Expand All @@ -59,7 +61,7 @@ exports.createSecureContext = function createSecureContext(options, context) {

if (options.cert) {
if (Array.isArray(options.cert)) {
for (let i = 0; i < options.cert.length; i++)
for (i = 0; i < options.cert.length; i++)
c.context.setCert(options.cert[i]);
} else {
c.context.setCert(options.cert);
Expand All @@ -72,7 +74,7 @@ exports.createSecureContext = function createSecureContext(options, context) {
// which leads to the crash later on.
if (options.key) {
if (Array.isArray(options.key)) {
for (let i = 0; i < options.key.length; i++) {
for (i = 0; i < options.key.length; i++) {
var key = options.key[i];

if (key.passphrase)
Expand Down Expand Up @@ -103,7 +105,7 @@ exports.createSecureContext = function createSecureContext(options, context) {

if (options.crl) {
if (Array.isArray(options.crl)) {
for (let i = 0, len = options.crl.length; i < len; i++) {
for (i = 0, len = options.crl.length; i < len; i++) {
c.context.addCRL(options.crl[i]);
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ function REPLServer(prompt,

// After executing the current expression, store the values of RegExp
// predefined properties back in `savedRegExMatches`
for (let idx = 1; idx < savedRegExMatches.length; idx += 1) {
for (var idx = 1; idx < savedRegExMatches.length; idx += 1) {
savedRegExMatches[idx] = RegExp[`$${idx}`];
}

Expand Down
2 changes: 1 addition & 1 deletion lib/tls.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ function check(hostParts, pattern, wildcards) {
return false;

// Check host parts from right to left first.
for (let i = hostParts.length - 1; i > 0; i -= 1)
for (var i = hostParts.length - 1; i > 0; i -= 1)
if (hostParts[i] !== patternParts[i])
return false;

Expand Down
12 changes: 6 additions & 6 deletions lib/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) {
if (typeof url !== 'string') {
throw new TypeError("Parameter 'url' must be a string, not " + typeof url);
}

var i, j, k, l;
// Copy chrome, IE, opera backslash-handling behavior.
// Back slashes before the query string get converted to forward slashes
// See: https://code.google.com/p/chromium/issues/detail?id=25916
Expand Down Expand Up @@ -169,7 +169,7 @@ Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) {

// find the first instance of any hostEndingChars
var hostEnd = -1;
for (let i = 0; i < hostEndingChars.length; i++) {
for (i = 0; i < hostEndingChars.length; i++) {
const hec = rest.indexOf(hostEndingChars[i]);
if (hec !== -1 && (hostEnd === -1 || hec < hostEnd))
hostEnd = hec;
Expand Down Expand Up @@ -197,7 +197,7 @@ Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) {

// the host is the remaining to the left of the first non-host char
hostEnd = -1;
for (let i = 0; i < nonHostChars.length; i++) {
for (i = 0; i < nonHostChars.length; i++) {
const hec = rest.indexOf(nonHostChars[i]);
if (hec !== -1 && (hostEnd === -1 || hec < hostEnd))
hostEnd = hec;
Expand All @@ -224,12 +224,12 @@ Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) {
// validate a little.
if (!ipv6Hostname) {
var hostparts = this.hostname.split(/\./);
for (let i = 0, l = hostparts.length; i < l; i++) {
for (i = 0, l = hostparts.length; i < l; i++) {
var part = hostparts[i];
if (!part) continue;
if (!part.match(hostnamePartPattern)) {
var newpart = '';
for (let j = 0, k = part.length; j < k; j++) {
for (j = 0, k = part.length; j < k; j++) {
if (part.charCodeAt(j) > 127) {
// we replace non-ASCII char with a temporary placeholder
// we need this to make sure size of hostname is not
Expand Down Expand Up @@ -294,7 +294,7 @@ Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) {
// First, make 100% sure that any "autoEscape" chars get
// escaped, even if encodeURIComponent doesn't think they
// need to be.
for (let i = 0, l = autoEscape.length; i < l; i++) {
for (i = 0, l = autoEscape.length; i < l; i++) {
var ae = autoEscape[i];
if (rest.indexOf(ae) === -1)
continue;
Expand Down

0 comments on commit d7b9f36

Please sign in to comment.