diff options
author | Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> | 2023-03-21 13:04:01 +0000 |
---|---|---|
committer | Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> | 2023-03-21 13:04:01 +0000 |
commit | 04831fee6dca3eb86cd1d6b9ef879b296263fe35 (patch) | |
tree | 546cd9925aada5ac2f984ba52af68e80184a9d62 /src | |
parent | 6c2d5972f3544c4f3e987828a99e88f27b62cf87 (diff) |
refactor: Make move semantics explicit for callers
Diffstat (limited to 'src')
-rw-r--r-- | src/bench/checkqueue.cpp | 2 | ||||
-rw-r--r-- | src/checkqueue.h | 9 | ||||
-rw-r--r-- | src/test/checkqueue_tests.cpp | 12 | ||||
-rw-r--r-- | src/test/fuzz/checkqueue.cpp | 4 | ||||
-rw-r--r-- | src/test/transaction_tests.cpp | 2 | ||||
-rw-r--r-- | src/validation.cpp | 2 |
6 files changed, 16 insertions, 15 deletions
diff --git a/src/bench/checkqueue.cpp b/src/bench/checkqueue.cpp index dfd7275f46..41a4a216bf 100644 --- a/src/bench/checkqueue.cpp +++ b/src/bench/checkqueue.cpp @@ -60,7 +60,7 @@ static void CCheckQueueSpeedPrevectorJob(benchmark::Bench& bench) // Make insecure_rand here so that each iteration is identical. CCheckQueueControl<PrevectorJob> control(&queue); for (auto vChecks : vBatches) { - control.Add(vChecks); + control.Add(std::move(vChecks)); } // control waits for completion by RAII, but // it is done explicitly here for clarity diff --git a/src/checkqueue.h b/src/checkqueue.h index 63628860c5..a4818ad44f 100644 --- a/src/checkqueue.h +++ b/src/checkqueue.h @@ -166,7 +166,7 @@ public: } //! Add a batch of checks to the queue - void Add(std::vector<T>& vChecks) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex) + void Add(std::vector<T>&& vChecks) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex) { if (vChecks.empty()) { return; @@ -237,10 +237,11 @@ public: return fRet; } - void Add(std::vector<T>& vChecks) + void Add(std::vector<T>&& vChecks) { - if (pqueue != nullptr) - pqueue->Add(vChecks); + if (pqueue != nullptr) { + pqueue->Add(std::move(vChecks)); + } } ~CCheckQueueControl() diff --git a/src/test/checkqueue_tests.cpp b/src/test/checkqueue_tests.cpp index 90154c8757..8d55ce75f7 100644 --- a/src/test/checkqueue_tests.cpp +++ b/src/test/checkqueue_tests.cpp @@ -191,7 +191,7 @@ static void Correct_Queue_range(std::vector<size_t> range) while (total) { vChecks.resize(std::min(total, (size_t) InsecureRandRange(10))); total -= vChecks.size(); - control.Add(vChecks); + control.Add(std::move(vChecks)); } BOOST_REQUIRE(control.Wait()); if (FakeCheckCheckCompletion::n_calls != i) { @@ -253,7 +253,7 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_Catches_Failure) vChecks.reserve(r); for (size_t k = 0; k < r && remaining; k++, remaining--) vChecks.emplace_back(remaining == 1); - control.Add(vChecks); + control.Add(std::move(vChecks)); } bool success = control.Wait(); if (i > 0) { @@ -278,7 +278,7 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_Recovers_From_Failure) std::vector<FailingCheck> vChecks; vChecks.resize(100, false); vChecks[99] = end_fails; - control.Add(vChecks); + control.Add(std::move(vChecks)); } bool r =control.Wait(); BOOST_REQUIRE(r != end_fails); @@ -304,7 +304,7 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_UniqueCheck) std::vector<UniqueCheck> vChecks; for (size_t k = 0; k < r && total; k++) vChecks.emplace_back(--total); - control.Add(vChecks); + control.Add(std::move(vChecks)); } } { @@ -342,7 +342,7 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_Memory) // to catch any sort of deallocation failure vChecks.emplace_back(total == 0 || total == i || total == i/2); } - control.Add(vChecks); + control.Add(std::move(vChecks)); } } BOOST_REQUIRE_EQUAL(MemoryCheck::fake_allocated_memory, 0U); @@ -364,7 +364,7 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_FrozenCleanup) // swaps in default initialized Checks (otherwise freezing destructor // would get called twice). vChecks[0].should_freeze = true; - control.Add(vChecks); + control.Add(std::move(vChecks)); bool waitResult = control.Wait(); // Hangs here assert(waitResult); }); diff --git a/src/test/fuzz/checkqueue.cpp b/src/test/fuzz/checkqueue.cpp index 0c776e1b2f..cd2089de59 100644 --- a/src/test/fuzz/checkqueue.cpp +++ b/src/test/fuzz/checkqueue.cpp @@ -48,7 +48,7 @@ FUZZ_TARGET(checkqueue) checks_2.emplace_back(result); } if (fuzzed_data_provider.ConsumeBool()) { - check_queue_1.Add(checks_1); + check_queue_1.Add(std::move(checks_1)); } if (fuzzed_data_provider.ConsumeBool()) { (void)check_queue_1.Wait(); @@ -56,7 +56,7 @@ FUZZ_TARGET(checkqueue) CCheckQueueControl<DumbCheck> check_queue_control{&check_queue_2}; if (fuzzed_data_provider.ConsumeBool()) { - check_queue_control.Add(checks_2); + check_queue_control.Add(std::move(checks_2)); } if (fuzzed_data_provider.ConsumeBool()) { (void)check_queue_control.Wait(); diff --git a/src/test/transaction_tests.cpp b/src/test/transaction_tests.cpp index f7ea99f6a6..7511dff9e8 100644 --- a/src/test/transaction_tests.cpp +++ b/src/test/transaction_tests.cpp @@ -548,7 +548,7 @@ BOOST_AUTO_TEST_CASE(test_big_witness_transaction) for(uint32_t i = 0; i < mtx.vin.size(); i++) { std::vector<CScriptCheck> vChecks; vChecks.emplace_back(coins[tx.vin[i].prevout.n].out, tx, i, SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_WITNESS, false, &txdata); - control.Add(vChecks); + control.Add(std::move(vChecks)); } bool controlCheck = control.Wait(); diff --git a/src/validation.cpp b/src/validation.cpp index dce066412c..9d069a8357 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -2324,7 +2324,7 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state, return error("ConnectBlock(): CheckInputScripts on %s failed with %s", tx.GetHash().ToString(), state.ToString()); } - control.Add(vChecks); + control.Add(std::move(vChecks)); } CTxUndo undoDummy; |