From 8bb9219b6301215f53e43967d17445aaf1b81090 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C5=91rinc?= Date: Wed, 30 Jul 2025 20:37:23 -0700 Subject: [PATCH] refactor: unify container presence checks - find The changes made here were: | From | To | |------------------------|------------------| | `m.find(k) == m.end()` | `!m.contains(k)` | | `m.find(k) != m.end()` | `m.contains(k)` | --- src/bitcoin-cli.cpp | 2 +- src/common/args.cpp | 2 +- src/node/mini_miner.cpp | 2 +- src/node/utxo_snapshot.h | 2 +- src/policy/packages.cpp | 4 ++-- src/rpc/util.cpp | 2 +- src/test/util_threadnames_tests.cpp | 2 +- src/txmempool.cpp | 2 +- src/wallet/scriptpubkeyman.cpp | 4 ++-- 9 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp index 279aa89e88e..9efab1608fc 100644 --- a/src/bitcoin-cli.cpp +++ b/src/bitcoin-cli.cpp @@ -1129,7 +1129,7 @@ static void ParseGetInfoResult(UniValue& result) const std::string proxy = network["proxy"].getValStr(); if (proxy.empty()) continue; // Add proxy to ordered_proxy if has not been processed - if (proxy_networks.find(proxy) == proxy_networks.end()) ordered_proxies.push_back(proxy); + if (!proxy_networks.contains(proxy)) ordered_proxies.push_back(proxy); proxy_networks[proxy].push_back(network["name"].getValStr()); } diff --git a/src/common/args.cpp b/src/common/args.cpp index 0b8d2e4d24d..f7d4652a51f 100644 --- a/src/common/args.cpp +++ b/src/common/args.cpp @@ -164,7 +164,7 @@ std::list ArgsManager::GetUnrecognizedSections() const LOCK(cs_args); std::list unrecognized = m_config_sections; - unrecognized.remove_if([](const SectionInfo& appeared){ return available_sections.find(appeared.m_name) != available_sections.end(); }); + unrecognized.remove_if([](const SectionInfo& appeared){ return available_sections.contains(appeared.m_name); }); return unrecognized; } diff --git a/src/node/mini_miner.cpp b/src/node/mini_miner.cpp index b70c7503b6d..a2503c587de 100644 --- a/src/node/mini_miner.cpp +++ b/src/node/mini_miner.cpp @@ -240,7 +240,7 @@ void MiniMiner::SanityCheck() const entry->second.GetModFeesWithAncestors() >= entry->second.GetModifiedFee();})); // None of the entries should be to-be-replaced transactions Assume(std::all_of(m_to_be_replaced.begin(), m_to_be_replaced.end(), - [&](const auto& txid){return m_entries_by_txid.find(txid) == m_entries_by_txid.end();})); + [&](const auto& txid){ return !m_entries_by_txid.contains(txid); })); } void MiniMiner::BuildMockTemplate(std::optional target_feerate) diff --git a/src/node/utxo_snapshot.h b/src/node/utxo_snapshot.h index e4eb6d60ad8..3a493d444b4 100644 --- a/src/node/utxo_snapshot.h +++ b/src/node/utxo_snapshot.h @@ -77,7 +77,7 @@ public: // Read the version uint16_t version; s >> version; - if (m_supported_versions.find(version) == m_supported_versions.end()) { + if (!m_supported_versions.contains(version)) { throw std::ios_base::failure(strprintf("Version of snapshot %s does not match any of the supported versions.", version)); } diff --git a/src/policy/packages.cpp b/src/policy/packages.cpp index 187bd467579..0f04b4cfb11 100644 --- a/src/policy/packages.cpp +++ b/src/policy/packages.cpp @@ -26,7 +26,7 @@ bool IsTopoSortedPackage(const Package& txns, std::unordered_setvin) { - if (later_txids.find(input.prevout.hash) != later_txids.end()) { + if (later_txids.contains(input.prevout.hash)) { // The parent is a subsequent transaction in the package. return false; } @@ -62,7 +62,7 @@ bool IsConsistentPackage(const Package& txns) return false; } for (const auto& input : tx->vin) { - if (inputs_seen.find(input.prevout) != inputs_seen.end()) { + if (inputs_seen.contains(input.prevout)) { // This input is also present in another tx in the package. return false; } diff --git a/src/rpc/util.cpp b/src/rpc/util.cpp index 642b8c099bc..e9c97ba0cc1 100644 --- a/src/rpc/util.cpp +++ b/src/rpc/util.cpp @@ -1172,7 +1172,7 @@ UniValue RPCResult::MatchesType(const UniValue& result) const std::map result_obj; result.getObjMap(result_obj); for (const auto& result_entry : result_obj) { - if (doc_keys.find(result_entry.first) == doc_keys.end()) { + if (!doc_keys.contains(result_entry.first)) { errors.pushKV(result_entry.first, "key returned that was not in doc"); } } diff --git a/src/test/util_threadnames_tests.cpp b/src/test/util_threadnames_tests.cpp index efa0b2736be..db3e90b7909 100644 --- a/src/test/util_threadnames_tests.cpp +++ b/src/test/util_threadnames_tests.cpp @@ -58,7 +58,7 @@ BOOST_AUTO_TEST_CASE(util_threadnames_test_rename_threaded) // Names "test_thread.[n]" should exist for n = [0, 99] for (int i = 0; i < 100; ++i) { - BOOST_CHECK(names.find(TEST_THREAD_NAME_BASE + ToString(i)) != names.end()); + BOOST_CHECK(names.contains(TEST_THREAD_NAME_BASE + ToString(i))); } } diff --git a/src/txmempool.cpp b/src/txmempool.cpp index e0d16a81d9e..011de1d42e2 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -988,7 +988,7 @@ util::Result, std::vector>> CTxMemPool:: CTxMemPool::ChangeSet::TxHandle CTxMemPool::ChangeSet::StageAddition(const CTransactionRef& tx, const CAmount fee, int64_t time, unsigned int entry_height, uint64_t entry_sequence, bool spends_coinbase, int64_t sigops_cost, LockPoints lp) { LOCK(m_pool->cs); - Assume(m_to_add.find(tx->GetHash()) == m_to_add.end()); + Assume(!m_to_add.contains(tx->GetHash())); Assume(!m_dependencies_processed); // We need to process dependencies after adding a new transaction. diff --git a/src/wallet/scriptpubkeyman.cpp b/src/wallet/scriptpubkeyman.cpp index fc27da5d764..aca9cca8743 100644 --- a/src/wallet/scriptpubkeyman.cpp +++ b/src/wallet/scriptpubkeyman.cpp @@ -1107,8 +1107,8 @@ bool DescriptorScriptPubKeyMan::AddDescriptorKeyWithDB(WalletBatch& batch, const assert(!m_storage.IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)); // Check if provided key already exists - if (m_map_keys.find(pubkey.GetID()) != m_map_keys.end() || - m_map_crypted_keys.find(pubkey.GetID()) != m_map_crypted_keys.end()) { + if (m_map_keys.contains(pubkey.GetID()) || + m_map_crypted_keys.contains(pubkey.GetID())) { return true; }