Skip to content

Commit 83e8ff0

Browse files
committed
merge bitcoin#28687: std::views::reverse
1 parent 525bf6f commit 83e8ff0

File tree

10 files changed

+25
-69
lines changed

10 files changed

+25
-69
lines changed

contrib/devtools/copyright_header.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
'src/bench/nanobench.h',
2424
'src/crypto/*',
2525
'src/ctpl_stl.h',
26-
'src/reverse_iterator.h',
2726
'src/test/fuzz/FuzzedDataProvider.h',
2827
'src/tinyformat.h',
2928
'src/util/expected.h',

src/Makefile.am

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,6 @@ BITCOIN_CORE_H = \
297297
psbt.h \
298298
random.h \
299299
randomenv.h \
300-
reverse_iterator.h \
301300
rpc/blockchain.h \
302301
rpc/client.h \
303302
rpc/index_util.h \

src/net_processing.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
#include <primitives/block.h>
2727
#include <primitives/transaction.h>
2828
#include <random.h>
29-
#include <reverse_iterator.h>
3029
#include <scheduler.h>
3130
#include <streams.h>
3231
#include <sync.h>
@@ -47,6 +46,7 @@
4746
#include <list>
4847
#include <memory>
4948
#include <optional>
49+
#include <ranges>
5050
#include <typeinfo>
5151

5252
#include <spork.h>
@@ -2124,7 +2124,7 @@ void PeerManagerImpl::UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlock
21242124
if (peer == nullptr) return;
21252125

21262126
LOCK(peer->m_block_inv_mutex);
2127-
for (const uint256& hash : reverse_iterate(vHashes)) {
2127+
for (const uint256& hash : vHashes | std::views::reverse) {
21282128
peer->m_blocks_for_headers_relay.push_back(hash);
21292129
}
21302130
});
@@ -3035,7 +3035,7 @@ void PeerManagerImpl::HeadersDirectFetchBlocks(CNode& pfrom, const Peer& peer, c
30353035
} else {
30363036
std::vector<CInv> vGetData;
30373037
// Download as much as possible, from earliest to latest.
3038-
for (const CBlockIndex *pindex : reverse_iterate(vToFetch)) {
3038+
for (const CBlockIndex *pindex : vToFetch | std::views::reverse) {
30393039
if (nodestate->nBlocksInFlight >= MAX_BLOCKS_IN_TRANSIT_PER_PEER) {
30403040
// Can't download any more from this peer
30413041
break;

src/node/blockstorage.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include <hash.h>
1616
#include <masternode/node.h>
1717
#include <pow.h>
18-
#include <reverse_iterator.h>
1918
#include <shutdown.h>
2019
#include <streams.h>
2120
#include <undo.h>
@@ -24,6 +23,7 @@
2423
#include <walletinitinterface.h>
2524

2625
#include <map>
26+
#include <ranges>
2727
#include <unordered_map>
2828

2929
std::atomic_bool fImporting(false);
@@ -410,7 +410,7 @@ const CBlockIndex* BlockManager::GetLastCheckpoint(const CCheckpointData& data)
410410
{
411411
const MapCheckpoints& checkpoints = data.mapCheckpoints;
412412

413-
for (const MapCheckpoints::value_type& i : reverse_iterate(checkpoints)) {
413+
for (const MapCheckpoints::value_type& i : checkpoints | std::views::reverse) {
414414
const uint256& hash = i.second;
415415
const CBlockIndex* pindex = LookupBlockIndex(hash);
416416
if (pindex) {

src/reverse_iterator.h

Lines changed: 0 additions & 39 deletions
This file was deleted.

src/test/fuzz/prevector.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@
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 <test/fuzz/FuzzedDataProvider.h>
6-
#include <test/fuzz/fuzz.h>
7-
85
#include <prevector.h>
9-
#include <vector>
10-
11-
#include <reverse_iterator.h>
126
#include <serialize.h>
137
#include <streams.h>
8+
#include <test/fuzz/FuzzedDataProvider.h>
9+
#include <test/fuzz/fuzz.h>
1410

11+
#include <ranges>
12+
#include <vector>
1513
namespace {
1614

1715
template <unsigned int N, typename T>
@@ -47,15 +45,15 @@ class prevector_tester
4745
assert(v == real_vector[pos]);
4846
++pos;
4947
}
50-
for (const T& v : reverse_iterate(pre_vector)) {
48+
for (const T& v : pre_vector | std::views::reverse) {
5149
--pos;
5250
assert(v == real_vector[pos]);
5351
}
5452
for (const T& v : const_pre_vector) {
5553
assert(v == real_vector[pos]);
5654
++pos;
5755
}
58-
for (const T& v : reverse_iterate(const_pre_vector)) {
56+
for (const T& v : const_pre_vector | std::views::reverse) {
5957
--pos;
6058
assert(v == real_vector[pos]);
6159
}

src/test/prevector_tests.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

55
#include <prevector.h>
6-
#include <vector>
7-
8-
#include <reverse_iterator.h>
96
#include <serialize.h>
107
#include <streams.h>
11-
128
#include <test/util/setup_common.h>
139

1410
#include <boost/test/unit_test.hpp>
1511

12+
#include <ranges>
13+
#include <vector>
14+
1615
BOOST_FIXTURE_TEST_SUITE(prevector_tests, TestingSetup)
1716

1817
template<unsigned int N, typename T>
@@ -57,14 +56,14 @@ class prevector_tester {
5756
for (const T& v : pre_vector) {
5857
local_check(v == real_vector[pos++]);
5958
}
60-
for (const T& v : reverse_iterate(pre_vector)) {
61-
local_check(v == real_vector[--pos]);
59+
for (const T& v : pre_vector | std::views::reverse) {
60+
local_check(v == real_vector[--pos]);
6261
}
6362
for (const T& v : const_pre_vector) {
6463
local_check(v == real_vector[pos++]);
6564
}
66-
for (const T& v : reverse_iterate(const_pre_vector)) {
67-
local_check(v == real_vector[--pos]);
65+
for (const T& v : const_pre_vector | std::views::reverse) {
66+
local_check(v == real_vector[--pos]);
6867
}
6968
CDataStream ss1(SER_DISK, 0);
7069
CDataStream ss2(SER_DISK, 0);

src/txmempool.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#include <policy/fees.h>
1515
#include <policy/policy.h>
1616
#include <policy/settings.h>
17-
#include <reverse_iterator.h>
1817
#include <util/check.h>
1918
#include <util/moneystr.h>
2019
#include <util/overflow.h>
@@ -30,6 +29,7 @@
3029

3130
#include <cmath>
3231
#include <optional>
32+
#include <ranges>
3333

3434
// Helpers for modifying CTxMemPool::mapTx, which is a boost multi_index.
3535
struct update_descendant_state
@@ -195,7 +195,7 @@ void CTxMemPool::UpdateTransactionsFromBlock(const std::vector<uint256> &vHashes
195195
// This maximizes the benefit of the descendant cache and guarantees that
196196
// CTxMemPoolEntry::m_children will be updated, an assumption made in
197197
// UpdateForDescendants.
198-
for (const uint256 &hash : reverse_iterate(vHashesToUpdate)) {
198+
for (const uint256& hash : vHashesToUpdate | std::views::reverse) {
199199
// calculate children from mapNextTx
200200
txiter it = mapTx.find(hash);
201201
if (it == mapTx.end()) {

src/validation.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
#include <pow.h>
3232
#include <primitives/block.h>
3333
#include <primitives/transaction.h>
34-
#include <reverse_iterator.h>
3534
#include <script/script.h>
3635
#include <script/sigcache.h>
3736
#include <shutdown.h>
@@ -66,6 +65,7 @@
6665
#include <deque>
6766
#include <numeric>
6867
#include <optional>
68+
#include <ranges>
6969
#include <string>
7070

7171
#define MICRO 0.000001
@@ -3228,7 +3228,7 @@ bool CChainState::ActivateBestChainStep(BlockValidationState& state, CBlockIndex
32283228
nHeight = nTargetHeight;
32293229

32303230
// Connect new blocks.
3231-
for (CBlockIndex* pindexConnect : reverse_iterate(vpindexToConnect)) {
3231+
for (CBlockIndex* pindexConnect : vpindexToConnect | std::views::reverse) {
32323232
if (!ConnectTip(state, pindexConnect, pindexConnect == pindexMostWork ? pblock : std::shared_ptr<const CBlock>(), connectTrace, disconnectpool)) {
32333233
if (state.IsInvalid()) {
32343234
// The block violates a consensus rule.

src/wallet/wallet.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include <policy/settings.h>
2323
#include <primitives/block.h>
2424
#include <primitives/transaction.h>
25-
#include <reverse_iterator.h>
2625
#include <script/descriptor.h>
2726
#include <script/script.h>
2827
#include <script/sign.h>
@@ -52,7 +51,8 @@
5251
#include <univalue.h>
5352

5453
#include <algorithm>
55-
#include <assert.h>
54+
#include <cassert>
55+
#include <ranges>
5656

5757
using interfaces::FoundBlock;
5858

@@ -3335,7 +3335,7 @@ bool CWallet::AutoBackupWallet(const fs::path& wallet_path, bilingual_str& error
33353335

33363336
// Loop backward through backup files and keep the N newest ones (1 <= N <= 10)
33373337
int counter{0};
3338-
for (const auto& [entry_time, entry] : reverse_iterate(folder_set)) {
3338+
for (const auto& [entry_time, entry] : folder_set | std::views::reverse) {
33393339
counter++;
33403340
if (counter > nWalletBackups) {
33413341
// More than nWalletBackups backups: delete oldest one(s)

0 commit comments

Comments
 (0)