aboutsummaryrefslogtreecommitdiff
path: root/src/validation.cpp
diff options
context:
space:
mode:
authorBen Woosley <ben.woosley@gmail.com>2018-05-15 15:41:53 -0700
committerBen Woosley <ben.woosley@gmail.com>2018-06-11 13:12:55 -0700
commit9b72c988a0050d8932275c74c60928918ee7ef71 (patch)
tree2853b851aaffa1fe04f3f904e094b2962941f120 /src/validation.cpp
parent7c32b414b6325743c99fed1208bc53ab0fa1996f (diff)
downloadbitcoin-9b72c988a0050d8932275c74c60928918ee7ef71.tar.xz
scripted-diff: Avoid temporary copies when looping over std::map
The ::value_type of the std::map/std::multimap/std::unordered_map containers is std::pair<const Key, T>. Dropping the const results in an unnecessary copy, for example in C++11 range-based loops. For this I started with a more general scripted diff, then narrowed it down based on the inspection showing that all actual map/multimap/unordered_map variables used in loops start with m or have map in the name. -BEGIN VERIFY SCRIPT- sed -i -E 's/for \(([^<]*)std::pair<([^c])(.+) : m/for (\1std::pair<const \2\3 : m/' src/*.cpp src/**/*.cpp sed -i -E 's/for \(([^<]*)std::pair<([^c])(.+) : (.*)map/for (\1std::pair<const \2\3 : \4map/' src/*.cpp src/**/*.cpp -END VERIFY SCRIPT-
Diffstat (limited to 'src/validation.cpp')
-rw-r--r--src/validation.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/validation.cpp b/src/validation.cpp
index 9791d6e2d8..1262951649 100644
--- a/src/validation.cpp
+++ b/src/validation.cpp
@@ -3840,7 +3840,7 @@ bool CChainState::LoadBlockIndex(const Consensus::Params& consensus_params, CBlo
// Calculate nChainWork
std::vector<std::pair<int, CBlockIndex*> > vSortedByHeight;
vSortedByHeight.reserve(mapBlockIndex.size());
- for (const std::pair<uint256, CBlockIndex*>& item : mapBlockIndex)
+ for (const std::pair<const uint256, CBlockIndex*>& item : mapBlockIndex)
{
CBlockIndex* pindex = item.second;
vSortedByHeight.push_back(std::make_pair(pindex->nHeight, pindex));
@@ -3907,7 +3907,7 @@ bool static LoadBlockIndexDB(const CChainParams& chainparams)
// Check presence of blk files
LogPrintf("Checking all blk files are present...\n");
std::set<int> setBlkDataFiles;
- for (const std::pair<uint256, CBlockIndex*>& item : mapBlockIndex)
+ for (const std::pair<const uint256, CBlockIndex*>& item : mapBlockIndex)
{
CBlockIndex* pindex = item.second;
if (pindex->nStatus & BLOCK_HAVE_DATA) {