Skip to content

Commit fa720b9

Browse files
author
MarcoFalke
committed
refactor: Return std::span from MakeByteSpan
In theory this commit should only touch the span.h header, because std::span can implicilty convert into Span in most places, if needed. However, at least when using the clang compiler, there are some false-positive lifetimebound warnings and some implicit conversions can not be resolved. Thus, this refactoring commit also changed the affected places to replace Span with std::span.
1 parent aa68ed2 commit fa720b9

File tree

8 files changed

+14
-14
lines changed

8 files changed

+14
-14
lines changed

src/bip324.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
#include <iterator>
2323
#include <string>
2424

25-
BIP324Cipher::BIP324Cipher(const CKey& key, Span<const std::byte> ent32) noexcept :
26-
m_key(key)
25+
BIP324Cipher::BIP324Cipher(const CKey& key, std::span<const std::byte> ent32) noexcept
26+
: m_key(key)
2727
{
2828
m_our_pubkey = m_key.EllSwiftCreate(ent32);
2929
}

src/bip324.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class BIP324Cipher
4545
BIP324Cipher() = delete;
4646

4747
/** Initialize a BIP324 cipher with specified key and encoding entropy (testing only). */
48-
BIP324Cipher(const CKey& key, Span<const std::byte> ent32) noexcept;
48+
BIP324Cipher(const CKey& key, std::span<const std::byte> ent32) noexcept;
4949

5050
/** Initialize a BIP324 cipher with specified key (testing only). */
5151
BIP324Cipher(const CKey& key, const EllSwiftPubKey& pubkey) noexcept;

src/dbwrapper.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,12 +402,12 @@ void CDBIterator::SeekImpl(Span<const std::byte> key)
402402
m_impl_iter->iter->Seek(slKey);
403403
}
404404

405-
Span<const std::byte> CDBIterator::GetKeyImpl() const
405+
std::span<const std::byte> CDBIterator::GetKeyImpl() const
406406
{
407407
return MakeByteSpan(m_impl_iter->iter->key());
408408
}
409409

410-
Span<const std::byte> CDBIterator::GetValueImpl() const
410+
std::span<const std::byte> CDBIterator::GetValueImpl() const
411411
{
412412
return MakeByteSpan(m_impl_iter->iter->value());
413413
}

src/dbwrapper.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ class CDBIterator
130130
const std::unique_ptr<IteratorImpl> m_impl_iter;
131131

132132
void SeekImpl(Span<const std::byte> key);
133-
Span<const std::byte> GetKeyImpl() const;
134-
Span<const std::byte> GetValueImpl() const;
133+
std::span<const std::byte> GetKeyImpl() const;
134+
std::span<const std::byte> GetValueImpl() const;
135135

136136
public:
137137

src/pubkey.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ bool CPubKey::Derive(CPubKey& pubkeyChild, ChainCode &ccChild, unsigned int nChi
353353
return true;
354354
}
355355

356-
EllSwiftPubKey::EllSwiftPubKey(Span<const std::byte> ellswift) noexcept
356+
EllSwiftPubKey::EllSwiftPubKey(std::span<const std::byte> ellswift) noexcept
357357
{
358358
assert(ellswift.size() == SIZE);
359359
std::copy(ellswift.begin(), ellswift.end(), m_pubkey.begin());

src/pubkey.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ struct EllSwiftPubKey
317317
EllSwiftPubKey() noexcept = default;
318318

319319
/** Construct a new ellswift public key from a given serialization. */
320-
EllSwiftPubKey(Span<const std::byte> ellswift) noexcept;
320+
EllSwiftPubKey(std::span<const std::byte> ellswift) noexcept;
321321

322322
/** Decode to normal compressed CPubKey (for debugging purposes). */
323323
CPubKey Decode() const;

src/span.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,14 +266,14 @@ Span<std::byte> AsWritableBytes(Span<T> s) noexcept
266266
}
267267

268268
template <typename V>
269-
Span<const std::byte> MakeByteSpan(V&& v) noexcept
269+
auto MakeByteSpan(const V& v) noexcept
270270
{
271-
return AsBytes(Span{std::forward<V>(v)});
271+
return std::as_bytes(std::span{v});
272272
}
273273
template <typename V>
274-
Span<std::byte> MakeWritableByteSpan(V&& v) noexcept
274+
auto MakeWritableByteSpan(V&& v) noexcept
275275
{
276-
return AsWritableBytes(Span{std::forward<V>(v)});
276+
return std::as_writable_bytes(std::span{std::forward<V>(v)});
277277
}
278278

279279
// Helper functions to safely cast basic byte pointers to unsigned char pointers.

src/test/util_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ BOOST_AUTO_TEST_CASE(util_HexStr)
243243
constexpr std::string_view out_exp{"04678afdb0"};
244244
constexpr std::span in_s{HEX_PARSE_OUTPUT, out_exp.size() / 2};
245245
const Span<const uint8_t> in_u{MakeUCharSpan(in_s)};
246-
const Span<const std::byte> in_b{MakeByteSpan(in_s)};
246+
const std::span<const std::byte> in_b{MakeByteSpan(in_s)};
247247

248248
BOOST_CHECK_EQUAL(HexStr(in_u), out_exp);
249249
BOOST_CHECK_EQUAL(HexStr(in_s), out_exp);

0 commit comments

Comments
 (0)