refactor: unify container presence checks - find
What changed, and why it matters
This commit is a pure code cleanup: it replaces verbose 'find ... == end()' checks with the simpler 'contains()' method on C++ containers. There is no change in behavior, no bug fix, and no security impact.
No security action needed. This is a routine maintainability refactor.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit refactors container presence checks across nine source files, converting patterns like ‘m.find(k) == m.end()’ to ‘!m.contains(k)’ and ‘m.find(k) != m.end()’ to ‘m.contains(k)’. These are semantically equivalent for associative containers. No logic, control flow, or data handling changes are introduced.
Changed components
src/bitcoin-cli.cppsrc/common/args.cppsrc/node/mini_miner.cppsrc/node/utxo_snapshot.hsrc/policy/packages.cppsrc/rpc/util.cppsrc/test/util_threadnames_tests.cppsrc/txmempool.cppsrc/wallet/scriptpubkeyman.cppInspect captured patch +11 / −11
diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp
index 279aa89e..9efab160 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 0b8d2e4d..f7d4652a 100644
--- a/src/common/args.cpp
+++ b/src/common/args.cpp
@@ -164,7 +164,7 @@ std::list<SectionInfo> ArgsManager::GetUnrecognizedSections() const
LOCK(cs_args);
std::list<SectionInfo> 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 b70c7503..a2503c58 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<CFeeRate> target_feerate)
diff --git a/src/node/utxo_snapshot.h b/src/node/utxo_snapshot.h
index e4eb6d60..3a493d44 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 187bd467..0f04b4cf 100644
--- a/src/policy/packages.cpp
+++ b/src/policy/packages.cpp
@@ -26,7 +26,7 @@ bool IsTopoSortedPackage(const Package& txns, std::unordered_set<Txid, SaltedTxi
// than its child.
for (const auto& tx : txns) {
for (const auto& input : tx->vin) {
- 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 642b8c09..e9c97ba0 100644
--- a/src/rpc/util.cpp
+++ b/src/rpc/util.cpp
@@ -1172,7 +1172,7 @@ UniValue RPCResult::MatchesType(const UniValue& result) const
std::map<std::string, UniValue> 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 efa0b273..db3e90b7 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 e0d16a81..011de1d4 100644
--- a/src/txmempool.cpp
+++ b/src/txmempool.cpp
@@ -988,7 +988,7 @@ util::Result<std::pair<std::vector<FeeFrac>, std::vector<FeeFrac>>> 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 fc27da5d..aca9cca8 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;
}
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.