range-based loops and const qualifications in net.cpp #10888

pull benma wants to merge 1 commits into bitcoin:master from benma:netcpp_cosmetics2 changing 1 files +37 −34
  1. benma commented at 9:44 AM on July 20, 2017: none

    Plus a use of std::copy() instead of manual copying.

    (The loop on line 117 is already done in #10493).

  2. benma force-pushed on Jul 20, 2017
  3. in src/net.cpp:316 in ddbdf9f0b7 outdated
     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))
    


    jonasschnelli commented at 11:27 AM on July 20, 2017:

    Please switch to brackets here.


    benma commented at 4:56 PM on July 20, 2017:

    Done.

  4. practicalswift commented at 11:38 AM on July 20, 2017: contributor

    Concept ACK (strong ACK! :-))

  5. jonasschnelli added the label Refactoring on Jul 20, 2017
  6. benma force-pushed on Jul 20, 2017
  7. dcousens approved
  8. bytting commented at 4:37 AM on July 21, 2017: contributor

    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

  9. practicalswift commented at 9:17 AM on July 21, 2017: contributor

    @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;
    
  10. bytting commented at 9:44 AM on July 21, 2017: contributor

    @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.

  11. benma commented at 7:39 AM on July 22, 2017: none

    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.

  12. benma force-pushed on Sep 11, 2017
  13. benma commented at 1:46 PM on September 11, 2017: none

    Rebased.

  14. benma commented at 5:27 PM on September 11, 2017: none

    Can someone please retrigger CI?

  15. sipa commented at 11:50 PM on September 11, 2017: member

    utACK a9144d535122a4d08348e477315b5a94368e6dfc

    Travis passed after restart.

  16. in src/net.cpp:138 in a9144d5351 outdated
     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)
    


    MarcoFalke commented at 3:02 AM on September 12, 2017:

    const SeedSpec6& seed_in makes more sense to me as it prevents a copy, no?


    benma commented at 7:11 AM on September 12, 2017:

    Correct. Done!

  17. MarcoFalke commented at 3:03 AM on September 12, 2017: member

    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)

  18. benma force-pushed on Sep 12, 2017
  19. range-based loops and const qualifications in net.cpp
    Plus a use of std::copy() instead of manual copying.
    05cae8aefd
  20. benma commented at 7:12 AM on September 12, 2017: none

    @MarcoFalke I also applied clang-format. Nice tool. Maybe it should go into the CI for all future changes ;)

  21. MarcoFalke commented at 7:17 AM on September 12, 2017: member

    re-utACK 05cae8a

  22. benma commented at 11:12 PM on September 20, 2017: none

    Can this be merged?

  23. sipa merged this on Sep 20, 2017
  24. sipa closed this on Sep 20, 2017

  25. sipa referenced this in commit 98212745c8 on Sep 20, 2017
  26. PastaPastaPasta referenced this in commit 1eebe9f66a on Dec 22, 2019
  27. PastaPastaPasta referenced this in commit f3b1eb4f45 on Jan 2, 2020
  28. PastaPastaPasta referenced this in commit dfc8635268 on Jan 4, 2020
  29. PastaPastaPasta referenced this in commit dc75e25549 on Jan 12, 2020
  30. PastaPastaPasta referenced this in commit d702ae8ac4 on Jan 12, 2020
  31. PastaPastaPasta referenced this in commit 4a876991af on Jan 12, 2020
  32. PastaPastaPasta referenced this in commit 6cf675807e on Jan 12, 2020
  33. codablock referenced this in commit bedfb7832d on Jan 14, 2020
  34. PastaPastaPasta referenced this in commit 78c06fa838 on Jan 14, 2020
  35. ckti referenced this in commit d917fb7e68 on Mar 28, 2021
  36. ckti referenced this in commit f7d2e43945 on Mar 28, 2021
  37. gades referenced this in commit 3d3779221d on Jun 25, 2021
  38. gades referenced this in commit 7cdd0f238c on Jun 30, 2021
  39. furszy referenced this in commit 60d36292bc on Jul 26, 2021
  40. MarcoFalke locked this on Sep 8, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-16 18:15 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me