Skip to content

Commit f2f7e97

Browse files
committed
Merge #10347: Use range-based for loops (C++11) when looping over vector elements
211adc0 Use range-based for loops (C++11) when looping over vector elements (practicalswift) Tree-SHA512: 0e007f20dcef99d3c7a1036265e00f689d69f42e02fd82dd8389f45b52d31947e5f9388de2610d3d9bd9f554915ce0d35ebce561e5ae3a9013956d0ee4937145
2 parents 7e96ecf + 211adc0 commit f2f7e97

File tree

5 files changed

+22
-25
lines changed

5 files changed

+22
-25
lines changed

src/net_processing.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -754,8 +754,8 @@ void PeerLogicValidation::BlockConnected(const std::shared_ptr<const CBlock>& pb
754754
const CTransaction& tx = *ptx;
755755

756756
// Which orphan pool entries must we evict?
757-
for (size_t j = 0; j < tx.vin.size(); j++) {
758-
auto itByPrev = mapOrphanTransactionsByPrev.find(tx.vin[j].prevout);
757+
for (const auto& txin : tx.vin) {
758+
auto itByPrev = mapOrphanTransactionsByPrev.find(txin.prevout);
759759
if (itByPrev == mapOrphanTransactionsByPrev.end()) continue;
760760
for (auto mi = itByPrev->second.begin(); mi != itByPrev->second.end(); ++mi) {
761761
const CTransaction& orphanTx = *(*mi)->second.tx;
@@ -1553,10 +1553,8 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
15531553

15541554
uint32_t nFetchFlags = GetFetchFlags(pfrom);
15551555

1556-
for (unsigned int nInv = 0; nInv < vInv.size(); nInv++)
1556+
for (CInv &inv : vInv)
15571557
{
1558-
CInv &inv = vInv[nInv];
1559-
15601558
if (interruptMsgProc)
15611559
return true;
15621560

src/policy/fees.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -604,8 +604,8 @@ void CBlockPolicyEstimator::processBlock(unsigned int nBlockHeight,
604604

605605
unsigned int countedTxs = 0;
606606
// Update averages with data points from current block
607-
for (unsigned int i = 0; i < entries.size(); i++) {
608-
if (processBlockTx(nBlockHeight, entries[i]))
607+
for (const auto& entry : entries) {
608+
if (processBlockTx(nBlockHeight, entry))
609609
countedTxs++;
610610
}
611611

src/script/interpreter.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,24 +1142,24 @@ class CTransactionSignatureSerializer {
11421142

11431143
uint256 GetPrevoutHash(const CTransaction& txTo) {
11441144
CHashWriter ss(SER_GETHASH, 0);
1145-
for (unsigned int n = 0; n < txTo.vin.size(); n++) {
1146-
ss << txTo.vin[n].prevout;
1145+
for (const auto& txin : txTo.vin) {
1146+
ss << txin.prevout;
11471147
}
11481148
return ss.GetHash();
11491149
}
11501150

11511151
uint256 GetSequenceHash(const CTransaction& txTo) {
11521152
CHashWriter ss(SER_GETHASH, 0);
1153-
for (unsigned int n = 0; n < txTo.vin.size(); n++) {
1154-
ss << txTo.vin[n].nSequence;
1153+
for (const auto& txin : txTo.vin) {
1154+
ss << txin.nSequence;
11551155
}
11561156
return ss.GetHash();
11571157
}
11581158

11591159
uint256 GetOutputsHash(const CTransaction& txTo) {
11601160
CHashWriter ss(SER_GETHASH, 0);
1161-
for (unsigned int n = 0; n < txTo.vout.size(); n++) {
1162-
ss << txTo.vout[n];
1161+
for (const auto& txout : txTo.vout) {
1162+
ss << txout;
11631163
}
11641164
return ss.GetHash();
11651165
}

src/validation.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,6 @@ bool CheckSequenceLocks(const CTransaction &tx, int flags, LockPoints* lp, bool
309309
return EvaluateSequenceLocks(index, lockPair);
310310
}
311311

312-
313312
void LimitMempoolSize(CTxMemPool& pool, size_t limit, unsigned long age) {
314313
int expired = pool.Expire(GetTime() - age);
315314
if (expired != 0) {
@@ -2817,8 +2816,8 @@ bool ContextualCheckBlock(const CBlock& block, CValidationState& state, const Co
28172816

28182817
// No witness data is allowed in blocks that don't commit to witness data, as this would otherwise leave room for spam
28192818
if (!fHaveWitness) {
2820-
for (size_t i = 0; i < block.vtx.size(); i++) {
2821-
if (block.vtx[i]->HasWitness()) {
2819+
for (const auto& tx : block.vtx) {
2820+
if (tx->HasWitness()) {
28222821
return state.DoS(100, false, REJECT_INVALID, "unexpected-witness", true, strprintf("%s : unexpected witness data found", __func__));
28232822
}
28242823
}

src/wallet/wallet.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1788,8 +1788,8 @@ bool CWalletTx::IsEquivalentTo(const CWalletTx& _tx) const
17881788
{
17891789
CMutableTransaction tx1 = *this->tx;
17901790
CMutableTransaction tx2 = *_tx.tx;
1791-
for (unsigned int i = 0; i < tx1.vin.size(); i++) tx1.vin[i].scriptSig = CScript();
1792-
for (unsigned int i = 0; i < tx2.vin.size(); i++) tx2.vin[i].scriptSig = CScript();
1791+
for (auto& txin : tx1.vin) txin.scriptSig = CScript();
1792+
for (auto& txin : tx2.vin) txin.scriptSig = CScript();
17931793
return CTransaction(tx1) == CTransaction(tx2);
17941794
}
17951795

@@ -2268,10 +2268,10 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, const int nConfMin
22682268

22692269
if (nTotalLower == nTargetValue)
22702270
{
2271-
for (unsigned int i = 0; i < vValue.size(); ++i)
2271+
for (const auto& input : vValue)
22722272
{
2273-
setCoinsRet.insert(vValue[i]);
2274-
nValueRet += vValue[i].txout.nValue;
2273+
setCoinsRet.insert(input);
2274+
nValueRet += input.txout.nValue;
22752275
}
22762276
return true;
22772277
}
@@ -2401,7 +2401,7 @@ bool CWallet::SignTransaction(CMutableTransaction &tx)
24012401
// sign the new tx
24022402
CTransaction txNewConst(tx);
24032403
int nIn = 0;
2404-
for (auto& input : tx.vin) {
2404+
for (const auto& input : tx.vin) {
24052405
std::map<uint256, CWalletTx>::const_iterator mi = mapWallet.find(input.prevout.hash);
24062406
if(mi == mapWallet.end() || input.prevout.n >= mi->second.tx->vout.size()) {
24072407
return false;
@@ -3340,11 +3340,11 @@ std::set< std::set<CTxDestination> > CWallet::GetAddressGroupings()
33403340
}
33413341

33423342
// group lone addrs by themselves
3343-
for (unsigned int i = 0; i < pcoin->tx->vout.size(); i++)
3344-
if (IsMine(pcoin->tx->vout[i]))
3343+
for (const auto& txout : pcoin->tx->vout)
3344+
if (IsMine(txout))
33453345
{
33463346
CTxDestination address;
3347-
if(!ExtractDestination(pcoin->tx->vout[i].scriptPubKey, address))
3347+
if(!ExtractDestination(txout.scriptPubKey, address))
33483348
continue;
33493349
grouping.insert(address);
33503350
groupings.insert(grouping);

0 commit comments

Comments
 (0)