diff options
author | Amiti Uttarwar <amiti@uttarwar.org> | 2023-04-25 16:29:29 +0100 |
---|---|---|
committer | Amiti Uttarwar <amiti@uttarwar.org> | 2023-05-24 11:39:31 -0700 |
commit | 2b6bd12eea0c970881753124ec3f0a67e2de8e17 (patch) | |
tree | cc0c03c7f2c28dcb16f54da998449d3e42dd9412 /src/addrman.cpp | |
parent | a13f3746dccd9c4ec16d6bfe9b33ebd26e3238e1 (diff) |
refactor: de-duplicate lookups
retain the values needed to prevent redundant node lookups
Diffstat (limited to 'src/addrman.cpp')
-rw-r--r-- | src/addrman.cpp | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/src/addrman.cpp b/src/addrman.cpp index cdfd079fcd..30ce2cadc8 100644 --- a/src/addrman.cpp +++ b/src/addrman.cpp @@ -757,10 +757,10 @@ std::pair<CAddress, NodeSeconds> AddrManImpl::Select_(bool new_only, std::option // Iterate over the positions of that bucket, starting at the initial one, // and looping around. - int i; + int i, position, node_id; for (i = 0; i < ADDRMAN_BUCKET_SIZE; ++i) { - int position = (initial_position + i) % ADDRMAN_BUCKET_SIZE; - int node_id = GetEntry(search_tried, bucket, position); + position = (initial_position + i) % ADDRMAN_BUCKET_SIZE; + node_id = GetEntry(search_tried, bucket, position); if (node_id != -1) { if (network.has_value()) { const auto it{mapInfo.find(node_id)}; @@ -777,9 +777,7 @@ std::pair<CAddress, NodeSeconds> AddrManImpl::Select_(bool new_only, std::option if (i == ADDRMAN_BUCKET_SIZE) continue; // Find the entry to return. - int position = (initial_position + i) % ADDRMAN_BUCKET_SIZE; - int nId = GetEntry(search_tried, bucket, position); - const auto it_found{mapInfo.find(nId)}; + const auto it_found{mapInfo.find(node_id)}; assert(it_found != mapInfo.end()); const AddrInfo& info{it_found->second}; |