No description provided.
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-
practicalswift commented at 9:37 PM on May 5, 2017: contributor
-
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:txInindicates aCTransactiontype. Better to make it lowercasetxin.
practicalswift commented at 9:55 PM on May 5, 2017:@luke-jr Likely I'm missing something here, but
txTo.vinisstd::vector<CTxIn>and notCTransaction. Shouldn'ttxInthen indicateCTxIn. 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 &txOutandCTransactionRef& txInare used in other parts of the code base. The suggestions is that I change alltxIn/txOuttotxin/txoutin my PR?
luke-jr commented at 10:12 PM on May 5, 2017:Right. Might also change
transactionRefto simplytxalso, but it's less confusing.luke-jr approvedluke-jr commented at 9:49 PM on May 5, 2017: memberutACK, with one minor nit.
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!
practicalswift force-pushed on May 5, 2017fanquake added the label Refactoring on May 5, 2017practicalswift force-pushed on May 6, 2017practicalswift force-pushed on May 6, 2017practicalswift force-pushed on May 8, 2017practicalswift force-pushed on May 8, 2017practicalswift commented at 7:44 AM on May 8, 2017: contributor@luke-jr Nit addressed! Looks good? :-)
kallewoof approvedpaveljanik commented at 6:34 AM on May 12, 2017: contributorin 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.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
inputorcoin, to avoid making it look like Hungarian notation for a transaction input?sipa commented at 4:50 AM on May 15, 2017: memberutACK, two nits
practicalswift force-pushed on May 15, 2017practicalswift commented at 7:30 AM on May 15, 2017: contributor@sipa Good points! Nits addressed.
Thanks for reviewing.
sipa commented at 4:53 AM on May 17, 2017: memberutACK 83e8c9207733ad5d3013ee3009632514b15a9347
sipa commented at 12:23 AM on May 18, 2017: memberNeeds rebase.
practicalswift force-pushed on May 18, 2017practicalswift commented at 7:43 AM on May 18, 2017: contributor@sipa Thanks for the ping. Now rebased! :-)
Use range-based for loops (C++11) when looping over vector elements 211adc074apracticalswift force-pushed on May 19, 2017practicalswift commented at 7:57 AM on May 19, 2017: contributorRebased again!
ryanofsky commented at 7:07 PM on May 23, 2017: memberutACK 211adc074a662505f2b54f3f2755f4fefc167aac
sipa merged this on May 23, 2017sipa closed this on May 23, 2017sipa referenced this in commit f2f7e97e8c on May 23, 2017PastaPastaPasta referenced this in commit f8eca07b77 on Jun 10, 2019PastaPastaPasta referenced this in commit a283a9ed60 on Jun 11, 2019PastaPastaPasta referenced this in commit b9474c07a8 on Jun 11, 2019PastaPastaPasta referenced this in commit 03fe233a1b on Jun 15, 2019PastaPastaPasta referenced this in commit 578ab32fee on Jun 19, 2019PastaPastaPasta referenced this in commit 06904c00b2 on Jun 19, 2019PastaPastaPasta referenced this in commit d39219e839 on Jun 19, 2019PastaPastaPasta referenced this in commit b76426ff38 on Jun 19, 2019PastaPastaPasta referenced this in commit 5826a1a261 on Jun 19, 2019PastaPastaPasta referenced this in commit 41f4a9b987 on Jun 20, 2019PastaPastaPasta referenced this in commit aa8ebb9d23 on Jun 22, 2019PastaPastaPasta referenced this in commit 6221294028 on Jun 22, 2019PastaPastaPasta referenced this in commit 57fedc1be2 on Jun 22, 2019PastaPastaPasta referenced this in commit 7b32670b8f on Jun 22, 2019PastaPastaPasta referenced this in commit 4a59880bce on Jun 24, 2019PastaPastaPasta referenced this in commit 535d7d6a84 on Jun 26, 2019barrystyle referenced this in commit db53af5fec on Jan 22, 2020practicalswift deleted the branch on Apr 10, 2021DrahtBot locked this on Aug 18, 2022Labels
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