From 9b72c988a0050d8932275c74c60928918ee7ef71 Mon Sep 17 00:00:00 2001 From: Ben Woosley Date: Tue, 15 May 2018 15:41:53 -0700 Subject: 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. 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 > vSortedByHeight; vSortedByHeight.reserve(mapBlockIndex.size()); - for (const std::pair& item : mapBlockIndex) + for (const std::pair& 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 setBlkDataFiles; - for (const std::pair& item : mapBlockIndex) + for (const std::pair& item : mapBlockIndex) { CBlockIndex* pindex = item.second; if (pindex->nStatus & BLOCK_HAVE_DATA) { -- cgit v1.2.3