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 Beth Griggs committed 2020-04-14 11:03:19 +01:00
1 parent d515b95676
commit f9e2baebdf
1 file changed
+13 -9
+13 -9
View File
@@ -316,27 +316,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) {
@@ -350,13 +354,13 @@ function emitInitScript(asyncId, type, triggerAsyncId, resource) {
function emitBeforeScript(asyncId, triggerAsyncId, resource) {
pushAsyncContext(asyncId, triggerAsyncId, resource);
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);
popAsyncContext(asyncId);
@@ -365,7 +369,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);
}
@@ -382,7 +386,7 @@ function clearAsyncIdStack() {
function hasAsyncIdStack() {
return async_hook_fields[kStackLength] > 0;
return hasHooks(kStackLength);
}