async_hooks: use hasHooks function internally

PR-URL: https://github.com/nodejs/node/pull/32656
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
rickyes authored and Michaël Zasso committed 2020-04-22 19:42:21 +02:00
1 parent 2cf7381a87
commit 2c5b0147fa
1 file changed
+13 -9
+13 -9
View File
@@ -299,27 +299,31 @@ function defaultTriggerAsyncIdScope(triggerAsyncId, block, ...args) {
}
}
function hasHooks(key) {
return async_hook_fields[key] > 0;
}
function enabledHooksExist() {
return async_hook_fields[kCheck] > 0;
return hasHooks(kCheck);
}
function initHooksExist() {
return async_hook_fields[kInit] > 0;
return hasHooks(kInit);
}
function afterHooksExist() {
return async_hook_fields[kAfter] > 0;
return hasHooks(kAfter);
}
function destroyHooksExist() {
return async_hook_fields[kDestroy] > 0;
return hasHooks(kDestroy);
}
function emitInitScript(asyncId, type, triggerAsyncId, resource) {
// Short circuit all checks for the common case. Which is that no hooks have
// been set. Do this to remove performance impact for embedders (and core).
if (async_hook_fields[kInit] === 0)
if (!hasHooks(kInit))
return;
if (triggerAsyncId === null) {
@@ -333,13 +337,13 @@ function emitInitScript(asyncId, type, triggerAsyncId, resource) {
function emitBeforeScript(asyncId, triggerAsyncId) {
pushAsyncIds(asyncId, triggerAsyncId);
if (async_hook_fields[kBefore] > 0)
if (hasHooks(kBefore))
emitBeforeNative(asyncId);
}
function emitAfterScript(asyncId) {
if (async_hook_fields[kAfter] > 0)
if (hasHooks(kAfter))
emitAfterNative(asyncId);
popAsyncIds(asyncId);
@@ -348,7 +352,7 @@ function emitAfterScript(asyncId) {
function emitDestroyScript(asyncId) {
// Return early if there are no destroy callbacks, or invalid asyncId.
if (async_hook_fields[kDestroy] === 0 || asyncId <= 0)
if (!hasHooks(kDestroy) || asyncId <= 0)
return;
async_wrap.queueDestroyAsyncId(asyncId);
}
@@ -364,7 +368,7 @@ function clearAsyncIdStack() {
function hasAsyncIdStack() {
return async_hook_fields[kStackLength] > 0;
return hasHooks(kStackLength);
}