Use range-based for loops (C++11) when looping over vector elements #10347

pull practicalswift wants to merge 1 commits into bitcoin:master from practicalswift:range-based-for-loops changing 5 files +22 −25
  1. practicalswift commented at 9:37 PM on May 5, 2017: contributor

    No description provided.

  2. in src/script/interpreter.cpp:1145 in 3d5a6b491e outdated
    1141 | @@ -1142,24 +1142,24 @@ class CTransactionSignatureSerializer {
    1142 |  
    1143 |  uint256 GetPrevoutHash(const CTransaction& txTo) {
    1144 |      CHashWriter ss(SER_GETHASH, 0);
    1145 | -    for (unsigned int n = 0; n < txTo.vin.size(); n++) {
    1146 | -        ss << txTo.vin[n].prevout;
    1147 | +    for (const auto& txIn : txTo.vin) {
    


    luke-jr commented at 9:47 PM on May 5, 2017:

    txIn indicates a CTransaction type. Better to make it lowercase txin.


    practicalswift commented at 9:55 PM on May 5, 2017:

    @luke-jr Likely I'm missing something here, but txTo.vin is std::vector<CTxIn> and not CTransaction. Shouldn't txIn then indicate CTxIn. What am I missing? :-)


    luke-jr commented at 10:04 PM on May 5, 2017:

    Hungarian notation uses the lowercase type identifier (eg, "tx") followed by camel case variable name (eg, "In"). While it's not required to use this notation, your "txIn" variable name looks like it is, while not matching the usage expectation.


    practicalswift commented at 10:05 PM on May 5, 2017:

    @luke-jr I think I get it now. CTransactionRef &txOut and CTransactionRef& txIn are used in other parts of the code base. The suggestions is that I change all txIn/txOut to txin/txout in my PR?


    luke-jr commented at 10:12 PM on May 5, 2017:

    Right. Might also change transactionRef to simply tx also, but it's less confusing.

  3. luke-jr approved
  4. luke-jr commented at 9:49 PM on May 5, 2017: member

    utACK, with one minor nit.

  5. in src/wallet/wallet.cpp:1784 in 3d5a6b491e outdated
    1780 | @@ -1781,8 +1781,8 @@ bool CWalletTx::IsEquivalentTo(const CWalletTx& _tx) const
    1781 |  {
    1782 |          CMutableTransaction tx1 = *this->tx;
    1783 |          CMutableTransaction tx2 = *_tx.tx;
    1784 | -        for (unsigned int i = 0; i < tx1.vin.size(); i++) tx1.vin[i].scriptSig = CScript();
    1785 | -        for (unsigned int i = 0; i < tx2.vin.size(); i++) tx2.vin[i].scriptSig = CScript();
    1786 | +        for (const auto& txIn : tx1.vin) txIn.scriptSig = CScript();
    


    ryanofsky commented at 9:49 PM on May 5, 2017:

    Needs to be non-const


    practicalswift commented at 7:46 AM on May 8, 2017:

    @ryanofsky Thanks! Fixed!

  6. practicalswift force-pushed on May 5, 2017
  7. fanquake added the label Refactoring on May 5, 2017
  8. practicalswift force-pushed on May 6, 2017
  9. practicalswift force-pushed on May 6, 2017
  10. practicalswift force-pushed on May 8, 2017
  11. practicalswift force-pushed on May 8, 2017
  12. practicalswift commented at 7:44 AM on May 8, 2017: contributor

    @luke-jr Nit addressed! Looks good? :-)

  13. kallewoof approved
  14. in src/validation.cpp:3061 in 660b5237c4 outdated
    3057 | @@ -3058,8 +3058,8 @@ bool ContextualCheckBlock(const CBlock& block, CValidationState& state, const Co
    3058 |  
    3059 |      // No witness data is allowed in blocks that don't commit to witness data, as this would otherwise leave room for spam
    3060 |      if (!fHaveWitness) {
    3061 | -        for (size_t i = 0; i < block.vtx.size(); i++) {
    3062 | -            if (block.vtx[i]->HasWitness()) {
    3063 | +      for (const auto& transactionRef : block.vtx) {
    


    sipa commented at 4:49 AM on May 15, 2017:

    For consistency I would call this just tx.

  15. in src/wallet/wallet.cpp:2152 in 660b5237c4 outdated
    2148 | @@ -2149,10 +2149,10 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, const int nConfMin
    2149 |  
    2150 |      if (nTotalLower == nTargetValue)
    2151 |      {
    2152 | -        for (unsigned int i = 0; i < vValue.size(); ++i)
    2153 | +        for (const auto& inputCoin : vValue)
    


    sipa commented at 4:50 AM on May 15, 2017:

    Simply call this input or coin, to avoid making it look like Hungarian notation for a transaction input?

  16. sipa commented at 4:50 AM on May 15, 2017: member

    utACK, two nits

  17. practicalswift force-pushed on May 15, 2017
  18. practicalswift commented at 7:30 AM on May 15, 2017: contributor

    @sipa Good points! Nits addressed.

    Thanks for reviewing.

  19. sipa commented at 4:53 AM on May 17, 2017: member

    utACK 83e8c9207733ad5d3013ee3009632514b15a9347

  20. sipa commented at 12:23 AM on May 18, 2017: member

    Needs rebase.

  21. practicalswift force-pushed on May 18, 2017
  22. practicalswift commented at 7:43 AM on May 18, 2017: contributor

    @sipa Thanks for the ping. Now rebased! :-)

  23. Use range-based for loops (C++11) when looping over vector elements 211adc074a
  24. practicalswift force-pushed on May 19, 2017
  25. practicalswift commented at 7:57 AM on May 19, 2017: contributor

    Rebased again!

  26. ryanofsky commented at 7:07 PM on May 23, 2017: member

    utACK 211adc074a662505f2b54f3f2755f4fefc167aac

  27. sipa merged this on May 23, 2017
  28. sipa closed this on May 23, 2017

  29. sipa referenced this in commit f2f7e97e8c on May 23, 2017
  30. PastaPastaPasta referenced this in commit f8eca07b77 on Jun 10, 2019
  31. PastaPastaPasta referenced this in commit a283a9ed60 on Jun 11, 2019
  32. PastaPastaPasta referenced this in commit b9474c07a8 on Jun 11, 2019
  33. PastaPastaPasta referenced this in commit 03fe233a1b on Jun 15, 2019
  34. PastaPastaPasta referenced this in commit 578ab32fee on Jun 19, 2019
  35. PastaPastaPasta referenced this in commit 06904c00b2 on Jun 19, 2019
  36. PastaPastaPasta referenced this in commit d39219e839 on Jun 19, 2019
  37. PastaPastaPasta referenced this in commit b76426ff38 on Jun 19, 2019
  38. PastaPastaPasta referenced this in commit 5826a1a261 on Jun 19, 2019
  39. PastaPastaPasta referenced this in commit 41f4a9b987 on Jun 20, 2019
  40. PastaPastaPasta referenced this in commit aa8ebb9d23 on Jun 22, 2019
  41. PastaPastaPasta referenced this in commit 6221294028 on Jun 22, 2019
  42. PastaPastaPasta referenced this in commit 57fedc1be2 on Jun 22, 2019
  43. PastaPastaPasta referenced this in commit 7b32670b8f on Jun 22, 2019
  44. PastaPastaPasta referenced this in commit 4a59880bce on Jun 24, 2019
  45. PastaPastaPasta referenced this in commit 535d7d6a84 on Jun 26, 2019
  46. barrystyle referenced this in commit db53af5fec on Jan 22, 2020
  47. practicalswift deleted the branch on Apr 10, 2021
  48. DrahtBot locked this on Aug 18, 2022

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 15:15 UTC

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