Skip to content

Commit 5be20b4

Browse files
lrecknageltargos
authored andcommitted
doc: add explanation why keep var with for loop
This comment will help contributors to understand why keeping var PR-URL: #30380 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Gireesh Punathil <[email protected]>
1 parent 363391e commit 5be20b4

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

lib/internal/async_hooks.js

+4
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ function emitInitNative(asyncId, type, triggerAsyncId, resource) {
129129
active_hooks.call_depth += 1;
130130
// Use a single try/catch for all hooks to avoid setting up one per iteration.
131131
try {
132+
// Using var here instead of let because "for (var ...)" is faster than let.
133+
// Refs: https://github.com/nodejs/node/pull/30380#issuecomment-552948364
132134
for (var i = 0; i < active_hooks.array.length; i++) {
133135
if (typeof active_hooks.array[i][init_symbol] === 'function') {
134136
active_hooks.array[i][init_symbol](
@@ -159,6 +161,8 @@ function emitHook(symbol, asyncId) {
159161
// Use a single try/catch for all hook to avoid setting up one per
160162
// iteration.
161163
try {
164+
// Using var here instead of let because "for (var ...)" is faster than let.
165+
// Refs: https://github.com/nodejs/node/pull/30380#issuecomment-552948364
162166
for (var i = 0; i < active_hooks.array.length; i++) {
163167
if (typeof active_hooks.array[i][symbol] === 'function') {
164168
active_hooks.array[i][symbol](asyncId);

0 commit comments

Comments
 (0)