Skip to content

Commit

Permalink
src: avoid extra Persistent in DefaultTriggerAsyncIdScope
Browse files Browse the repository at this point in the history
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: #23844
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Matheus Marchini <mat@mmarchini.me>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
  • Loading branch information
addaleax authored and targos committed Nov 1, 2018
1 parent 22caa26 commit fef17b7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/env-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
}

Expand Down
2 changes: 1 addition & 1 deletion src/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ class Environment {
~DefaultTriggerAsyncIdScope();

private:
AliasedBuffer<double, v8::Float64Array> async_id_fields_ref_;
AsyncHooks* async_hooks_;
double old_default_trigger_async_id_;

DISALLOW_COPY_AND_ASSIGN(DefaultTriggerAsyncIdScope);
Expand Down

0 comments on commit fef17b7

Please sign in to comment.