aboutsummaryrefslogtreecommitdiff
path: root/src/addrman.cpp
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2015-08-06 19:49:19 +0200
committerPieter Wuille <pieter.wuille@gmail.com>2015-08-26 01:59:09 +0200
commitc33c11ebacb93d74370f44f6c24d447da88648f4 (patch)
tree4106b2c5f11c440cf1705ca64cbebcee52cd728d /src/addrman.cpp
parentda9beb288d2ee35b9c70513dd18f220b2dc32f16 (diff)
Improve addrman Select() performance when buckets are nearly empty
Diffstat (limited to 'src/addrman.cpp')
-rw-r--r--src/addrman.cpp12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/addrman.cpp b/src/addrman.cpp
index b605f4351d..ff1f7e9187 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -341,8 +341,10 @@ CAddrInfo CAddrMan::Select_()
while (1) {
int nKBucket = GetRandInt(ADDRMAN_TRIED_BUCKET_COUNT);
int nKBucketPos = GetRandInt(ADDRMAN_BUCKET_SIZE);
- if (vvTried[nKBucket][nKBucketPos] == -1)
- continue;
+ while (vvTried[nKBucket][nKBucketPos] == -1) {
+ nKBucket = (nKBucket + insecure_rand()) % ADDRMAN_TRIED_BUCKET_COUNT;
+ nKBucketPos = (nKBucketPos + insecure_rand()) % ADDRMAN_BUCKET_SIZE;
+ }
int nId = vvTried[nKBucket][nKBucketPos];
assert(mapInfo.count(nId) == 1);
CAddrInfo& info = mapInfo[nId];
@@ -356,8 +358,10 @@ CAddrInfo CAddrMan::Select_()
while (1) {
int nUBucket = GetRandInt(ADDRMAN_NEW_BUCKET_COUNT);
int nUBucketPos = GetRandInt(ADDRMAN_BUCKET_SIZE);
- if (vvNew[nUBucket][nUBucketPos] == -1)
- continue;
+ while (vvNew[nUBucket][nUBucketPos] == -1) {
+ nUBucket = (nUBucket + insecure_rand()) % ADDRMAN_NEW_BUCKET_COUNT;
+ nUBucketPos = (nUBucketPos + insecure_rand()) % ADDRMAN_BUCKET_SIZE;
+ }
int nId = vvNew[nUBucket][nUBucketPos];
assert(mapInfo.count(nId) == 1);
CAddrInfo& info = mapInfo[nId];