mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 11:37:34 +00:00
AK: Add Span<T>::matching_prefix_length
This commit is contained in:
parent
2109f61b0d
commit
3526d67694
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
Add a link
Reference in a new issue