Auto merge of #4605 - daira:more-iterator-cleanups, r=daira

More iterator cleanups

Signed-off-by: Daira Hopwood <daira@jacaranda.org>
This commit is contained in:
Homu 2020-07-15 20:09:37 +00:00
commit 2ba4f16590
1 changed files with 9 additions and 13 deletions

View File

@ -3870,10 +3870,8 @@ bool ReceivedBlockTransactions(
}
std::pair<std::multimap<CBlockIndex*, CBlockIndex*>::iterator, std::multimap<CBlockIndex*, CBlockIndex*>::iterator> range = mapBlocksUnlinked.equal_range(pindex);
while (range.first != range.second) {
std::multimap<CBlockIndex*, CBlockIndex*>::iterator it = range.first;
queue.push_back(it->second);
range.first++;
mapBlocksUnlinked.erase(it);
queue.push_back(range.first->second);
range.first = mapBlocksUnlinked.erase(range.first);
}
}
} else {
@ -4411,10 +4409,10 @@ void PruneOneBlockFile(const int fileNumber)
// mapBlocksUnlinked or setBlockIndexCandidates.
std::pair<std::multimap<CBlockIndex*, CBlockIndex*>::iterator, std::multimap<CBlockIndex*, CBlockIndex*>::iterator> range = mapBlocksUnlinked.equal_range(pindex->pprev);
while (range.first != range.second) {
std::multimap<CBlockIndex *, CBlockIndex *>::iterator it = range.first;
range.first++;
if (it->second == pindex) {
mapBlocksUnlinked.erase(it);
if (range.first->second == pindex) {
range.first = mapBlocksUnlinked.erase(range.first);
} else {
++range.first;
}
}
}
@ -5160,20 +5158,18 @@ bool LoadExternalBlockFile(const CChainParams& chainparams, FILE* fileIn, CDiskB
queue.pop_front();
std::pair<std::multimap<uint256, CDiskBlockPos>::iterator, std::multimap<uint256, CDiskBlockPos>::iterator> range = mapBlocksUnknownParent.equal_range(head);
while (range.first != range.second) {
std::multimap<uint256, CDiskBlockPos>::iterator it = range.first;
if (ReadBlockFromDisk(block, it->second, chainparams.GetConsensus()))
if (ReadBlockFromDisk(block, range.first->second, chainparams.GetConsensus()))
{
LogPrintf("%s: Processing out of order child %s of %s\n", __func__, block.GetHash().ToString(),
head.ToString());
CValidationState dummy;
if (ProcessNewBlock(dummy, chainparams, NULL, &block, true, &it->second))
if (ProcessNewBlock(dummy, chainparams, NULL, &block, true, &(range.first->second)))
{
nLoaded++;
queue.push_back(block.GetHash());
}
}
range.first++;
mapBlocksUnknownParent.erase(it);
range.first = mapBlocksUnknownParent.erase(range.first);
}
}
} catch (const std::exception& e) {