mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 15:57:35 +00:00
Everywhere: Use ReadonlySpan<T> instead of Span<T const>
This commit is contained in:
parent
1c92e6ee9d
commit
63b11030f0
102 changed files with 206 additions and 206 deletions
|
@ -31,7 +31,7 @@ struct Array {
|
|||
|
||||
[[nodiscard]] constexpr size_t size() const { return Size; }
|
||||
|
||||
[[nodiscard]] constexpr Span<T const> span() const { return { __data, Size }; }
|
||||
[[nodiscard]] constexpr ReadonlySpan<T> span() const { return { __data, Size }; }
|
||||
[[nodiscard]] constexpr Span<T> span() { return { __data, Size }; }
|
||||
|
||||
[[nodiscard]] constexpr T const& at(size_t index) const
|
||||
|
@ -76,7 +76,7 @@ struct Array {
|
|||
[[nodiscard]] constexpr ConstIterator end() const { return ConstIterator::end(*this); }
|
||||
[[nodiscard]] constexpr Iterator end() { return Iterator::end(*this); }
|
||||
|
||||
[[nodiscard]] constexpr operator Span<T const>() const { return span(); }
|
||||
[[nodiscard]] constexpr operator ReadonlySpan<T>() const { return span(); }
|
||||
[[nodiscard]] constexpr operator Span<T>() { return span(); }
|
||||
|
||||
constexpr size_t fill(T const& value)
|
||||
|
|
|
@ -123,8 +123,8 @@ public:
|
|||
[[nodiscard]] Bytes bytes() { return { data(), size() }; }
|
||||
[[nodiscard]] ReadonlyBytes bytes() const { return { data(), size() }; }
|
||||
|
||||
[[nodiscard]] AK::Span<u8> span() { return { data(), size() }; }
|
||||
[[nodiscard]] AK::Span<u8 const> span() const { return { data(), size() }; }
|
||||
[[nodiscard]] AK::Bytes span() { return { data(), size() }; }
|
||||
[[nodiscard]] AK::ReadonlyBytes span() const { return { data(), size() }; }
|
||||
|
||||
[[nodiscard]] u8* offset_pointer(size_t offset) { return data() + offset; }
|
||||
[[nodiscard]] u8 const* offset_pointer(size_t offset) const { return data() + offset; }
|
||||
|
|
|
@ -163,7 +163,7 @@ public:
|
|||
ConstIterator end() const { return ConstIterator::end(*this); }
|
||||
|
||||
Span<T> span() { return { data(), size() }; }
|
||||
Span<T const> span() const { return { data(), size() }; }
|
||||
ReadonlySpan<T> span() const { return { data(), size() }; }
|
||||
|
||||
private:
|
||||
struct Storage {
|
||||
|
|
18
AK/Format.h
18
AK/Format.h
|
@ -264,13 +264,13 @@ private:
|
|||
|
||||
class TypeErasedFormatParams {
|
||||
public:
|
||||
Span<TypeErasedParameter const> parameters() const { return m_parameters; }
|
||||
ReadonlySpan<TypeErasedParameter> parameters() const { return m_parameters; }
|
||||
|
||||
void set_parameters(Span<TypeErasedParameter const> parameters) { m_parameters = parameters; }
|
||||
void set_parameters(ReadonlySpan<TypeErasedParameter> parameters) { m_parameters = parameters; }
|
||||
size_t take_next_index() { return m_next_index++; }
|
||||
|
||||
private:
|
||||
Span<TypeErasedParameter const> m_parameters;
|
||||
ReadonlySpan<TypeErasedParameter> m_parameters;
|
||||
size_t m_next_index { 0 };
|
||||
};
|
||||
|
||||
|
@ -359,14 +359,14 @@ struct Formatter<StringView> : StandardFormatter {
|
|||
|
||||
template<typename T>
|
||||
requires(HasFormatter<T>)
|
||||
struct Formatter<Span<T const>> : StandardFormatter {
|
||||
struct Formatter<ReadonlySpan<T>> : StandardFormatter {
|
||||
Formatter() = default;
|
||||
explicit Formatter(StandardFormatter formatter)
|
||||
: StandardFormatter(move(formatter))
|
||||
{
|
||||
}
|
||||
|
||||
ErrorOr<void> format(FormatBuilder& builder, Span<T const> value)
|
||||
ErrorOr<void> format(FormatBuilder& builder, ReadonlySpan<T> value)
|
||||
{
|
||||
if (m_mode == Mode::Pointer) {
|
||||
Formatter<FlatPtr> formatter { *this };
|
||||
|
@ -406,19 +406,19 @@ struct Formatter<Span<T const>> : StandardFormatter {
|
|||
|
||||
template<typename T>
|
||||
requires(HasFormatter<T>)
|
||||
struct Formatter<Span<T>> : Formatter<Span<T const>> {
|
||||
struct Formatter<Span<T>> : Formatter<ReadonlySpan<T>> {
|
||||
ErrorOr<void> format(FormatBuilder& builder, Span<T> value)
|
||||
{
|
||||
return Formatter<Span<T const>>::format(builder, value);
|
||||
return Formatter<ReadonlySpan<T>>::format(builder, value);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T, size_t inline_capacity>
|
||||
requires(HasFormatter<T>)
|
||||
struct Formatter<Vector<T, inline_capacity>> : Formatter<Span<T const>> {
|
||||
struct Formatter<Vector<T, inline_capacity>> : Formatter<ReadonlySpan<T>> {
|
||||
ErrorOr<void> format(FormatBuilder& builder, Vector<T, inline_capacity> const& value)
|
||||
{
|
||||
return Formatter<Span<T const>>::format(builder, value.span());
|
||||
return Formatter<ReadonlySpan<T>>::format(builder, value.span());
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ constexpr void const* bitap_bitwise(void const* haystack, size_t haystack_length
|
|||
}
|
||||
|
||||
template<typename HaystackIterT>
|
||||
inline Optional<size_t> memmem(HaystackIterT const& haystack_begin, HaystackIterT const& haystack_end, Span<u8 const> needle)
|
||||
inline Optional<size_t> memmem(HaystackIterT const& haystack_begin, HaystackIterT const& haystack_end, ReadonlyBytes needle)
|
||||
requires(requires { (*haystack_begin).data(); (*haystack_begin).size(); })
|
||||
{
|
||||
auto prepare_kmp_partial_table = [&] {
|
||||
|
@ -123,7 +123,7 @@ inline Optional<size_t> memmem_optional(void const* haystack, size_t haystack_le
|
|||
}
|
||||
|
||||
// Fallback to KMP.
|
||||
Array<Span<u8 const>, 1> spans { Span<u8 const> { (u8 const*)haystack, haystack_length } };
|
||||
Array<ReadonlyBytes, 1> spans { ReadonlyBytes { (u8 const*)haystack, haystack_length } };
|
||||
return memmem(spans.begin(), spans.end(), { (u8 const*)needle, needle_length });
|
||||
}
|
||||
|
||||
|
|
|
@ -192,7 +192,7 @@ public:
|
|||
return false;
|
||||
}
|
||||
|
||||
[[nodiscard]] bool constexpr starts_with(Span<T const> other) const
|
||||
[[nodiscard]] bool constexpr starts_with(ReadonlySpan<T> other) const
|
||||
{
|
||||
if (size() < other.size())
|
||||
return false;
|
||||
|
@ -250,7 +250,7 @@ public:
|
|||
return TypedTransfer<T>::compare(data(), other.data(), size());
|
||||
}
|
||||
|
||||
ALWAYS_INLINE constexpr operator Span<T const>() const
|
||||
ALWAYS_INLINE constexpr operator ReadonlySpan<T>() const
|
||||
{
|
||||
return { data(), size() };
|
||||
}
|
||||
|
|
|
@ -77,13 +77,13 @@ public:
|
|||
return m_high;
|
||||
}
|
||||
|
||||
Span<u8> bytes()
|
||||
Bytes bytes()
|
||||
{
|
||||
return Span<u8>(reinterpret_cast<u8*>(this), sizeof(R));
|
||||
return Bytes { reinterpret_cast<u8*>(this), sizeof(R) };
|
||||
}
|
||||
Span<u8 const> bytes() const
|
||||
ReadonlyBytes bytes() const
|
||||
{
|
||||
return Span<u8 const>(reinterpret_cast<u8 const*>(this), sizeof(R));
|
||||
return ReadonlyBytes { reinterpret_cast<u8 const*>(this), sizeof(R) };
|
||||
}
|
||||
|
||||
template<Unsigned U>
|
||||
|
|
|
@ -64,7 +64,7 @@ public:
|
|||
Utf16View() = default;
|
||||
~Utf16View() = default;
|
||||
|
||||
explicit Utf16View(Span<u16 const> code_units)
|
||||
explicit Utf16View(ReadonlySpan<u16> code_units)
|
||||
: m_code_units(code_units)
|
||||
{
|
||||
}
|
||||
|
@ -116,7 +116,7 @@ private:
|
|||
|
||||
size_t calculate_length_in_code_points() const;
|
||||
|
||||
Span<u16 const> m_code_units;
|
||||
ReadonlySpan<u16> m_code_units;
|
||||
mutable Optional<size_t> m_length_in_code_points;
|
||||
};
|
||||
|
||||
|
|
|
@ -90,7 +90,7 @@ public:
|
|||
m_size = other.size();
|
||||
}
|
||||
|
||||
explicit Vector(Span<T const> other)
|
||||
explicit Vector(ReadonlySpan<T> other)
|
||||
requires(!IsLvalueReference<T>)
|
||||
{
|
||||
ensure_capacity(other.size());
|
||||
|
@ -112,10 +112,10 @@ public:
|
|||
}
|
||||
|
||||
Span<StorageType> span() { return { data(), size() }; }
|
||||
Span<StorageType const> span() const { return { data(), size() }; }
|
||||
ReadonlySpan<StorageType> span() const { return { data(), size() }; }
|
||||
|
||||
operator Span<StorageType>() { return span(); }
|
||||
operator Span<StorageType const>() const { return span(); }
|
||||
operator ReadonlySpan<StorageType>() const { return span(); }
|
||||
|
||||
bool is_empty() const { return size() == 0; }
|
||||
ALWAYS_INLINE size_t size() const { return m_size; }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue