From 039425cf4fab56ea0e42564849a15485afa582ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Barbosa?= Date: Fri, 26 Jan 2018 16:28:31 +0000 Subject: [PATCH] [wallet] Remove duplicate mapWallet lookups --- src/wallet/wallet.cpp | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 07a23ce249bed..2b8019395c9f3 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -531,14 +531,11 @@ void CWallet::SyncMetaData(std::pair ran int nMinOrderPos = std::numeric_limits::max(); const CWalletTx* copyFrom = nullptr; - for (TxSpends::iterator it = range.first; it != range.second; ++it) - { - const uint256& hash = it->second; - int n = mapWallet[hash].nOrderPos; - if (n < nMinOrderPos) - { - nMinOrderPos = n; - copyFrom = &mapWallet[hash]; + for (TxSpends::iterator it = range.first; it != range.second; ++it) { + const CWalletTx* wtx = &mapWallet[it->second]; + if (wtx->nOrderPos < nMinOrderPos) { + nMinOrderPos = wtx->nOrderPos;; + copyFrom = wtx; } } @@ -988,9 +985,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, bool fFlushOnClose) bool CWallet::LoadToWallet(const CWalletTx& wtxIn) { uint256 hash = wtxIn.GetHash(); - - mapWallet[hash] = wtxIn; - CWalletTx& wtx = mapWallet[hash]; + CWalletTx& wtx = mapWallet.emplace(hash, wtxIn).first->second; wtx.BindWallet(this); wtxOrdered.insert(std::make_pair(wtx.nOrderPos, TxPair(&wtx, nullptr))); AddToSpends(hash);