From 8f2f1e0458d263dc9b51caad0adc0246e3580114 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Barbosa?= Date: Sun, 13 Aug 2017 15:04:57 +0100 Subject: wallet: Avoid second mapWallet lookup --- src/wallet/feebumper.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/wallet/feebumper.cpp') diff --git a/src/wallet/feebumper.cpp b/src/wallet/feebumper.cpp index 4bfd8726a5..5e84597f04 100644 --- a/src/wallet/feebumper.cpp +++ b/src/wallet/feebumper.cpp @@ -76,12 +76,12 @@ CFeeBumper::CFeeBumper(const CWallet *pWallet, const uint256 txidIn, const CCoin vErrors.clear(); bumpedTxid.SetNull(); AssertLockHeld(pWallet->cs_wallet); - if (!pWallet->mapWallet.count(txid)) { + auto it = pWallet->mapWallet.find(txid); + if (it == pWallet->mapWallet.end()) { vErrors.push_back("Invalid or non-wallet transaction id"); currentResult = BumpFeeResult::INVALID_ADDRESS_OR_KEY; return; } - auto it = pWallet->mapWallet.find(txid); const CWalletTx& wtx = it->second; if (!preconditionChecks(pWallet, wtx)) { @@ -241,12 +241,13 @@ bool CFeeBumper::commit(CWallet *pWallet) if (!vErrors.empty() || currentResult != BumpFeeResult::OK) { return false; } - if (txid.IsNull() || !pWallet->mapWallet.count(txid)) { + auto it = txid.IsNull() ? pWallet->mapWallet.end() : pWallet->mapWallet.find(txid); + if (it == pWallet->mapWallet.end()) { vErrors.push_back("Invalid or non-wallet transaction id"); currentResult = BumpFeeResult::MISC_ERROR; return false; } - CWalletTx& oldWtx = pWallet->mapWallet[txid]; + CWalletTx& oldWtx = it->second; // make sure the transaction still has no descendants and hasn't been mined in the meantime if (!preconditionChecks(pWallet, oldWtx)) { -- cgit v1.2.3