From fef17b716d2c54818504f64646df1ac5c1f5b68d Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Wed, 24 Oct 2018 10:56:26 +0200 Subject: [PATCH] src: avoid extra `Persistent` in `DefaultTriggerAsyncIdScope` Instead of getting a reference to the main `AliasedBuffer`, which would always unnecesarily allocate and destroy a `Persistent` handle, store and use a reference to the owning object. PR-URL: https://github.com/nodejs/node/pull/23844 Reviewed-By: Matteo Collina Reviewed-By: Matheus Marchini Reviewed-By: Colin Ihrig Reviewed-By: James M Snell Reviewed-By: Anatoli Papirovski --- src/env-inl.h | 8 ++++---- src/env.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/env-inl.h b/src/env-inl.h index 9d369d492c1cd1..da8ca222b3361f 100644 --- a/src/env-inl.h +++ b/src/env-inl.h @@ -186,20 +186,20 @@ inline void Environment::AsyncHooks::clear_async_id_stack() { inline Environment::AsyncHooks::DefaultTriggerAsyncIdScope ::DefaultTriggerAsyncIdScope(Environment* env, double default_trigger_async_id) - : async_id_fields_ref_(env->async_hooks()->async_id_fields()) { + : async_hooks_(env->async_hooks()) { if (env->async_hooks()->fields()[AsyncHooks::kCheck] > 0) { CHECK_GE(default_trigger_async_id, 0); } old_default_trigger_async_id_ = - async_id_fields_ref_[AsyncHooks::kDefaultTriggerAsyncId]; - async_id_fields_ref_[AsyncHooks::kDefaultTriggerAsyncId] = + async_hooks_->async_id_fields()[AsyncHooks::kDefaultTriggerAsyncId]; + async_hooks_->async_id_fields()[AsyncHooks::kDefaultTriggerAsyncId] = default_trigger_async_id; } inline Environment::AsyncHooks::DefaultTriggerAsyncIdScope ::~DefaultTriggerAsyncIdScope() { - async_id_fields_ref_[AsyncHooks::kDefaultTriggerAsyncId] = + async_hooks_->async_id_fields()[AsyncHooks::kDefaultTriggerAsyncId] = old_default_trigger_async_id_; } diff --git a/src/env.h b/src/env.h index a85058f895a4d8..e2aec13764b139 100644 --- a/src/env.h +++ b/src/env.h @@ -487,7 +487,7 @@ class Environment { ~DefaultTriggerAsyncIdScope(); private: - AliasedBuffer async_id_fields_ref_; + AsyncHooks* async_hooks_; double old_default_trigger_async_id_; DISALLOW_COPY_AND_ASSIGN(DefaultTriggerAsyncIdScope);