Skip to content

Commit

Permalink
doc: add explanation why keep var with for loop
Browse files Browse the repository at this point in the history
This comment will help contributors to understand why keeping var
PR-URL: #30380
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
  • Loading branch information
lrecknagel authored and MylesBorins committed Dec 17, 2019
1 parent d138e2d commit c705a8e
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/internal/async_hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ function emitInitNative(asyncId, type, triggerAsyncId, resource) {
active_hooks.call_depth += 1;
// Use a single try/catch for all hooks to avoid setting up one per iteration.
try {
// Using var here instead of let because "for (var ...)" is faster than let.
// Refs: https://github.com/nodejs/node/pull/30380#issuecomment-552948364
for (var i = 0; i < active_hooks.array.length; i++) {
if (typeof active_hooks.array[i][init_symbol] === 'function') {
active_hooks.array[i][init_symbol](
Expand Down Expand Up @@ -159,6 +161,8 @@ function emitHook(symbol, asyncId) {
// Use a single try/catch for all hook to avoid setting up one per
// iteration.
try {
// Using var here instead of let because "for (var ...)" is faster than let.
// Refs: https://github.com/nodejs/node/pull/30380#issuecomment-552948364
for (var i = 0; i < active_hooks.array.length; i++) {
if (typeof active_hooks.array[i][symbol] === 'function') {
active_hooks.array[i][symbol](asyncId);
Expand Down

0 comments on commit c705a8e

Please sign in to comment.