Browse Source

Avoid repeated lookups in mapOrphanTransactions and mapOrphanTransactionsByPrev

0.10
Wladimir J. van der Laan 10 years ago
parent
commit
89d91f6aa7
  1. 23
      src/main.cpp

23
src/main.cpp

@ -492,16 +492,17 @@ bool AddOrphanTx(const CTransaction& tx)
void static EraseOrphanTx(uint256 hash) void static EraseOrphanTx(uint256 hash)
{ {
if (!mapOrphanTransactions.count(hash)) map<uint256, CTransaction>::iterator it = mapOrphanTransactions.find(hash);
if (it == mapOrphanTransactions.end())
return; return;
const CTransaction& tx = mapOrphanTransactions[hash]; BOOST_FOREACH(const CTxIn& txin, it->second.vin)
BOOST_FOREACH(const CTxIn& txin, tx.vin)
{ {
mapOrphanTransactionsByPrev[txin.prevout.hash].erase(hash); map<uint256, set<uint256> >::iterator itPrev = mapOrphanTransactionsByPrev.find(txin.prevout.hash);
if (mapOrphanTransactionsByPrev[txin.prevout.hash].empty()) itPrev->second.erase(hash);
mapOrphanTransactionsByPrev.erase(txin.prevout.hash); if (itPrev->second.empty())
mapOrphanTransactionsByPrev.erase(itPrev);
} }
mapOrphanTransactions.erase(hash); mapOrphanTransactions.erase(it);
} }
unsigned int LimitOrphanTxSize(unsigned int nMaxOrphans) 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 // Recursively process any orphan transactions that depended on this one
for (unsigned int i = 0; i < vWorkQueue.size(); i++) for (unsigned int i = 0; i < vWorkQueue.size(); i++)
{ {
uint256 hashPrev = vWorkQueue[i]; map<uint256, set<uint256> >::iterator itByPrev = mapOrphanTransactionsByPrev.find(vWorkQueue[i]);
for (set<uint256>::iterator mi = mapOrphanTransactionsByPrev[hashPrev].begin(); if (itByPrev == mapOrphanTransactionsByPrev.end())
mi != mapOrphanTransactionsByPrev[hashPrev].end(); continue;
for (set<uint256>::iterator mi = itByPrev->second.begin();
mi != itByPrev->second.end();
++mi) ++mi)
{ {
const uint256& orphanHash = *mi; const uint256& orphanHash = *mi;

Loading…
Cancel
Save