From f8d9593ce076e6e568f896e247d58a0eb7accf86 Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Mon, 8 Sep 2014 17:37:26 +0200 Subject: [PATCH] Avoid repeated lookups in mapOrphanTransactions and mapOrphanTransactionsByPrev Rebased-From: 89d91f6 Rebased-By: Wladimir J. van der Laan --- src/main.cpp | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 0bc2bc001..2f15611b3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -318,16 +318,17 @@ bool AddOrphanTx(const CTransaction& tx) void static EraseOrphanTx(uint256 hash) { - if (!mapOrphanTransactions.count(hash)) + map::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 >::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) @@ -3585,9 +3586,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::iterator mi = mapOrphanTransactionsByPrev[hashPrev].begin(); - mi != mapOrphanTransactionsByPrev[hashPrev].end(); + map >::iterator itByPrev = mapOrphanTransactionsByPrev.find(vWorkQueue[i]); + if (itByPrev == mapOrphanTransactionsByPrev.end()) + continue; + for (set::iterator mi = itByPrev->second.begin(); + mi != itByPrev->second.end(); ++mi) { const uint256& orphanHash = *mi;