Skip to content

Commit 6c2d597

Browse files
hebastomartinus
andcommitted
refactor: Use move semantics in CCheckQueue::Add
Co-authored-by: Martin Leitner-Ankerl <[email protected]>
1 parent 0682003 commit 6c2d597

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

src/checkqueue.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <util/threadnames.h>
1212

1313
#include <algorithm>
14+
#include <iterator>
1415
#include <vector>
1516

1617
template <typename T>
@@ -173,10 +174,7 @@ class CCheckQueue
173174

174175
{
175176
LOCK(m_mutex);
176-
for (T& check : vChecks) {
177-
queue.emplace_back();
178-
check.swap(queue.back());
179-
}
177+
queue.insert(queue.end(), std::make_move_iterator(vChecks.begin()), std::make_move_iterator(vChecks.end()));
180178
nTodo += vChecks.size();
181179
}
182180

src/test/checkqueue_tests.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,17 @@ struct FrozenCleanupCheck {
140140
cv.wait(l, []{ return nFrozen.load(std::memory_order_relaxed) == 0;});
141141
}
142142
}
143+
FrozenCleanupCheck(FrozenCleanupCheck&& other) noexcept
144+
{
145+
should_freeze = other.should_freeze;
146+
other.should_freeze = false;
147+
}
148+
FrozenCleanupCheck& operator=(FrozenCleanupCheck&& other) noexcept
149+
{
150+
should_freeze = other.should_freeze;
151+
other.should_freeze = false;
152+
return *this;
153+
}
143154
void swap(FrozenCleanupCheck& x) noexcept
144155
{
145156
std::swap(should_freeze, x.should_freeze);

src/test/fuzz/checkqueue.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
namespace {
1515
struct DumbCheck {
16-
const bool result = false;
16+
bool result = false;
1717

1818
DumbCheck() = default;
1919

0 commit comments

Comments
 (0)