diff options
author | Ben Woosley <ben.woosley@gmail.com> | 2018-05-15 15:41:53 -0700 |
---|---|---|
committer | Ben Woosley <ben.woosley@gmail.com> | 2018-06-11 13:12:55 -0700 |
commit | 9b72c988a0050d8932275c74c60928918ee7ef71 (patch) | |
tree | 2853b851aaffa1fe04f3f904e094b2962941f120 /src/init.cpp | |
parent | 7c32b414b6325743c99fed1208bc53ab0fa1996f (diff) |
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/init.cpp')
-rw-r--r-- | src/init.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/init.cpp b/src/init.cpp index 9246f6e71c..f9af1629dc 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -614,7 +614,7 @@ static void CleanupBlockRevFiles() // keeping a separate counter. Once we hit a gap (or if 0 doesn't exist) // start removing block files. int nContigCounter = 0; - for (const std::pair<std::string, fs::path>& item : mapBlockFiles) { + for (const std::pair<const std::string, fs::path>& item : mapBlockFiles) { if (atoi(item.first) == nContigCounter) { nContigCounter++; continue; |