Skip to content

Commit ad84558

Browse files
authored
Revert "src: modernize cleanup queue to use c++20"
This reverts commit 581b444. PR-URL: #56846 Refs: #56063 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 0a4672e commit ad84558

File tree

3 files changed

+13
-25
lines changed

3 files changed

+13
-25
lines changed

src/cleanup_queue-inl.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33

44
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
55

6-
#include <compare>
7-
86
#include "cleanup_queue.h"
97
#include "util.h"
108

@@ -31,18 +29,6 @@ void CleanupQueue::Remove(Callback cb, void* arg) {
3129
cleanup_hooks_.erase(search);
3230
}
3331

34-
constexpr std::strong_ordering CleanupQueue::CleanupHookCallback::operator<=>(
35-
const CleanupHookCallback& other) const noexcept {
36-
if (insertion_order_counter_ > other.insertion_order_counter_) {
37-
return std::strong_ordering::greater;
38-
}
39-
40-
if (insertion_order_counter_ < other.insertion_order_counter_) {
41-
return std::strong_ordering::less;
42-
}
43-
return std::strong_ordering::equivalent;
44-
}
45-
4632
} // namespace node
4733

4834
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS

src/cleanup_queue.cc

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
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 {
98
std::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

2327
void 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;

src/cleanup_queue.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
55

6-
#include <compare>
76
#include <cstddef>
87
#include <cstdint>
98
#include <unordered_set>
@@ -42,9 +41,6 @@ class CleanupQueue : public MemoryRetainer {
4241
arg_(arg),
4342
insertion_order_counter_(insertion_order_counter) {}
4443

45-
constexpr std::strong_ordering operator<=>(
46-
const CleanupHookCallback& other) const noexcept;
47-
4844
// Only hashes `arg_`, since that is usually enough to identify the hook.
4945
struct Hash {
5046
size_t operator()(const CleanupHookCallback& cb) const;

0 commit comments

Comments
 (0)