Trivial refactor: BOOST_FOREACH(a, b) -> for (a : b) #9478

pull kallewoof wants to merge 7 commits into bitcoin:master from kallewoof:replace-boostforeach changing 59 files +304 −348
  1. kallewoof commented at 2:34 PM on January 5, 2017: member

    Replaces all BOOST_FOREACH(a, b)for (a : b). BOOST_REVERSE_FOREACH requires an additional wrapper, so it was left as is.

    There are a few places where #include <boost/foreach.hpp> has been ADDED, for BOOST_REVERSE_FOREACH. It was previously obtained via some header file it included, that no longer uses BOOST*_FOREACH.

    As the PR touches on a lot of stuff, I split it into multiple commits, in case cherry picking was preferred. Let me know if I should squash.

    From git diff -U0 replace-boostforeach | grep -v "BOOST_FOREACH" | grep -v "for (" | grep -v "#include" | grep "^[+-]" (from master):

    --- a/src/bench/coin_selection.cpp
    +++ b/src/bench/coin_selection.cpp
    --- a/src/bitcoin-tx.cpp
    +++ b/src/bitcoin-tx.cpp
    --- a/src/bloom.cpp
    +++ b/src/bloom.cpp
    +
    --- a/src/checkqueue.h
    +++ b/src/checkqueue.h
    --- a/src/coins.cpp
    +++ b/src/coins.cpp
    --- a/src/coins.h
    +++ b/src/coins.h
    --- a/src/core_write.cpp
    +++ b/src/core_write.cpp
    --- a/src/httprpc.cpp
    +++ b/src/httprpc.cpp
    --- a/src/init.cpp
    +++ b/src/init.cpp
    --- a/src/keystore.cpp
    +++ b/src/keystore.cpp
    +
    --- a/src/memusage.h
    +++ b/src/memusage.h
    --- a/src/miner.cpp
    +++ b/src/miner.cpp
    --- a/src/net.cpp
    +++ b/src/net.cpp
    --- a/src/net.h
    +++ b/src/net.h
    --- a/src/net_processing.cpp
    +++ b/src/net_processing.cpp
    --- a/src/policy/policy.cpp
    +++ b/src/policy/policy.cpp
    +
    --- a/src/policy/rbf.cpp
    +++ b/src/policy/rbf.cpp
    --- a/src/qt/addresstablemodel.cpp
    +++ b/src/qt/addresstablemodel.cpp
    +
    --- a/src/qt/coincontroldialog.cpp
    +++ b/src/qt/coincontroldialog.cpp
    --- a/src/qt/peertablemodel.cpp
    +++ b/src/qt/peertablemodel.cpp
    --- a/src/qt/recentrequeststablemodel.cpp
    +++ b/src/qt/recentrequeststablemodel.cpp
    +
    --- a/src/qt/transactiondesc.cpp
    +++ b/src/qt/transactiondesc.cpp
    --- a/src/qt/transactionrecord.cpp
    +++ b/src/qt/transactionrecord.cpp
    +
    --- a/src/qt/transactiontablemodel.cpp
    +++ b/src/qt/transactiontablemodel.cpp
    +
    --- a/src/qt/walletmodel.cpp
    +++ b/src/qt/walletmodel.cpp
    +
    --- a/src/rest.cpp
    +++ b/src/rest.cpp
    --- a/src/rpc/blockchain.cpp
    +++ b/src/rpc/blockchain.cpp
    --- a/src/rpc/mining.cpp
    +++ b/src/rpc/mining.cpp
    --- a/src/rpc/misc.cpp
    +++ b/src/rpc/misc.cpp
    --- a/src/rpc/net.cpp
    +++ b/src/rpc/net.cpp
    +
    --- a/src/rpc/rawtransaction.cpp
    +++ b/src/rpc/rawtransaction.cpp
    --- a/src/rpc/server.cpp
    +++ b/src/rpc/server.cpp
    --- a/src/script/ismine.cpp
    +++ b/src/script/ismine.cpp
    +
    --- a/src/script/sign.cpp
    +++ b/src/script/sign.cpp
    +
    --- a/src/script/standard.cpp
    +++ b/src/script/standard.cpp
    +
    --- a/src/sync.cpp
    +++ b/src/sync.cpp
    --- a/src/test/DoS_tests.cpp
    +++ b/src/test/DoS_tests.cpp
    --- a/src/test/base58_tests.cpp
    +++ b/src/test/base58_tests.cpp
    --- a/src/test/bip32_tests.cpp
    +++ b/src/test/bip32_tests.cpp
    --- a/src/test/coins_tests.cpp
    +++ b/src/test/coins_tests.cpp
    --- a/src/test/getarg_tests.cpp
    +++ b/src/test/getarg_tests.cpp
    --- a/src/test/multisig_tests.cpp
    +++ b/src/test/multisig_tests.cpp
    --- a/src/test/prevector_tests.cpp
    +++ b/src/test/prevector_tests.cpp
    --- a/src/test/script_tests.cpp
    +++ b/src/test/script_tests.cpp
    --- a/src/test/sigopcount_tests.cpp
    +++ b/src/test/sigopcount_tests.cpp
    --- a/src/test/test_bitcoin.cpp
    +++ b/src/test/test_bitcoin.cpp
    --- a/src/test/transaction_tests.cpp
    +++ b/src/test/transaction_tests.cpp
    --- a/src/timedata.cpp
    +++ b/src/timedata.cpp
    +
    --- a/src/torcontrol.cpp
    +++ b/src/torcontrol.cpp
    --- a/src/txmempool.cpp
    +++ b/src/txmempool.cpp
    -
    --- a/src/util.cpp
    +++ b/src/util.cpp
    --- a/src/validation.cpp
    +++ b/src/validation.cpp
    --- a/src/wallet/crypter.cpp
    +++ b/src/wallet/crypter.cpp
    --- a/src/wallet/rpcdump.cpp
    +++ b/src/wallet/rpcdump.cpp
    --- a/src/wallet/rpcwallet.cpp
    +++ b/src/wallet/rpcwallet.cpp
    --- a/src/wallet/test/accounting_tests.cpp
    +++ b/src/wallet/test/accounting_tests.cpp
    --- a/src/wallet/test/wallet_tests.cpp
    +++ b/src/wallet/test/wallet_tests.cpp
    --- a/src/wallet/wallet.cpp
    +++ b/src/wallet/wallet.cpp
    --- a/src/wallet/walletdb.cpp
    +++ b/src/wallet/walletdb.cpp
    

    Benchmarks - master:

    #Benchmark,count,min,max,average,min_cycles,max_cycles,average_cycles
    Base58CheckEncode,229376,0.000004326357157,0.000004963512765,0.000004541861667,11222,12875,11781
    Base58Decode,917504,0.000001110929588,0.000001373788109,0.000001167395437,2881,3563,3028
    Base58Encode,360448,0.000002718508767,0.000003071909305,0.000002815554167,7052,7968,7303
    CCoinsCaching,90112,0.000010910531273,0.000014293444110,0.000012013304513,28302,37086,31164
    CoinSelection,448,0.002138502895832,0.002475425601006,0.002310852919306,5547436,6421437,5994558
    DeserializeAndCheckBlockTest,80,0.012595385313034,0.013895988464355,0.012998473644257,32673430,36047074,33719997
    DeserializeBlockTest,96,0.010183453559875,0.012159466743469,0.010994019607703,26417602,31543366,28519488
    LockedPool,576,0.001834303140640,0.002205252647400,0.001912279261483,4758394,5720700,4960736
    MempoolEviction,15360,0.000063847750425,0.000079267658293,0.000068315754955,165625,205627,177217
    RIPEMD160,352,0.002818815410137,0.003295376896858,0.002940198914571,7312272,8548505,7627320
    RollingBloom-refresh,1,0.002872000000000,0.002872000000000,0.002872000000000
    RollingBloom-refresh,1,0.000126000000000,0.000126000000000,0.000126000000000
    RollingBloom-refresh,1,0.000135000000000,0.000135000000000,0.000135000000000
    RollingBloom-refresh,1,0.000122000000000,0.000122000000000,0.000122000000000
    RollingBloom-refresh,1,0.000126000000000,0.000126000000000,0.000126000000000
    RollingBloom-refresh,1,0.000125000000000,0.000125000000000,0.000125000000000
    RollingBloom-refresh,1,0.000130000000000,0.000130000000000,0.000130000000000
    RollingBloom-refresh,1,0.000138000000000,0.000138000000000,0.000138000000000
    RollingBloom-refresh,1,0.000163000000000,0.000163000000000,0.000163000000000
    RollingBloom-refresh,1,0.000134000000000,0.000134000000000,0.000134000000000
    RollingBloom-refresh,1,0.000136000000000,0.000136000000000,0.000136000000000
    RollingBloom-refresh,1,0.000122000000000,0.000122000000000,0.000122000000000
    RollingBloom-refresh,1,0.000131000000000,0.000131000000000,0.000131000000000
    RollingBloom-refresh,1,0.000133000000000,0.000133000000000,0.000133000000000
    RollingBloom-refresh,1,0.000126000000000,0.000126000000000,0.000126000000000
    RollingBloom-refresh,1,0.000163000000000,0.000163000000000,0.000163000000000
    RollingBloom-refresh,1,0.000125000000000,0.000125000000000,0.000125000000000
    RollingBloom,1048576,0.000000882231689,0.000001236327080,0.000001071050747,2288,3207,2778
    SHA1,480,0.002087906002998,0.002517864108086,0.002206854025523,5416224,6531635,5724910
    SHA256,208,0.004832878708839,0.005551114678383,0.005082085728645,12536757,14400253,13183382
    SHA256_32b,4,0.352158546447754,0.359472036361694,0.355815291404724,913530634,932539127,923034880
    SHA512,352,0.003017187118530,0.003323063254356,0.003129244528034,7826806,8620341,8117744
    SipHash_32b,24,0.042123556137085,0.045263528823853,0.043853839238485,109271866,117417624,113760828
    Sleep100ms,10,0.100414991378784,0.103456497192383,0.102275800704956,260485208,268401932,265319716
    Trig,54525952,0.000000017816774,0.000000025302427,0.000000019326487,46,65,50
    VerifyScriptBench,5120,0.000190054997802,0.000236719846725,0.000202322099358,493006,614070,524855
    

    Benchmarks - proposed:

    #Benchmark,count,min,max,average,min_cycles,max_cycles,average_cycles
    Base58CheckEncode,229376,0.000004299872671,0.000005248482921,0.000004562055567,11154,13615,11834
    Base58Decode,851968,0.000001117034117,0.000001297114068,0.000001191562310,2898,3364,3091
    Base58Encode,360448,0.000002772125299,0.000003955938155,0.000002868102456,7191,10262,7440
    CCoinsCaching,90112,0.000011271360563,0.000018610735424,0.000011882358442,29238,48278,30823
    CoinSelection,448,0.002233907580376,0.002602994441986,0.002355379717691,5794937,6752443,6110212
    DeserializeAndCheckBlockTest,80,0.012478470802307,0.016817122697830,0.013458424806595,32370253,43625223,34912334
    DeserializeBlockTest,96,0.010576754808426,0.014374017715454,0.011311687529087,27437123,37287217,29344163
    LockedPool,512,0.001879997551441,0.002257555723190,0.001954525243491,4876869,5856165,5070210
    MempoolEviction,15360,0.000064164400101,0.000080461613834,0.000068432884291,166436,208720,177525
    RIPEMD160,352,0.002828940749168,0.003512464463711,0.003067639063705,7338448,9111611,7957752
    RollingBloom-refresh,1,0.002693000000000,0.002693000000000,0.002693000000000
    RollingBloom-refresh,1,0.000149000000000,0.000149000000000,0.000149000000000
    RollingBloom-refresh,1,0.000124000000000,0.000124000000000,0.000124000000000
    RollingBloom-refresh,1,0.000195000000000,0.000195000000000,0.000195000000000
    RollingBloom-refresh,1,0.000130000000000,0.000130000000000,0.000130000000000
    RollingBloom-refresh,1,0.000149000000000,0.000149000000000,0.000149000000000
    RollingBloom-refresh,1,0.000130000000000,0.000130000000000,0.000130000000000
    RollingBloom-refresh,1,0.000139000000000,0.000139000000000,0.000139000000000
    RollingBloom-refresh,1,0.000130000000000,0.000130000000000,0.000130000000000
    RollingBloom-refresh,1,0.000129000000000,0.000129000000000,0.000129000000000
    RollingBloom-refresh,1,0.000134000000000,0.000134000000000,0.000134000000000
    RollingBloom-refresh,1,0.000135000000000,0.000135000000000,0.000135000000000
    RollingBloom-refresh,1,0.000363000000000,0.000363000000000,0.000363000000000
    RollingBloom,786432,0.000000959367753,0.000010643812857,0.000001935391689,2488,27610,5020
    SHA1,48,0.005145609378815,0.030017614364624,0.020953019460042,13348212,77868423,54355436
    SHA256,64,0.006630629301071,0.073981046676636,0.015694499015808,17200231,191912711,40712921
    SHA256_32b,4,0.355887532234192,0.407057523727417,0.381472527980804,923204333,1055977091,989590712
    SHA512,224,0.003005154430866,0.007157191634178,0.004911704787186,7795668,18566260,12741400
    SipHash_32b,16,0.045298457145691,0.120459437370300,0.067544251680374,117509507,312483869,175220199
    Sleep100ms,10,0.100839495658875,0.104552507400513,0.102500391006470,261588712,271218584,265895782
    Trig,58720256,0.000000017373850,0.000000019301865,0.000000018000212,45,50,46
    VerifyScriptBench,5120,0.000192636623979,0.000232702121139,0.000206031044945,499713,603670,534475
    
  2. Trivial refactor: replace all BOOST_FOREACH (qt/). 1430e4d5ae
  3. Trivial refactor: replace all BOOST_FOREACH (rpc/). 27b75410f0
  4. Trivial refactor: replace all BOOST_FOREACH (bench/ & test/). bf59fbc82e
  5. Trivial refactor: replace all BOOST_FOREACH (wallet/). 23c9820187
  6. Trivial refactor: replace all BOOST_FOREACH (script/). 5330fa96ac
  7. Trivial refactor: replace all BOOST_FOREACH (policy/). f7877d0366
  8. Trivial refactor: replace all BOOST_FOREACH (src/). 3f94cce40a
  9. fanquake added the label Refactoring on Jan 5, 2017
  10. MarcoFalke commented at 3:19 PM on January 5, 2017: member

    This has already been attempted in #8801, but was deferred until later due the merge conflicts it would cause.

    As I mentioned earlier today, it probably makes sense to get the tagged pull requests for 0.14 in first. Then, after the feature freeze, decide which boost refactoring should be included in 0.14.

    Edit: Other relevant comment: #8718 (comment)

    Edit 2: Already a merge conflict 😛

  11. kallewoof commented at 1:25 AM on January 6, 2017: member

    @MarcoFalke I was hoping it would be manageable by keeping it in multiple commits and cherry picking as desired. But didn't realize it was duplicate of existing work. Should've checked! Thanks for the feedback :)

  12. kallewoof closed this on Jan 6, 2017

  13. MarcoFalke commented at 10:56 AM on January 6, 2017: member

    Indeed there is no reason to do such a change for very active code, as it can be changed "on the go" whenever a line is touched anyway.

  14. kallewoof commented at 10:58 AM on January 6, 2017: member

    I always thought PR's should be as "pure" as possible and not do anything extra. This is described in the contributor docs as well. That's what I have been aiming for so far. Each PR has one purpose and implements it with optimally minimal changes to the code base.

  15. MarcoFalke commented at 11:10 AM on January 6, 2017: member

    @kallewoof This is true and I tend to agree. Though, if you know the pain of merge conflicts, it seems less sensible to adhere to.

    You might want to apply this change to places in the code that are usually touched very rarely (E.g. src/test, but NOT src/wallet). This will preempt similar pulls from popping up.

  16. kallewoof commented at 11:14 AM on January 6, 2017: member

    @MarcoFalke I hear you on merge conflict pain. It just seems like there's no real good option to move forward on things like these.

    Regarding src/test, you mean like cherry-picking https://github.com/bitcoin/bitcoin/pull/9478/commits/bf59fbc82eec56d69b79adc413fa413dac987748 ? I can do that for sure. Presumably after 0.14 freeze like you mentioned?

  17. laanwj removed this from the "Later" column in a project

  18. kallewoof deleted the branch on Oct 17, 2019
  19. DrahtBot locked this on Dec 16, 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-14 18:15 UTC

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