diff options
author | Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> | 2023-03-21 13:03:41 +0000 |
---|---|---|
committer | Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> | 2023-03-21 13:03:41 +0000 |
commit | 6c2d5972f3544c4f3e987828a99e88f27b62cf87 (patch) | |
tree | 276783d4e29f3c05ed5e23257b33c65befbc911d /src | |
parent | 06820032142a75cc3c5b832045058bc6f6f74786 (diff) |
refactor: Use move semantics in `CCheckQueue::Add`
Co-authored-by: Martin Leitner-Ankerl <martin.ankerl@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/checkqueue.h | 6 | ||||
-rw-r--r-- | src/test/checkqueue_tests.cpp | 11 | ||||
-rw-r--r-- | src/test/fuzz/checkqueue.cpp | 2 |
3 files changed, 14 insertions, 5 deletions
diff --git a/src/checkqueue.h b/src/checkqueue.h index d83f717fb7..63628860c5 100644 --- a/src/checkqueue.h +++ b/src/checkqueue.h @@ -11,6 +11,7 @@ #include <util/threadnames.h> #include <algorithm> +#include <iterator> #include <vector> template <typename T> @@ -173,10 +174,7 @@ public: { LOCK(m_mutex); - for (T& check : vChecks) { - queue.emplace_back(); - check.swap(queue.back()); - } + queue.insert(queue.end(), std::make_move_iterator(vChecks.begin()), std::make_move_iterator(vChecks.end())); nTodo += vChecks.size(); } diff --git a/src/test/checkqueue_tests.cpp b/src/test/checkqueue_tests.cpp index 135f107159..90154c8757 100644 --- a/src/test/checkqueue_tests.cpp +++ b/src/test/checkqueue_tests.cpp @@ -140,6 +140,17 @@ struct FrozenCleanupCheck { cv.wait(l, []{ return nFrozen.load(std::memory_order_relaxed) == 0;}); } } + FrozenCleanupCheck(FrozenCleanupCheck&& other) noexcept + { + should_freeze = other.should_freeze; + other.should_freeze = false; + } + FrozenCleanupCheck& operator=(FrozenCleanupCheck&& other) noexcept + { + should_freeze = other.should_freeze; + other.should_freeze = false; + return *this; + } void swap(FrozenCleanupCheck& x) noexcept { std::swap(should_freeze, x.should_freeze); diff --git a/src/test/fuzz/checkqueue.cpp b/src/test/fuzz/checkqueue.cpp index 6256aefaa3..0c776e1b2f 100644 --- a/src/test/fuzz/checkqueue.cpp +++ b/src/test/fuzz/checkqueue.cpp @@ -13,7 +13,7 @@ namespace { struct DumbCheck { - const bool result = false; + bool result = false; DumbCheck() = default; |