Skip to content

Commit d8427cc

Browse files
hebastomartinus
andcommitted
refactor: Use move semantics in CCheckQueue::Loop
Co-authored-by: Martin Leitner-Ankerl <[email protected]>
1 parent 9a0b524 commit d8427cc

File tree

3 files changed

+3
-18
lines changed

3 files changed

+3
-18
lines changed

src/bench/checkqueue.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,13 @@ static void CCheckQueueSpeedPrevectorJob(benchmark::Bench& bench)
2929

3030
struct PrevectorJob {
3131
prevector<PREVECTOR_SIZE, uint8_t> p;
32-
PrevectorJob() = default;
3332
explicit PrevectorJob(FastRandomContext& insecure_rand){
3433
p.resize(insecure_rand.randrange(PREVECTOR_SIZE*2));
3534
}
3635
bool operator()()
3736
{
3837
return true;
3938
}
40-
void swap(PrevectorJob& x) noexcept
41-
{
42-
p.swap(x.p);
43-
};
4439
};
4540
CCheckQueue<PrevectorJob> queue {QUEUE_BATCH_SIZE};
4641
// The main thread should be counted to prevent thread oversubscription, and

src/checkqueue.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,9 @@ class CCheckQueue
112112
// * Try to account for idle jobs which will instantly start helping.
113113
// * Don't do batches smaller than 1 (duh), or larger than nBatchSize.
114114
nNow = std::max(1U, std::min(nBatchSize, (unsigned int)queue.size() / (nTotal + nIdle + 1)));
115-
vChecks.resize(nNow);
116-
for (unsigned int i = 0; i < nNow; i++) {
117-
// We want the lock on the m_mutex to be as short as possible, so swap jobs from the global
118-
// queue to the local batch vector instead of copying.
119-
vChecks[i].swap(queue.back());
120-
queue.pop_back();
121-
}
115+
auto start_it = queue.end() - nNow;
116+
vChecks.assign(std::make_move_iterator(start_it), std::make_move_iterator(queue.end()));
117+
queue.erase(start_it, queue.end());
122118
// Check whether we need to do work at all
123119
fOk = fAllOk;
124120
}

src/test/fuzz/checkqueue.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ namespace {
1515
struct DumbCheck {
1616
bool result = false;
1717

18-
DumbCheck() = default;
19-
2018
explicit DumbCheck(const bool _result) : result(_result)
2119
{
2220
}
@@ -25,10 +23,6 @@ struct DumbCheck {
2523
{
2624
return result;
2725
}
28-
29-
void swap(DumbCheck& x) noexcept
30-
{
31-
}
3226
};
3327
} // namespace
3428

0 commit comments

Comments
 (0)