From 2b6bd12eea0c970881753124ec3f0a67e2de8e17 Mon Sep 17 00:00:00 2001 From: Amiti Uttarwar Date: Tue, 25 Apr 2023 16:29:29 +0100 Subject: [PATCH] refactor: de-duplicate lookups retain the values needed to prevent redundant node lookups --- src/addrman.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/addrman.cpp b/src/addrman.cpp index cdfd079fcdf..30ce2cadc88 100644 --- a/src/addrman.cpp +++ b/src/addrman.cpp @@ -757,10 +757,10 @@ std::pair 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 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};