mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 22:50:59 +01:00
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-
This commit is contained in:
@@ -475,7 +475,7 @@ static UniValue getnetworkinfo(const JSONRPCRequest& request)
|
||||
UniValue localAddresses(UniValue::VARR);
|
||||
{
|
||||
LOCK(cs_mapLocalHost);
|
||||
for (const std::pair<CNetAddr, LocalServiceInfo> &item : mapLocalHost)
|
||||
for (const std::pair<const CNetAddr, LocalServiceInfo> &item : mapLocalHost)
|
||||
{
|
||||
UniValue rec(UniValue::VOBJ);
|
||||
rec.pushKV("address", item.first.ToString());
|
||||
|
||||
Reference in New Issue
Block a user