Skip to content

Commit 04831fe

Browse files
committed
refactor: Make move semantics explicit for callers
1 parent 6c2d597 commit 04831fe

File tree

6 files changed

+16
-15
lines changed

6 files changed

+16
-15
lines changed

src/bench/checkqueue.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ static void CCheckQueueSpeedPrevectorJob(benchmark::Bench& bench)
6060
// Make insecure_rand here so that each iteration is identical.
6161
CCheckQueueControl<PrevectorJob> control(&queue);
6262
for (auto vChecks : vBatches) {
63-
control.Add(vChecks);
63+
control.Add(std::move(vChecks));
6464
}
6565
// control waits for completion by RAII, but
6666
// it is done explicitly here for clarity

src/checkqueue.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ class CCheckQueue
166166
}
167167

168168
//! Add a batch of checks to the queue
169-
void Add(std::vector<T>& vChecks) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
169+
void Add(std::vector<T>&& vChecks) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
170170
{
171171
if (vChecks.empty()) {
172172
return;
@@ -237,10 +237,11 @@ class CCheckQueueControl
237237
return fRet;
238238
}
239239

240-
void Add(std::vector<T>& vChecks)
240+
void Add(std::vector<T>&& vChecks)
241241
{
242-
if (pqueue != nullptr)
243-
pqueue->Add(vChecks);
242+
if (pqueue != nullptr) {
243+
pqueue->Add(std::move(vChecks));
244+
}
244245
}
245246

246247
~CCheckQueueControl()

src/test/checkqueue_tests.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ static void Correct_Queue_range(std::vector<size_t> range)
191191
while (total) {
192192
vChecks.resize(std::min(total, (size_t) InsecureRandRange(10)));
193193
total -= vChecks.size();
194-
control.Add(vChecks);
194+
control.Add(std::move(vChecks));
195195
}
196196
BOOST_REQUIRE(control.Wait());
197197
if (FakeCheckCheckCompletion::n_calls != i) {
@@ -253,7 +253,7 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_Catches_Failure)
253253
vChecks.reserve(r);
254254
for (size_t k = 0; k < r && remaining; k++, remaining--)
255255
vChecks.emplace_back(remaining == 1);
256-
control.Add(vChecks);
256+
control.Add(std::move(vChecks));
257257
}
258258
bool success = control.Wait();
259259
if (i > 0) {
@@ -278,7 +278,7 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_Recovers_From_Failure)
278278
std::vector<FailingCheck> vChecks;
279279
vChecks.resize(100, false);
280280
vChecks[99] = end_fails;
281-
control.Add(vChecks);
281+
control.Add(std::move(vChecks));
282282
}
283283
bool r =control.Wait();
284284
BOOST_REQUIRE(r != end_fails);
@@ -304,7 +304,7 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_UniqueCheck)
304304
std::vector<UniqueCheck> vChecks;
305305
for (size_t k = 0; k < r && total; k++)
306306
vChecks.emplace_back(--total);
307-
control.Add(vChecks);
307+
control.Add(std::move(vChecks));
308308
}
309309
}
310310
{
@@ -342,7 +342,7 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_Memory)
342342
// to catch any sort of deallocation failure
343343
vChecks.emplace_back(total == 0 || total == i || total == i/2);
344344
}
345-
control.Add(vChecks);
345+
control.Add(std::move(vChecks));
346346
}
347347
}
348348
BOOST_REQUIRE_EQUAL(MemoryCheck::fake_allocated_memory, 0U);
@@ -364,7 +364,7 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_FrozenCleanup)
364364
// swaps in default initialized Checks (otherwise freezing destructor
365365
// would get called twice).
366366
vChecks[0].should_freeze = true;
367-
control.Add(vChecks);
367+
control.Add(std::move(vChecks));
368368
bool waitResult = control.Wait(); // Hangs here
369369
assert(waitResult);
370370
});

src/test/fuzz/checkqueue.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,15 @@ FUZZ_TARGET(checkqueue)
4848
checks_2.emplace_back(result);
4949
}
5050
if (fuzzed_data_provider.ConsumeBool()) {
51-
check_queue_1.Add(checks_1);
51+
check_queue_1.Add(std::move(checks_1));
5252
}
5353
if (fuzzed_data_provider.ConsumeBool()) {
5454
(void)check_queue_1.Wait();
5555
}
5656

5757
CCheckQueueControl<DumbCheck> check_queue_control{&check_queue_2};
5858
if (fuzzed_data_provider.ConsumeBool()) {
59-
check_queue_control.Add(checks_2);
59+
check_queue_control.Add(std::move(checks_2));
6060
}
6161
if (fuzzed_data_provider.ConsumeBool()) {
6262
(void)check_queue_control.Wait();

src/test/transaction_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ BOOST_AUTO_TEST_CASE(test_big_witness_transaction)
548548
for(uint32_t i = 0; i < mtx.vin.size(); i++) {
549549
std::vector<CScriptCheck> vChecks;
550550
vChecks.emplace_back(coins[tx.vin[i].prevout.n].out, tx, i, SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_WITNESS, false, &txdata);
551-
control.Add(vChecks);
551+
control.Add(std::move(vChecks));
552552
}
553553

554554
bool controlCheck = control.Wait();

src/validation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2324,7 +2324,7 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
23242324
return error("ConnectBlock(): CheckInputScripts on %s failed with %s",
23252325
tx.GetHash().ToString(), state.ToString());
23262326
}
2327-
control.Add(vChecks);
2327+
control.Add(std::move(vChecks));
23282328
}
23292329

23302330
CTxUndo undoDummy;

0 commit comments

Comments
 (0)