From a774c7a339c26b1409c9a9572d2b52810ee64062 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C5=91rinc?= Date: Sun, 17 Nov 2024 13:53:35 +0100 Subject: [PATCH] refactor: Fix remaining clang-tidy performance-inefficient-vector errors --- src/rpc/output_script.cpp | 1 + src/test/checkqueue_tests.cpp | 1 + src/test/cuckoocache_tests.cpp | 1 + src/test/rpc_tests.cpp | 1 + 4 files changed, 4 insertions(+) diff --git a/src/rpc/output_script.cpp b/src/rpc/output_script.cpp index 49f3a812437d5..5de2847be997d 100644 --- a/src/rpc/output_script.cpp +++ b/src/rpc/output_script.cpp @@ -123,6 +123,7 @@ static RPCHelpMan createmultisig() // Get the public keys const UniValue& keys = request.params[1].get_array(); std::vector pubkeys; + pubkeys.reserve(keys.size()); for (unsigned int i = 0; i < keys.size(); ++i) { pubkeys.push_back(HexToPubKey(keys[i].get_str())); } diff --git a/src/test/checkqueue_tests.cpp b/src/test/checkqueue_tests.cpp index a9a1e4707067a..b7014db4a5b9e 100644 --- a/src/test/checkqueue_tests.cpp +++ b/src/test/checkqueue_tests.cpp @@ -360,6 +360,7 @@ BOOST_AUTO_TEST_CASE(test_CheckQueueControl_Locks) auto queue = std::make_unique(QUEUE_BATCH_SIZE, SCRIPT_CHECK_THREADS); { std::vector tg; + tg.reserve(3); std::atomic nThreads {0}; std::atomic fails {0}; for (size_t i = 0; i < 3; ++i) { diff --git a/src/test/cuckoocache_tests.cpp b/src/test/cuckoocache_tests.cpp index bb4c8c70938f3..f08c4d44287b6 100644 --- a/src/test/cuckoocache_tests.cpp +++ b/src/test/cuckoocache_tests.cpp @@ -224,6 +224,7 @@ void test_cache_erase_parallel(size_t megabytes) /** Spin up 3 threads to run contains with erase. */ std::vector threads; + threads.reserve(3); /** Erase the first quarter */ for (uint32_t x = 0; x < 3; ++x) /** Each thread is emplaced with x copy-by-value diff --git a/src/test/rpc_tests.cpp b/src/test/rpc_tests.cpp index 5089f3e8e33fe..87303d7417498 100644 --- a/src/test/rpc_tests.cpp +++ b/src/test/rpc_tests.cpp @@ -428,6 +428,7 @@ BOOST_AUTO_TEST_CASE(rpc_getblockstats_calculate_percentiles_by_weight) { int64_t total_weight = 200; std::vector> feerates; + feerates.reserve(200); CAmount result[NUM_GETBLOCKSTATS_PERCENTILES] = { 0 }; for (int64_t i = 0; i < 100; i++) {