Skip to content

Commit 2b6bd12

Browse files
committed
refactor: de-duplicate lookups
retain the values needed to prevent redundant node lookups
1 parent a13f374 commit 2b6bd12

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/addrman.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -757,10 +757,10 @@ std::pair<CAddress, NodeSeconds> AddrManImpl::Select_(bool new_only, std::option
757757

758758
// Iterate over the positions of that bucket, starting at the initial one,
759759
// and looping around.
760-
int i;
760+
int i, position, node_id;
761761
for (i = 0; i < ADDRMAN_BUCKET_SIZE; ++i) {
762-
int position = (initial_position + i) % ADDRMAN_BUCKET_SIZE;
763-
int node_id = GetEntry(search_tried, bucket, position);
762+
position = (initial_position + i) % ADDRMAN_BUCKET_SIZE;
763+
node_id = GetEntry(search_tried, bucket, position);
764764
if (node_id != -1) {
765765
if (network.has_value()) {
766766
const auto it{mapInfo.find(node_id)};
@@ -777,9 +777,7 @@ std::pair<CAddress, NodeSeconds> AddrManImpl::Select_(bool new_only, std::option
777777
if (i == ADDRMAN_BUCKET_SIZE) continue;
778778

779779
// Find the entry to return.
780-
int position = (initial_position + i) % ADDRMAN_BUCKET_SIZE;
781-
int nId = GetEntry(search_tried, bucket, position);
782-
const auto it_found{mapInfo.find(nId)};
780+
const auto it_found{mapInfo.find(node_id)};
783781
assert(it_found != mapInfo.end());
784782
const AddrInfo& info{it_found->second};
785783

0 commit comments

Comments
 (0)