Skip to content

Commit fa2ae0a

Browse files
author
MarcoFalke
committed
span: Add Span::empty() and use it in script/descriptor
1 parent fa8a992 commit fa2ae0a

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

src/script/descriptor.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -825,9 +825,9 @@ std::unique_ptr<PubkeyProvider> ParsePubkey(uint32_t key_exp_index, const Span<c
825825
return nullptr;
826826
}
827827
if (origin_split.size() == 1) return ParsePubkeyInner(key_exp_index, origin_split[0], permit_uncompressed, out, error);
828-
if (origin_split[0].size() < 1 || origin_split[0][0] != '[') {
828+
if (origin_split[0].empty() || origin_split[0][0] != '[') {
829829
error = strprintf("Key origin start '[ character expected but not found, got '%c' instead",
830-
origin_split[0].size() < 1 ? /** empty, implies split char */ ']' : origin_split[0][0]);
830+
origin_split[0].empty() ? /** empty, implies split char */ ']' : origin_split[0][0]);
831831
return nullptr;
832832
}
833833
auto slash_split = Split(origin_split[0].subspan(1), '/');
@@ -897,7 +897,7 @@ std::unique_ptr<DescriptorImpl> ParseScript(uint32_t key_exp_index, Span<const c
897897
providers.emplace_back(std::move(pk));
898898
key_exp_index++;
899899
}
900-
if (providers.size() < 1 || providers.size() > 16) {
900+
if (providers.empty() || providers.size() > 16) {
901901
error = strprintf("Cannot have %u keys in multisig; must have between 1 and 16 keys, inclusive", providers.size());
902902
return nullptr;
903903
} else if (thres < 1) {

src/span.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ class Span
151151
return m_data[m_size - 1];
152152
}
153153
constexpr std::size_t size() const noexcept { return m_size; }
154+
constexpr bool empty() const noexcept { return size() == 0; }
154155
CONSTEXPR_IF_NOT_DEBUG C& operator[](std::size_t pos) const noexcept
155156
{
156157
ASSERT_IF_DEBUG(size() > pos);

0 commit comments

Comments
 (0)