diff options
author | Lucas Recknagel <lucas91@me.com> | 2019-11-12 15:01:10 +0000 |
---|---|---|
committer | Gireesh Punathil <gpunathi@in.ibm.com> | 2019-11-26 20:22:58 +0530 |
commit | 4506991aafa59f311024a7290b5195cf030cee7c (patch) | |
tree | f5d2d12087db7f75b1ef5e52aef1f3ec0cc02fb5 /lib/internal/async_hooks.js | |
parent | a2dfa3c4e42512d7e6d9efd090ff0514d1e9fc9c (diff) | |
download | node-new-4506991aafa59f311024a7290b5195cf030cee7c.tar.gz |
doc: add explanation why keep var with for loop
This comment will help contributors to understand why keeping var
PR-URL: https://github.com/nodejs/node/pull/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>
Diffstat (limited to 'lib/internal/async_hooks.js')
-rw-r--r-- | lib/internal/async_hooks.js | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/lib/internal/async_hooks.js b/lib/internal/async_hooks.js index d5d61bfb15..441b0bfb03 100644 --- a/lib/internal/async_hooks.js +++ b/lib/internal/async_hooks.js @@ -132,6 +132,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]( @@ -162,6 +164,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); |