diff options
author | Wladimir J. van der Laan <laanwj@gmail.com> | 2014-09-09 09:13:38 +0200 |
---|---|---|
committer | Wladimir J. van der Laan <laanwj@gmail.com> | 2014-09-09 09:16:22 +0200 |
commit | 8bc0a0173e885a5b60e12d3769604236967c262e (patch) | |
tree | df48728e656e843b7dd2dafa5956ecbf9d522f52 | |
parent | eecd3c0fb0625b036f68a7830dda8edde21fcb90 (diff) | |
parent | 89d91f6aa74da5e3fb1bbd08ce20ab3b9d593abd (diff) | |
download | bitcoin-8bc0a0173e885a5b60e12d3769604236967c262e.tar.xz |
Merge pull request #4873
89d91f6 Avoid repeated lookups in mapOrphanTransactions and mapOrphanTransactionsByPrev (Wladimir J. van der Laan)
-rw-r--r-- | src/main.cpp | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/src/main.cpp b/src/main.cpp index a3b31b719d..2e24eb950f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -492,16 +492,17 @@ bool AddOrphanTx(const CTransaction& tx) void static EraseOrphanTx(uint256 hash) { - if (!mapOrphanTransactions.count(hash)) + map<uint256, CTransaction>::iterator it = mapOrphanTransactions.find(hash); + if (it == mapOrphanTransactions.end()) return; - const CTransaction& tx = mapOrphanTransactions[hash]; - BOOST_FOREACH(const CTxIn& txin, tx.vin) + BOOST_FOREACH(const CTxIn& txin, it->second.vin) { - mapOrphanTransactionsByPrev[txin.prevout.hash].erase(hash); - if (mapOrphanTransactionsByPrev[txin.prevout.hash].empty()) - mapOrphanTransactionsByPrev.erase(txin.prevout.hash); + map<uint256, set<uint256> >::iterator itPrev = mapOrphanTransactionsByPrev.find(txin.prevout.hash); + itPrev->second.erase(hash); + if (itPrev->second.empty()) + mapOrphanTransactionsByPrev.erase(itPrev); } - mapOrphanTransactions.erase(hash); + mapOrphanTransactions.erase(it); } unsigned int LimitOrphanTxSize(unsigned int nMaxOrphans) @@ -3769,9 +3770,11 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, // Recursively process any orphan transactions that depended on this one for (unsigned int i = 0; i < vWorkQueue.size(); i++) { - uint256 hashPrev = vWorkQueue[i]; - for (set<uint256>::iterator mi = mapOrphanTransactionsByPrev[hashPrev].begin(); - mi != mapOrphanTransactionsByPrev[hashPrev].end(); + map<uint256, set<uint256> >::iterator itByPrev = mapOrphanTransactionsByPrev.find(vWorkQueue[i]); + if (itByPrev == mapOrphanTransactionsByPrev.end()) + continue; + for (set<uint256>::iterator mi = itByPrev->second.begin(); + mi != itByPrev->second.end(); ++mi) { const uint256& orphanHash = *mi; |