Plus a use of std::copy() instead of manual copying.
(The loop on line 117 is already done in #10493).
314 | {
315 | LOCK(cs_vNodes);
316 | for (CNode* pnode : vNodes)
317 | - if (subNet.Match((CNetAddr)pnode->addr))
318 | - return (pnode);
319 | + if (subNet.Match((CNetAddr)pnode->addr))
Please switch to brackets here.
Done.
Concept ACK (strong ACK! :-))
How about "improving" those FindNode functions to something like this,
auto iter = std::find_if(vNodes.begin(), vNodes.end(), [&](CNode *node) {
return node->GetAddrName() == addrName;
});
return iter == vNodes.end() ? NULL : *iter;
I believe C++11 allows that
@corebob I guess it is a matter of taste, but personally I find the current range-based for loop form more straightforward and easier to read:
for (CNode* pnode : vNodes) {
if (pnode->GetAddrName() == addrName) {
return pnode;
}
}
return NULL;
@practicalswift I pretty much agree. I think pro arguments could be made for getting rid of a raw loop, and getting rid of an extra exit point. Though probably not worth it in this case.
I am usually in favor of using algorithm, as explicit names (find_if) and lambdas are more descriptive than loops etc., but in this case, I don't like the return value conversion, so it indeed looks more complicated than before. Too bad.
Rebased.
Can someone please retrigger CI?
utACK a9144d535122a4d08348e477315b5a94368e6dfc
Travis passed after restart.
134 | @@ -135,11 +135,11 @@ static std::vector<CAddress> convertSeed6(const std::vector<SeedSpec6> &vSeedsIn 135 | const int64_t nOneWeek = 7*24*60*60; 136 | std::vector<CAddress> vSeedsOut; 137 | vSeedsOut.reserve(vSeedsIn.size()); 138 | - for (std::vector<SeedSpec6>::const_iterator i(vSeedsIn.begin()); i != vSeedsIn.end(); ++i) 139 | + for (const auto seed_in : vSeedsIn)
const SeedSpec6& seed_in makes more sense to me as it prevents a copy, no?
Correct. Done!
utACK a9144d535.
Since this is refactoring only you also might want to use clang format on the changed lines. (See the developer notes for a one-liner to fixup the formatting)
Plus a use of std::copy() instead of manual copying.
@MarcoFalke I also applied clang-format. Nice tool. Maybe it should go into the CI for all future changes ;)
re-utACK 05cae8a
Can this be merged?