@@ -144,7 +144,7 @@ CAddrInfo* CAddrMan::Create(const CAddress& addr, const CNetAddr& addrSource, in
144
144
return &mapInfo[nId];
145
145
}
146
146
147
- void CAddrMan::SwapRandom (unsigned int nRndPos1, unsigned int nRndPos2)
147
+ void CAddrMan::SwapRandom (unsigned int nRndPos1, unsigned int nRndPos2) const
148
148
{
149
149
AssertLockHeld (cs);
150
150
@@ -156,11 +156,13 @@ void CAddrMan::SwapRandom(unsigned int nRndPos1, unsigned int nRndPos2)
156
156
int nId1 = vRandom[nRndPos1];
157
157
int nId2 = vRandom[nRndPos2];
158
158
159
- assert (mapInfo.count (nId1) == 1 );
160
- assert (mapInfo.count (nId2) == 1 );
159
+ const auto it_1{mapInfo.find (nId1)};
160
+ const auto it_2{mapInfo.find (nId2)};
161
+ assert (it_1 != mapInfo.end ());
162
+ assert (it_2 != mapInfo.end ());
161
163
162
- mapInfo[nId1] .nRandomPos = nRndPos2;
163
- mapInfo[nId2] .nRandomPos = nRndPos1;
164
+ it_1-> second .nRandomPos = nRndPos2;
165
+ it_2-> second .nRandomPos = nRndPos1;
164
166
165
167
vRandom[nRndPos1] = nId2;
166
168
vRandom[nRndPos2] = nId1;
@@ -425,7 +427,7 @@ void CAddrMan::Attempt_(const CService& addr, bool fCountFailure, int64_t nTime)
425
427
}
426
428
}
427
429
428
- CAddrInfo CAddrMan::Select_ (bool newOnly)
430
+ CAddrInfo CAddrMan::Select_ (bool newOnly) const
429
431
{
430
432
AssertLockHeld (cs);
431
433
@@ -448,8 +450,9 @@ CAddrInfo CAddrMan::Select_(bool newOnly)
448
450
nKBucketPos = (nKBucketPos + insecure_rand.randbits (ADDRMAN_BUCKET_SIZE_LOG2)) % ADDRMAN_BUCKET_SIZE;
449
451
}
450
452
int nId = vvTried[nKBucket][nKBucketPos];
451
- assert (mapInfo.count (nId) == 1 );
452
- CAddrInfo& info = mapInfo[nId];
453
+ const auto it_found{mapInfo.find (nId)};
454
+ assert (it_found != mapInfo.end ());
455
+ const CAddrInfo& info{it_found->second };
453
456
if (insecure_rand.randbits (30 ) < fChanceFactor * info.GetChance () * (1 << 30 ))
454
457
return info;
455
458
fChanceFactor *= 1.2 ;
@@ -465,8 +468,9 @@ CAddrInfo CAddrMan::Select_(bool newOnly)
465
468
nUBucketPos = (nUBucketPos + insecure_rand.randbits (ADDRMAN_BUCKET_SIZE_LOG2)) % ADDRMAN_BUCKET_SIZE;
466
469
}
467
470
int nId = vvNew[nUBucket][nUBucketPos];
468
- assert (mapInfo.count (nId) == 1 );
469
- CAddrInfo& info = mapInfo[nId];
471
+ const auto it_found{mapInfo.find (nId)};
472
+ assert (it_found != mapInfo.end ());
473
+ const CAddrInfo& info{it_found->second };
470
474
if (insecure_rand.randbits (30 ) < fChanceFactor * info.GetChance () * (1 << 30 ))
471
475
return info;
472
476
fChanceFactor *= 1.2 ;
@@ -517,15 +521,15 @@ int CAddrMan::Check_()
517
521
518
522
for (int n = 0 ; n < ADDRMAN_TRIED_BUCKET_COUNT; n++) {
519
523
for (int i = 0 ; i < ADDRMAN_BUCKET_SIZE; i++) {
520
- if (vvTried[n][i] != -1 ) {
521
- if (!setTried.count (vvTried[n][i]))
522
- return -11 ;
523
- if (mapInfo[vvTried[n][i]].GetTriedBucket (nKey, m_asmap) != n)
524
- return -17 ;
525
- if (mapInfo[vvTried[n][i]].GetBucketPosition (nKey, false , n) != i)
526
- return -18 ;
527
- setTried.erase (vvTried[n][i]);
528
- }
524
+ if (vvTried[n][i] != -1 ) {
525
+ if (!setTried.count (vvTried[n][i]))
526
+ return -11 ;
527
+ if (mapInfo[vvTried[n][i]].GetTriedBucket (nKey, m_asmap) != n)
528
+ return -17 ;
529
+ if (mapInfo[vvTried[n][i]].GetBucketPosition (nKey, false , n) != i)
530
+ return -18 ;
531
+ setTried.erase (vvTried[n][i]);
532
+ }
529
533
}
530
534
}
531
535
@@ -553,7 +557,7 @@ int CAddrMan::Check_()
553
557
}
554
558
#endif
555
559
556
- void CAddrMan::GetAddr_ (std::vector<CAddress>& vAddr, size_t max_addresses, size_t max_pct, std::optional<Network> network)
560
+ void CAddrMan::GetAddr_ (std::vector<CAddress>& vAddr, size_t max_addresses, size_t max_pct, std::optional<Network> network) const
557
561
{
558
562
AssertLockHeld (cs);
559
563
@@ -573,9 +577,10 @@ void CAddrMan::GetAddr_(std::vector<CAddress>& vAddr, size_t max_addresses, size
573
577
574
578
int nRndPos = insecure_rand.randrange (vRandom.size () - n) + n;
575
579
SwapRandom (n, nRndPos);
576
- assert (mapInfo.count (vRandom[n]) == 1 );
580
+ const auto it{mapInfo.find (vRandom[n])};
581
+ assert (it != mapInfo.end ());
577
582
578
- const CAddrInfo& ai = mapInfo[vRandom[n]] ;
583
+ const CAddrInfo& ai{it-> second } ;
579
584
580
585
// Filter by network (optional)
581
586
if (network != std::nullopt && ai.GetNetClass () != network) continue ;
0 commit comments