diff options
author | fanquake <fanquake@gmail.com> | 2023-03-27 14:22:37 +0100 |
---|---|---|
committer | fanquake <fanquake@gmail.com> | 2023-03-27 14:34:52 +0100 |
commit | 39630675553280fe72254de69ec1ed2bc8fc9808 (patch) | |
tree | c65e616e43952456894989de68d6541d6b79a08b /src/test | |
parent | 3e835ca95863b1350a6425dad6e2bc604e01ecdf (diff) | |
parent | 03ec5b6f9ca3af28c9ce25cf2393e28ae852d808 (diff) |
Merge bitcoin/bitcoin#26642: clang-tidy: Add more `performance-*` checks and related fixes
03ec5b6f9ca3af28c9ce25cf2393e28ae852d808 clang-tidy: Exclude `performance-*` checks rather including them (Hennadii Stepanov)
24004372302adfc0e7cb36f8db6830694bf050e9 clang-tidy: Add `performance-type-promotion-in-math-fn` check (Hennadii Stepanov)
7e975e6cf86617346c1d8e2568f74a0252c03857 clang-tidy: Add `performance-inefficient-vector-operation` check (Hennadii Stepanov)
516b75f66ec3ba7495fc028c750937bd66cc9bba clang-tidy: Add `performance-faster-string-find` check (Hennadii Stepanov)
Pull request description:
ACKs for top commit:
martinus:
ACK 03ec5b6f9ca3af28c9ce25cf2393e28ae852d808
TheCharlatan:
re-ACK [03ec5b6](https://github.com/bitcoin/bitcoin/pull/26642/commits/03ec5b6f9ca3af28c9ce25cf2393e28ae852d808)
Tree-SHA512: 2dfa52f9131da88826f32583bfd534a56a998477db9804b7333c0e7ac0b6b36141009755c7163b9f95d0ecbf5c2cb63f8a69ce4b114bb83423faed21b50cec67
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/allocator_tests.cpp | 1 | ||||
-rw-r--r-- | src/test/fuzz/tx_pool.cpp | 1 | ||||
-rw-r--r-- | src/test/getarg_tests.cpp | 1 | ||||
-rw-r--r-- | src/test/policyestimator_tests.cpp | 1 | ||||
-rw-r--r-- | src/test/scheduler_tests.cpp | 2 | ||||
-rw-r--r-- | src/test/script_p2sh_tests.cpp | 4 | ||||
-rw-r--r-- | src/test/txrequest_tests.cpp | 1 | ||||
-rw-r--r-- | src/test/util/net.cpp | 1 | ||||
-rw-r--r-- | src/test/util_threadnames_tests.cpp | 1 | ||||
-rw-r--r-- | src/test/validation_block_tests.cpp | 1 |
10 files changed, 13 insertions, 1 deletions
diff --git a/src/test/allocator_tests.cpp b/src/test/allocator_tests.cpp index 715ce0a5b4..f74e50a890 100644 --- a/src/test/allocator_tests.cpp +++ b/src/test/allocator_tests.cpp @@ -77,6 +77,7 @@ BOOST_AUTO_TEST_CASE(arena_tests) b.walk(); #endif // Sweeping allocate all memory + addr.reserve(2048); for (int x=0; x<1024; ++x) addr.push_back(b.alloc(1024)); BOOST_CHECK(b.stats().free == 0); diff --git a/src/test/fuzz/tx_pool.cpp b/src/test/fuzz/tx_pool.cpp index 0cabaf323b..a055705575 100644 --- a/src/test/fuzz/tx_pool.cpp +++ b/src/test/fuzz/tx_pool.cpp @@ -316,6 +316,7 @@ FUZZ_TARGET_INIT(tx_pool, initialize_tx_pool) MockTime(fuzzed_data_provider, chainstate); std::vector<uint256> txids; + txids.reserve(g_outpoints_coinbase_init_mature.size()); for (const auto& outpoint : g_outpoints_coinbase_init_mature) { txids.push_back(outpoint.hash); } diff --git a/src/test/getarg_tests.cpp b/src/test/getarg_tests.cpp index 9c2d8a4dad..9106040b84 100644 --- a/src/test/getarg_tests.cpp +++ b/src/test/getarg_tests.cpp @@ -29,6 +29,7 @@ void ResetArgs(ArgsManager& local_args, const std::string& strArg) // Convert to char*: std::vector<const char*> vecChar; + vecChar.reserve(vecArg.size()); for (const std::string& s : vecArg) vecChar.push_back(s.c_str()); diff --git a/src/test/policyestimator_tests.cpp b/src/test/policyestimator_tests.cpp index 75ba9972f6..bc9c672560 100644 --- a/src/test/policyestimator_tests.cpp +++ b/src/test/policyestimator_tests.cpp @@ -24,6 +24,7 @@ BOOST_AUTO_TEST_CASE(BlockPolicyEstimates) CAmount basefee(2000); CAmount deltaFee(100); std::vector<CAmount> feeV; + feeV.reserve(10); // Populate vectors of increasing fees for (int j = 0; j < 10; j++) { diff --git a/src/test/scheduler_tests.cpp b/src/test/scheduler_tests.cpp index 1301a1b219..3fb3378598 100644 --- a/src/test/scheduler_tests.cpp +++ b/src/test/scheduler_tests.cpp @@ -71,6 +71,7 @@ BOOST_AUTO_TEST_CASE(manythreads) // As soon as these are created they will start running and servicing the queue std::vector<std::thread> microThreads; + microThreads.reserve(10); for (int i = 0; i < 5; i++) microThreads.emplace_back(std::bind(&CScheduler::serviceQueue, µTasks)); @@ -136,6 +137,7 @@ BOOST_AUTO_TEST_CASE(singlethreadedscheduler_ordered) // the extra threads should effectively be doing nothing // if they don't we'll get out of order behaviour std::vector<std::thread> threads; + threads.reserve(5); for (int i = 0; i < 5; ++i) { threads.emplace_back([&] { scheduler.serviceQueue(); }); } diff --git a/src/test/script_p2sh_tests.cpp b/src/test/script_p2sh_tests.cpp index c9f002b324..739ab75de3 100644 --- a/src/test/script_p2sh_tests.cpp +++ b/src/test/script_p2sh_tests.cpp @@ -156,6 +156,7 @@ BOOST_AUTO_TEST_CASE(set) FillableSigningProvider keystore; CKey key[4]; std::vector<CPubKey> keys; + keys.reserve(4); for (int i = 0; i < 4; i++) { key[i].MakeNewKey(true); @@ -270,12 +271,13 @@ BOOST_AUTO_TEST_CASE(AreInputsStandard) CCoinsViewCache coins(&coinsDummy); FillableSigningProvider keystore; CKey key[6]; - std::vector<CPubKey> keys; for (int i = 0; i < 6; i++) { key[i].MakeNewKey(true); BOOST_CHECK(keystore.AddKey(key[i])); } + std::vector<CPubKey> keys; + keys.reserve(3); for (int i = 0; i < 3; i++) keys.push_back(key[i].GetPubKey()); diff --git a/src/test/txrequest_tests.cpp b/src/test/txrequest_tests.cpp index 17a55d5ab5..dc257a0d51 100644 --- a/src/test/txrequest_tests.cpp +++ b/src/test/txrequest_tests.cpp @@ -386,6 +386,7 @@ void BuildBigPriorityTest(Scenario& scenario, int peers) } // Make a list of all peers, in order of intended request order (concatenation of pref_peers and npref_peers). std::vector<NodeId> request_order; + request_order.reserve(num_pref + num_npref); for (int i = 0; i < num_pref; ++i) request_order.push_back(pref_peers[i]); for (int i = 0; i < num_npref; ++i) request_order.push_back(npref_peers[i]); diff --git a/src/test/util/net.cpp b/src/test/util/net.cpp index 070a6a1c50..27a1277680 100644 --- a/src/test/util/net.cpp +++ b/src/test/util/net.cpp @@ -84,6 +84,7 @@ bool ConnmanTestMsg::ReceiveMsgFrom(CNode& node, CSerializedNetMsg& ser_msg) con std::vector<NodeEvictionCandidate> GetRandomNodeEvictionCandidates(int n_candidates, FastRandomContext& random_context) { std::vector<NodeEvictionCandidate> candidates; + candidates.reserve(n_candidates); for (int id = 0; id < n_candidates; ++id) { candidates.push_back({ /*id=*/id, diff --git a/src/test/util_threadnames_tests.cpp b/src/test/util_threadnames_tests.cpp index dbb5423a77..ae913939e8 100644 --- a/src/test/util_threadnames_tests.cpp +++ b/src/test/util_threadnames_tests.cpp @@ -38,6 +38,7 @@ std::set<std::string> RenameEnMasse(int num_threads) names.insert(util::ThreadGetInternalName()); }; + threads.reserve(num_threads); for (int i = 0; i < num_threads; ++i) { threads.push_back(std::thread(RenameThisThread, i)); } diff --git a/src/test/validation_block_tests.cpp b/src/test/validation_block_tests.cpp index 4c8687ce69..e08f2c98c2 100644 --- a/src/test/validation_block_tests.cpp +++ b/src/test/validation_block_tests.cpp @@ -174,6 +174,7 @@ BOOST_AUTO_TEST_CASE(processnewblock_signals_ordering) // this will create parallelism and randomness inside validation - the ValidationInterface // will subscribe to events generated during block validation and assert on ordering invariance std::vector<std::thread> threads; + threads.reserve(10); for (int i = 0; i < 10; i++) { threads.emplace_back([&]() { bool ignored; |