Skip to content

Commit 431ac07

Browse files
committed
refactor: use std23::ranges::fold_left in Dash-specific code
1 parent 0e09192 commit 431ac07

4 files changed

Lines changed: 12 additions & 24 deletions

File tree

src/evo/cbtx.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,22 @@
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

5-
#include <consensus/validation.h>
65
#include <evo/cbtx.h>
6+
77
#include <evo/specialtx.h>
88
#include <llmq/blockprocessor.h>
99
#include <llmq/commitment.h>
1010
#include <llmq/options.h>
1111
#include <llmq/quorumsman.h>
1212
#include <llmq/utils.h>
13-
#include <node/blockstorage.h>
13+
#include <util/std23.h>
1414

1515
#include <chain.h>
1616
#include <chainparams.h>
1717
#include <consensus/merkle.h>
18+
#include <consensus/validation.h>
1819
#include <deploymentstatus.h>
20+
#include <node/blockstorage.h>
1921

2022
using node::ReadBlockFromDisk;
2123

@@ -109,11 +111,7 @@ auto CachedGetQcHashesQcIndexedHashes(const CBlockIndex* pindexPrev, const llmq:
109111

110112
auto CalcHashCountFromQCHashes(const QcHashMap& qcHashes)
111113
{
112-
size_t hash_count{0};
113-
for (const auto& [_, vec_hashes] : qcHashes) {
114-
hash_count += vec_hashes.size();
115-
}
116-
return hash_count;
114+
return std23::ranges::fold_left(qcHashes, size_t{0}, [](size_t s, const auto& p) { return s + p.second.size(); });
117115
}
118116

119117
bool CalcCbTxMerkleRootQuorums(const CBlock& block, const CBlockIndex* pindexPrev,

src/governance/classes.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -233,14 +233,7 @@ bool CSuperblock::GetPayment(int nPaymentIndex, CGovernancePayment& paymentRet)
233233

234234
CAmount CSuperblock::GetPaymentsTotalAmount()
235235
{
236-
CAmount nPaymentsTotalAmount = 0;
237-
int nPayments = CountPayments();
238-
239-
for (int i = 0; i < nPayments; i++) {
240-
nPaymentsTotalAmount += vecPayments[i].nAmount;
241-
}
242-
243-
return nPaymentsTotalAmount;
236+
return std23::ranges::fold_left(vecPayments, CAmount{0}, [](CAmount s, const auto& p) { return s + p.nAmount; });
244237
}
245238

246239
/**

src/llmq/signing_shares.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -313,10 +313,9 @@ void CSigSharesManager::ProcessMessage(const CNode& pfrom, const std::string& ms
313313
} else if (msg_type == NetMsgType::QBSIGSHARES) {
314314
std::vector<CBatchedSigShares> msgs;
315315
vRecv >> msgs;
316-
size_t totalSigsCount = 0;
317-
for (const auto& bs : msgs) {
318-
totalSigsCount += bs.sigShares.size();
319-
}
316+
const size_t totalSigsCount = std23::ranges::fold_left(msgs, size_t{0}, [](size_t s, const auto& bs) {
317+
return s + bs.sigShares.size();
318+
});
320319
if (totalSigsCount > MAX_MSGS_TOTAL_BATCHED_SIGS) {
321320
LogPrint(BCLog::LLMQ_SIGS, "CSigSharesManager::%s -- too many sigs in QBSIGSHARES message. cnt=%d, max=%d, node=%d\n", __func__, msgs.size(), MAX_MSGS_TOTAL_BATCHED_SIGS, pfrom.GetId());
322321
BanNode(pfrom.GetId());

src/llmq/signing_shares.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <llmq/signhash.h>
1212
#include <llmq/signing.h>
1313
#include <msg_result.h>
14+
#include <util/std23.h>
1415

1516
#include <random.h>
1617
#include <saltedhasher.h>
@@ -231,11 +232,8 @@ class SigShareMap
231232

232233
[[nodiscard]] size_t Size() const
233234
{
234-
size_t s = 0;
235-
for (auto& p : internalMap) {
236-
s += p.second.size();
237-
}
238-
return s;
235+
return std23::ranges::fold_left(internalMap, size_t{0},
236+
[](size_t s, const auto& p) { return s + p.second.size(); });
239237
}
240238

241239
[[nodiscard]] size_t CountForSignHash(const uint256& signHash) const

0 commit comments

Comments
 (0)