Skip to content

Commit bc886fc

Browse files
committed
Change mapWallet to be a std::unordered_map
1 parent 2723560 commit bc886fc

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/wallet/wallet.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ std::shared_ptr<CWallet> RestoreWallet(WalletContext& context, const fs::path& b
414414
const CWalletTx* CWallet::GetWalletTx(const uint256& hash) const
415415
{
416416
AssertLockHeld(cs_wallet);
417-
std::map<uint256, CWalletTx>::const_iterator it = mapWallet.find(hash);
417+
const auto it = mapWallet.find(hash);
418418
if (it == mapWallet.end())
419419
return nullptr;
420420
return &(it->second);
@@ -551,7 +551,7 @@ std::set<uint256> CWallet::GetConflicts(const uint256& txid) const
551551
std::set<uint256> result;
552552
AssertLockHeld(cs_wallet);
553553

554-
std::map<uint256, CWalletTx>::const_iterator it = mapWallet.find(txid);
554+
const auto it = mapWallet.find(txid);
555555
if (it == mapWallet.end())
556556
return result;
557557
const CWalletTx& wtx = it->second;
@@ -642,7 +642,7 @@ bool CWallet::IsSpent(const COutPoint& outpoint) const
642642

643643
for (TxSpends::const_iterator it = range.first; it != range.second; ++it) {
644644
const uint256& wtxid = it->second;
645-
std::map<uint256, CWalletTx>::const_iterator mit = mapWallet.find(wtxid);
645+
const auto mit = mapWallet.find(wtxid);
646646
if (mit != mapWallet.end()) {
647647
int depth = GetTxDepthInMainChain(mit->second);
648648
if (depth > 0 || (depth == 0 && !mit->second.isAbandoned()))
@@ -1372,7 +1372,7 @@ CAmount CWallet::GetDebit(const CTxIn &txin, const isminefilter& filter) const
13721372
{
13731373
{
13741374
LOCK(cs_wallet);
1375-
std::map<uint256, CWalletTx>::const_iterator mi = mapWallet.find(txin.prevout.hash);
1375+
const auto mi = mapWallet.find(txin.prevout.hash);
13761376
if (mi != mapWallet.end())
13771377
{
13781378
const CWalletTx& prev = (*mi).second;
@@ -1961,7 +1961,7 @@ bool CWallet::SignTransaction(CMutableTransaction& tx) const
19611961
// Build coins map
19621962
std::map<COutPoint, Coin> coins;
19631963
for (auto& input : tx.vin) {
1964-
std::map<uint256, CWalletTx>::const_iterator mi = mapWallet.find(input.prevout.hash);
1964+
const auto mi = mapWallet.find(input.prevout.hash);
19651965
if(mi == mapWallet.end() || input.prevout.n >= mi->second.tx->vout.size()) {
19661966
return false;
19671967
}

src/wallet/wallet.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <policy/feerate.h>
1515
#include <psbt.h>
1616
#include <tinyformat.h>
17+
#include <util/hasher.h>
1718
#include <util/message.h>
1819
#include <util/result.h>
1920
#include <util/strencodings.h>
@@ -37,6 +38,7 @@
3738
#include <stdint.h>
3839
#include <string>
3940
#include <utility>
41+
#include <unordered_map>
4042
#include <vector>
4143

4244
#include <boost/signals2/signal.hpp>
@@ -390,7 +392,7 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati
390392

391393
/** Map from txid to CWalletTx for all transactions this wallet is
392394
* interested in, including received and sent transactions. */
393-
std::map<uint256, CWalletTx> mapWallet GUARDED_BY(cs_wallet);
395+
std::unordered_map<uint256, CWalletTx, SaltedTxidHasher> mapWallet GUARDED_BY(cs_wallet);
394396

395397
typedef std::multimap<int64_t, CWalletTx*> TxItems;
396398
TxItems wtxOrdered;

0 commit comments

Comments
 (0)