From af9510e0374443b093d633a91c4f1f8bf5071292 Mon Sep 17 00:00:00 2001 From: Murch Date: Sun, 6 Dec 2015 22:20:41 +0100 Subject: Moved set reduction to the end of ApproximateBestSubset to reduce performance impact --- src/wallet/wallet.cpp | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) (limited to 'src/wallet') diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 06b77bb9b9..f9e8a97ae6 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1605,7 +1605,7 @@ static void ApproximateBestSubset(vector= nTargetValue) { fReachedTarget = true; - - for (unsigned int i = 0; i < vValue.size(); i++) - { - //The target has been reached, but the candidate set may contain extraneous inputs. - //This iterates over all inputs and deducts any that are included, but smaller - //than the amount nTargetValue is still exceeded by. - if (vfIncluded[i] && (nTotal - vValue[i].first) >= nTargetValue ) - { - vfIncluded[i] = false; - nTotal -= vValue[i].first; - } - } - if (nTotal < nBest) { nBest = nTotal; vfBest = vfIncluded; } - nTotal -= vValue[i].first; - vfIncluded[i] = false; } } } } } + + //Reduces the approximate best subset by removing any inputs that are smaller than the surplus of nTotal beyond nTargetValue. + for (unsigned int i = 0; i < vValue.size(); i++) + { + if (vfBest[i] && (nBest - vValue[i].first) >= nTargetValue ) + { + vfBest[i] = false; + nBest -= vValue[i].first; + } + } } bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int nConfTheirs, vector vCoins, -- cgit v1.2.3