AK: Add Span<T>::matching_prefix_length
This commit is contained in:
parent
2109f61b0d
commit
3526d67694
Notes:
sideshowbarker
2024-07-17 05:06:13 +09:00
Author: https://github.com/timschumi Commit: https://github.com/SerenityOS/serenity/commit/3526d67694 Pull-request: https://github.com/SerenityOS/serenity/pull/19332 Reviewed-by: https://github.com/linusg ✅
1 changed files with 12 additions and 0 deletions
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…
Add table
Reference in a new issue