Skip to content

node-api: use container swap in DrainFinalizerQueue to reduce erase overhead #57861

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/node_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,12 @@ void node_napi_env__::EnqueueFinalizer(v8impl::RefTracker* finalizer) {

void node_napi_env__::DrainFinalizerQueue() {
// As userland code can delete additional references in one finalizer,
// the list of pending finalizers may be mutated as we execute them, so
// we keep iterating it until it is empty.
// the list of pending finalizers may be mutated as we execute them
// (items may be added or removed), so keep iterating until it is empty.
while (!pending_finalizers.empty()) {
v8impl::RefTracker* ref_tracker = *pending_finalizers.begin();
pending_finalizers.erase(ref_tracker);
auto it = pending_finalizers.begin();
v8impl::RefTracker* ref_tracker = *it;
pending_finalizers.erase(it);
ref_tracker->Finalize();
}
}
Expand Down
Loading