mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-20 07:09:15 +01:00
refactor: unify container presence checks - non-trivial counts
The changes made here were: | From | To | |-------------------|------------------| | `m.count(k) == 1` | `m.contains(k)` | | `m.count(k) == 0` | `!m.contains(k)` | | `m.count(k) != 1` | `!m.contains(k)` | | `m.count(k) < 1` | `!m.contains(k)` | * `mapInfo` is instance of `std::unordered_map` and can only contain 0 or 1 value for a given key; * similarly, `g_enabled_filter_types` and `setClientRules` are both `std::set` instances; * lastly, while `mapTxSpends` is `std::unordered_multimap` that could potentially hold multiple values, having a size less than 1 means that the value is missing. `QMap<WalletModel*, WalletView*> mapWalletViews` values were also migrated manually. Co-authored-by: pablomartin4btc <pablomartin4btc@gmail.com> Co-authored-by: fanquake <fanquake@gmail.com>
This commit is contained in:
@@ -516,7 +516,7 @@ void AddrManImpl::MakeTried(AddrInfo& info, nid_type nId)
|
||||
if (vvTried[nKBucket][nKBucketPos] != -1) {
|
||||
// find an item to evict
|
||||
nid_type nIdEvict = vvTried[nKBucket][nKBucketPos];
|
||||
assert(mapInfo.count(nIdEvict) == 1);
|
||||
assert(mapInfo.contains(nIdEvict));
|
||||
AddrInfo& infoOld = mapInfo[nIdEvict];
|
||||
|
||||
// Remove the to-be-evicted item from the tried set.
|
||||
@@ -919,7 +919,7 @@ void AddrManImpl::ResolveCollisions_()
|
||||
bool erase_collision = false;
|
||||
|
||||
// If id_new not found in mapInfo remove it from m_tried_collisions
|
||||
if (mapInfo.count(id_new) != 1) {
|
||||
if (!mapInfo.contains(id_new)) {
|
||||
erase_collision = true;
|
||||
} else {
|
||||
AddrInfo& info_new = mapInfo[id_new];
|
||||
@@ -985,7 +985,7 @@ std::pair<CAddress, NodeSeconds> AddrManImpl::SelectTriedCollision_()
|
||||
nid_type id_new = *it;
|
||||
|
||||
// If id_new not found in mapInfo remove it from m_tried_collisions
|
||||
if (mapInfo.count(id_new) != 1) {
|
||||
if (!mapInfo.contains(id_new)) {
|
||||
m_tried_collisions.erase(it);
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -968,7 +968,7 @@ bool AppInitParameterInteraction(const ArgsManager& args)
|
||||
|
||||
// Signal NODE_COMPACT_FILTERS if peerblockfilters and basic filters index are both enabled.
|
||||
if (args.GetBoolArg("-peerblockfilters", DEFAULT_PEERBLOCKFILTERS)) {
|
||||
if (g_enabled_filter_types.count(BlockFilterType::BASIC) != 1) {
|
||||
if (!g_enabled_filter_types.contains(BlockFilterType::BASIC)) {
|
||||
return InitError(_("Cannot set -peerblockfilters without -blockfilterindex."));
|
||||
}
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@ bool WalletFrame::addView(WalletView* walletView)
|
||||
{
|
||||
if (!clientModel) return false;
|
||||
|
||||
if (mapWalletViews.count(walletView->getWalletModel()) > 0) return false;
|
||||
if (mapWalletViews.contains(walletView->getWalletModel())) return false;
|
||||
|
||||
walletView->setClientModel(clientModel);
|
||||
walletView->showOutOfSyncWarning(bOutOfSync);
|
||||
@@ -90,7 +90,7 @@ bool WalletFrame::addView(WalletView* walletView)
|
||||
|
||||
void WalletFrame::setCurrentWallet(WalletModel* wallet_model)
|
||||
{
|
||||
if (mapWalletViews.count(wallet_model) == 0) return;
|
||||
if (!mapWalletViews.contains(wallet_model)) return;
|
||||
|
||||
// Stop the effect of hidden widgets on the size hint of the shown one in QStackedWidget.
|
||||
WalletView* view_about_to_hide = currentWalletView();
|
||||
@@ -116,7 +116,7 @@ void WalletFrame::setCurrentWallet(WalletModel* wallet_model)
|
||||
|
||||
void WalletFrame::removeWallet(WalletModel* wallet_model)
|
||||
{
|
||||
if (mapWalletViews.count(wallet_model) == 0) return;
|
||||
if (!mapWalletViews.contains(wallet_model)) return;
|
||||
|
||||
WalletView *walletView = mapWalletViews.take(wallet_model);
|
||||
walletStack->removeWidget(walletView);
|
||||
|
||||
@@ -580,7 +580,7 @@ public:
|
||||
// Bail out if we already have a CANDIDATE_BEST announcement for this (txhash, peer) combination. The case
|
||||
// where there is a non-CANDIDATE_BEST announcement already will be caught by the uniqueness property of the
|
||||
// ByPeer index when we try to emplace the new object below.
|
||||
if (m_index.get<ByPeer>().count(ByPeerView{peer, true, gtxid.ToUint256()})) return;
|
||||
if (m_index.get<ByPeer>().contains(ByPeerView{peer, true, gtxid.ToUint256()})) return;
|
||||
|
||||
// Try creating the announcement with CANDIDATE_DELAYED state (which will fail due to the uniqueness
|
||||
// of the ByPeer index if a non-CANDIDATE_BEST announcement already exists with the same txhash and peer).
|
||||
|
||||
@@ -265,7 +265,7 @@ void WaitForDeleteWallet(std::shared_ptr<CWallet>&& wallet)
|
||||
wallet.reset();
|
||||
{
|
||||
WAIT_LOCK(g_wallet_release_mutex, lock);
|
||||
while (g_unloading_wallet_set.count(name) == 1) {
|
||||
while (g_unloading_wallet_set.contains(name)) {
|
||||
g_wallet_release_cv.wait(lock);
|
||||
}
|
||||
}
|
||||
@@ -1525,7 +1525,7 @@ void CWallet::blockDisconnected(const interfaces::BlockInfo& block)
|
||||
|
||||
for (const CTxIn& tx_in : ptx->vin) {
|
||||
// No other wallet transactions conflicted with this transaction
|
||||
if (mapTxSpends.count(tx_in.prevout) < 1) continue;
|
||||
if (!mapTxSpends.contains(tx_in.prevout)) continue;
|
||||
|
||||
std::pair<TxSpends::const_iterator, TxSpends::const_iterator> range = mapTxSpends.equal_range(tx_in.prevout);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user