11#include " cleanup_queue.h" // NOLINT(build/include_inline)
22#include < algorithm>
3- #include < ranges>
43#include < vector>
54#include " cleanup_queue-inl.h"
65
@@ -9,20 +8,27 @@ namespace node {
98std::vector<CleanupQueue::CleanupHookCallback> CleanupQueue::GetOrdered ()
109 const {
1110 // Copy into a vector, since we can't sort an unordered_set in-place.
12- std::vector callbacks (cleanup_hooks_.begin (), cleanup_hooks_.end ());
11+ std::vector<CleanupHookCallback> callbacks (cleanup_hooks_.begin (),
12+ cleanup_hooks_.end ());
1313 // We can't erase the copied elements from `cleanup_hooks_` yet, because we
1414 // need to be able to check whether they were un-scheduled by another hook.
1515
16- // Sort in descending order so that the most recently inserted callbacks are
17- // run first.
18- std::ranges::sort (callbacks, std::greater ());
16+ std::sort (callbacks.begin (),
17+ callbacks.end (),
18+ [](const CleanupHookCallback& a, const CleanupHookCallback& b) {
19+ // Sort in descending order so that the most recently inserted
20+ // callbacks are run first.
21+ return a.insertion_order_counter_ > b.insertion_order_counter_ ;
22+ });
1923
2024 return callbacks;
2125}
2226
2327void CleanupQueue::Drain () {
24- for (const CleanupHookCallback& cb : GetOrdered ()) {
25- if (!cleanup_hooks_.contains (cb)) {
28+ std::vector<CleanupHookCallback> callbacks = GetOrdered ();
29+
30+ for (const CleanupHookCallback& cb : callbacks) {
31+ if (cleanup_hooks_.count (cb) == 0 ) {
2632 // This hook was removed from the `cleanup_hooks_` set during another
2733 // hook that was run earlier. Nothing to do here.
2834 continue ;
0 commit comments