Skip to content

Commit 7936446

Browse files
committed
Merge #12276: Remove duplicate mapWallet lookups
039425c [wallet] Remove duplicate mapWallet lookups (João Barbosa) Pull request description: Tree-SHA512: 8075925d2adb64737c691e988d74a37bc326711aaee2c37327361679c051f219fa500e14cbcdb6a169352bcdbab160e11df4276b2657e19e12908ee2d4444d30
2 parents 288deac + 039425c commit 7936446

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

src/wallet/wallet.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -531,14 +531,11 @@ void CWallet::SyncMetaData(std::pair<TxSpends::iterator, TxSpends::iterator> ran
531531

532532
int nMinOrderPos = std::numeric_limits<int>::max();
533533
const CWalletTx* copyFrom = nullptr;
534-
for (TxSpends::iterator it = range.first; it != range.second; ++it)
535-
{
536-
const uint256& hash = it->second;
537-
int n = mapWallet[hash].nOrderPos;
538-
if (n < nMinOrderPos)
539-
{
540-
nMinOrderPos = n;
541-
copyFrom = &mapWallet[hash];
534+
for (TxSpends::iterator it = range.first; it != range.second; ++it) {
535+
const CWalletTx* wtx = &mapWallet[it->second];
536+
if (wtx->nOrderPos < nMinOrderPos) {
537+
nMinOrderPos = wtx->nOrderPos;;
538+
copyFrom = wtx;
542539
}
543540
}
544541

@@ -988,9 +985,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, bool fFlushOnClose)
988985
bool CWallet::LoadToWallet(const CWalletTx& wtxIn)
989986
{
990987
uint256 hash = wtxIn.GetHash();
991-
992-
mapWallet[hash] = wtxIn;
993-
CWalletTx& wtx = mapWallet[hash];
988+
CWalletTx& wtx = mapWallet.emplace(hash, wtxIn).first->second;
994989
wtx.BindWallet(this);
995990
wtxOrdered.insert(std::make_pair(wtx.nOrderPos, TxPair(&wtx, nullptr)));
996991
AddToSpends(hash);

0 commit comments

Comments
 (0)