mirror of
https://github.com/SerenityOS/serenity
synced 2024-10-02 22:24:26 +00:00
AK: Add Span<T>::matching_prefix_length
This commit is contained in:
parent
2109f61b0d
commit
3526d67694
12
AK/Span.h
12
AK/Span.h
|
@ -227,6 +227,18 @@ public:
|
|||
return TypedTransfer<T>::compare(data(), other.data(), other.size());
|
||||
}
|
||||
|
||||
[[nodiscard]] size_t constexpr matching_prefix_length(ReadonlySpan<T> other) const
|
||||
{
|
||||
auto maximum_length = min(size(), other.size());
|
||||
|
||||
for (size_t i = 0; i < maximum_length; i++) {
|
||||
if (data()[i] != other.data()[i])
|
||||
return i;
|
||||
}
|
||||
|
||||
return maximum_length;
|
||||
}
|
||||
|
||||
[[nodiscard]] ALWAYS_INLINE constexpr T const& at(size_t index) const
|
||||
{
|
||||
VERIFY(index < this->m_size);
|
||||
|
|
Loading…
Reference in a new issue