diff options
author | MarcoFalke <falke.marco@gmail.com> | 2021-05-13 13:43:36 +0200 |
---|---|---|
committer | MarcoFalke <falke.marco@gmail.com> | 2021-07-21 16:01:14 +0200 |
commit | fae0c79351ce34186249d44af0c5c9c7521f4b6c (patch) | |
tree | 07be60559c4d33a3d7e430552ea0888052b761b6 /src/addrman.cpp | |
parent | fa02934c8c9d290ea4d12683e8680c70967a4d3a (diff) | |
download | bitcoin-fae0c79351ce34186249d44af0c5c9c7521f4b6c.tar.xz |
refactor: Mark CAddrMan::GetAddr const
Diffstat (limited to 'src/addrman.cpp')
-rw-r--r-- | src/addrman.cpp | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/src/addrman.cpp b/src/addrman.cpp index 6cbcbed839..db5166be44 100644 --- a/src/addrman.cpp +++ b/src/addrman.cpp @@ -138,7 +138,7 @@ CAddrInfo* CAddrMan::Create(const CAddress& addr, const CNetAddr& addrSource, in return &mapInfo[nId]; } -void CAddrMan::SwapRandom(unsigned int nRndPos1, unsigned int nRndPos2) +void CAddrMan::SwapRandom(unsigned int nRndPos1, unsigned int nRndPos2) const { AssertLockHeld(cs); @@ -150,11 +150,13 @@ void CAddrMan::SwapRandom(unsigned int nRndPos1, unsigned int nRndPos2) int nId1 = vRandom[nRndPos1]; int nId2 = vRandom[nRndPos2]; - assert(mapInfo.count(nId1) == 1); - assert(mapInfo.count(nId2) == 1); + const auto it_1{mapInfo.find(nId1)}; + const auto it_2{mapInfo.find(nId2)}; + assert(it_1 != mapInfo.end()); + assert(it_2 != mapInfo.end()); - mapInfo[nId1].nRandomPos = nRndPos2; - mapInfo[nId2].nRandomPos = nRndPos1; + it_1->second.nRandomPos = nRndPos2; + it_2->second.nRandomPos = nRndPos1; vRandom[nRndPos1] = nId2; vRandom[nRndPos2] = nId1; @@ -541,7 +543,7 @@ int CAddrMan::Check_() } #endif -void CAddrMan::GetAddr_(std::vector<CAddress>& vAddr, size_t max_addresses, size_t max_pct, std::optional<Network> network) +void CAddrMan::GetAddr_(std::vector<CAddress>& vAddr, size_t max_addresses, size_t max_pct, std::optional<Network> network) const { AssertLockHeld(cs); @@ -561,9 +563,10 @@ void CAddrMan::GetAddr_(std::vector<CAddress>& vAddr, size_t max_addresses, size int nRndPos = insecure_rand.randrange(vRandom.size() - n) + n; SwapRandom(n, nRndPos); - assert(mapInfo.count(vRandom[n]) == 1); + const auto it{mapInfo.find(vRandom[n])}; + assert(it != mapInfo.end()); - const CAddrInfo& ai = mapInfo[vRandom[n]]; + const CAddrInfo& ai{it->second}; // Filter by network (optional) if (network != std::nullopt && ai.GetNetClass() != network) continue; |