From ed79e4f497a9a7747b006a5cb04d4173a6bbc1c5 Mon Sep 17 00:00:00 2001 From: Jonas Schnelli Date: Fri, 24 Mar 2017 10:54:48 +0100 Subject: Optimize GetOldestKeyPoolTime(), return as soon as we have both oldest keys --- src/wallet/wallet.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 0a06879754..d7d2927ba2 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -3069,12 +3069,18 @@ int64_t CWallet::GetOldestKeyPoolTime() for(const int64_t& id : setKeyPool) { - if (!walletdb.ReadPool(id, keypool)) + if (!walletdb.ReadPool(id, keypool)) { throw std::runtime_error(std::string(__func__) + ": read failed"); - if (keypool.fInternal && keypool.nTime < oldest_internal) + } + if (keypool.fInternal && keypool.nTime < oldest_internal) { oldest_internal = keypool.nTime; - else if (!keypool.fInternal && keypool.nTime < oldest_external) + } + else if (!keypool.fInternal && keypool.nTime < oldest_external) { oldest_external = keypool.nTime; + } + if (oldest_internal != now && oldest_external != now) { + break; + } } return std::max(oldest_internal, oldest_external); } -- cgit v1.2.3