Skip to content

Commit 568dd2f

Browse files
committed
Replace MakeSpan helper with Span deduction guide
1 parent 383d350 commit 568dd2f

16 files changed

+106
-104
lines changed

src/base58.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ std::string EncodeBase58Check(Span<const unsigned char> input)
149149
return false;
150150
}
151151
// re-calculate the checksum, ensure it matches the included 4-byte checksum
152-
uint256 hash = Hash(MakeSpan(vchRet).first(vchRet.size() - 4));
152+
uint256 hash = Hash(Span{vchRet}.first(vchRet.size() - 4));
153153
if (memcmp(&hash, &vchRet[vchRet.size() - 4], 4) != 0) {
154154
vchRet.clear();
155155
return false;

src/compressor.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ struct ScriptCompression
6565
void Ser(Stream &s, const CScript& script) {
6666
CompressedScript compr;
6767
if (CompressScript(script, compr)) {
68-
s << MakeSpan(compr);
68+
s << Span{compr};
6969
return;
7070
}
7171
unsigned int nSize = script.size() + nSpecialScripts;
7272
s << VARINT(nSize);
73-
s << MakeSpan(script);
73+
s << Span{script};
7474
}
7575

7676
template<typename Stream>
@@ -79,7 +79,7 @@ struct ScriptCompression
7979
s >> VARINT(nSize);
8080
if (nSize < nSpecialScripts) {
8181
CompressedScript vch(GetSpecialScriptSize(nSize), 0x00);
82-
s >> MakeSpan(vch);
82+
s >> Span{vch};
8383
DecompressScript(script, nSize, vch);
8484
return;
8585
}
@@ -90,7 +90,7 @@ struct ScriptCompression
9090
s.ignore(nSize);
9191
} else {
9292
script.resize(nSize);
93-
s >> MakeSpan(script);
93+
s >> Span{script};
9494
}
9595
}
9696
};

src/net_processing.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1815,7 +1815,7 @@ void PeerManagerImpl::ProcessGetBlockData(CNode& pfrom, Peer& peer, const CInv&
18151815
if (!ReadRawBlockFromDisk(block_data, pindex, m_chainparams.MessageStart())) {
18161816
assert(!"cannot load block from disk");
18171817
}
1818-
m_connman.PushMessage(&pfrom, msgMaker.Make(NetMsgType::BLOCK, MakeSpan(block_data)));
1818+
m_connman.PushMessage(&pfrom, msgMaker.Make(NetMsgType::BLOCK, Span{block_data}));
18191819
// Don't set pblock as we've sent the block
18201820
} else {
18211821
// Send block from disk

src/netaddress.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ static void Checksum(Span<const uint8_t> addr_pubkey, uint8_t (&checksum)[CHECKS
196196

197197
SHA3_256 hasher;
198198

199-
hasher.Write(MakeSpan(prefix).first(prefix_len));
199+
hasher.Write(Span{prefix}.first(prefix_len));
200200
hasher.Write(addr_pubkey);
201201
hasher.Write(VERSION);
202202

@@ -693,13 +693,13 @@ uint32_t CNetAddr::GetLinkedIPv4() const
693693
return ReadBE32(m_addr.data());
694694
} else if (IsRFC6052() || IsRFC6145()) {
695695
// mapped IPv4, SIIT translated IPv4: the IPv4 address is the last 4 bytes of the address
696-
return ReadBE32(MakeSpan(m_addr).last(ADDR_IPV4_SIZE).data());
696+
return ReadBE32(Span{m_addr}.last(ADDR_IPV4_SIZE).data());
697697
} else if (IsRFC3964()) {
698698
// 6to4 tunneled IPv4: the IPv4 address is in bytes 2-6
699-
return ReadBE32(MakeSpan(m_addr).subspan(2, ADDR_IPV4_SIZE).data());
699+
return ReadBE32(Span{m_addr}.subspan(2, ADDR_IPV4_SIZE).data());
700700
} else if (IsRFC4380()) {
701701
// Teredo tunneled IPv4: the IPv4 address is in the last 4 bytes of the address, but bitflipped
702-
return ~ReadBE32(MakeSpan(m_addr).last(ADDR_IPV4_SIZE).data());
702+
return ~ReadBE32(Span{m_addr}.last(ADDR_IPV4_SIZE).data());
703703
}
704704
assert(false);
705705
}

src/netaddress.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ class CNetAddr
433433

434434
if (SetNetFromBIP155Network(bip155_net, address_size)) {
435435
m_addr.resize(address_size);
436-
s >> MakeSpan(m_addr);
436+
s >> Span{m_addr};
437437

438438
if (m_net != NET_IPV6) {
439439
return;

src/policy/policy.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ bool IsWitnessStandard(const CTransaction& tx, const CCoinsViewCache& mapInputs)
251251
// - No annexes
252252
if (witnessversion == 1 && witnessprogram.size() == WITNESS_V1_TAPROOT_SIZE && !p2sh) {
253253
// Taproot spend (non-P2SH-wrapped, version 1, witness program size 32; see BIP 341)
254-
auto stack = MakeSpan(tx.vin[i].scriptWitness.stack);
254+
Span stack{tx.vin[i].scriptWitness.stack};
255255
if (stack.size() >= 2 && !stack.back().empty() && stack.back()[0] == ANNEX_TAG) {
256256
// Annexes are nonstandard as long as no semantics are defined for them.
257257
return false;

src/psbt.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ struct PSBTInput
8181
if (final_script_sig.empty() && final_script_witness.IsNull()) {
8282
// Write any partial signatures
8383
for (auto sig_pair : partial_sigs) {
84-
SerializeToVector(s, PSBT_IN_PARTIAL_SIG, MakeSpan(sig_pair.second.first));
84+
SerializeToVector(s, PSBT_IN_PARTIAL_SIG, Span{sig_pair.second.first});
8585
s << sig_pair.second.second;
8686
}
8787

src/pubkey.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,13 +157,13 @@ class CPubKey
157157
//! Get the KeyID of this public key (hash of its serialization)
158158
CKeyID GetID() const
159159
{
160-
return CKeyID(Hash160(MakeSpan(vch).first(size())));
160+
return CKeyID(Hash160(Span{vch}.first(size())));
161161
}
162162

163163
//! Get the 256-bit hash of this public key.
164164
uint256 GetHash() const
165165
{
166-
return Hash(MakeSpan(vch).first(size()));
166+
return Hash(Span{vch}.first(size()));
167167
}
168168

169169
/*

src/script/descriptor.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ class DescriptorImpl : public Descriptor
631631
out.origins.emplace(entry.first.GetID(), std::make_pair<CPubKey, KeyOriginInfo>(CPubKey(entry.first), std::move(entry.second)));
632632
}
633633

634-
output_scripts = MakeScripts(pubkeys, MakeSpan(subscripts), out);
634+
output_scripts = MakeScripts(pubkeys, Span{subscripts}, out);
635635
return true;
636636
}
637637

@@ -974,10 +974,10 @@ std::unique_ptr<PubkeyProvider> ParsePubkeyInner(uint32_t key_exp_index, const S
974974
}
975975
KeyPath path;
976976
DeriveType type = DeriveType::NO;
977-
if (split.back() == MakeSpan("*").first(1)) {
977+
if (split.back() == Span{"*"}.first(1)) {
978978
split.pop_back();
979979
type = DeriveType::UNHARDENED;
980-
} else if (split.back() == MakeSpan("*'").first(2) || split.back() == MakeSpan("*h").first(2)) {
980+
} else if (split.back() == Span{"*'"}.first(2) || split.back() == Span{"*h"}.first(2)) {
981981
split.pop_back();
982982
type = DeriveType::HARDENED;
983983
}

src/script/sign.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ static bool SignTaprootScript(const SigningProvider& provider, const BaseSignatu
167167

168168
// <xonly pubkey> OP_CHECKSIG
169169
if (script.size() == 34 && script[33] == OP_CHECKSIG && script[0] == 0x20) {
170-
XOnlyPubKey pubkey(MakeSpan(script).subspan(1, 32));
170+
XOnlyPubKey pubkey{Span{script}.subspan(1, 32)};
171171
std::vector<unsigned char> sig;
172172
if (CreateTaprootScriptSig(creator, sigdata, provider, sig, pubkey, leaf_hash, sigversion)) {
173173
result = Vector(std::move(sig));

0 commit comments

Comments
 (0)