mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-22 09:12:13 -05:00
AK: Span: Allow slicing with zero length.
Previously, the following would not work: Bytes{}.slice(0); because it was asserted that `start < size()`.
This commit is contained in:
parent
413db2d6d5
commit
df21487794
Notes:
sideshowbarker
2024-07-19 03:24:36 +09:00
Author: https://github.com/asynts Commit: https://github.com/SerenityOS/serenity/commit/df21487794d Pull-request: https://github.com/SerenityOS/serenity/pull/3220 Reviewed-by: https://github.com/awesomekling
1 changed files with 10 additions and 6 deletions
16
AK/Span.h
16
AK/Span.h
|
@ -142,16 +142,20 @@ public:
|
|||
|
||||
ALWAYS_INLINE bool is_empty() const { return this->m_size == 0; }
|
||||
|
||||
ALWAYS_INLINE Span slice(size_t start, size_t size) const
|
||||
ALWAYS_INLINE Span slice(size_t start, size_t length) const
|
||||
{
|
||||
ASSERT(start + size <= this->m_size);
|
||||
return { this->m_values + start, size };
|
||||
ASSERT(start + length <= size());
|
||||
return { this->m_values + start, length };
|
||||
}
|
||||
|
||||
ALWAYS_INLINE Span slice(size_t start) const
|
||||
{
|
||||
ASSERT(start < this->m_size);
|
||||
return { this->m_values + start, this->m_size - start };
|
||||
ASSERT(start <= size());
|
||||
return { this->m_values + start, size() - start };
|
||||
}
|
||||
|
||||
ALWAYS_INLINE Span trim(size_t length) const
|
||||
{
|
||||
return { this->m_values, min(size(), length) };
|
||||
}
|
||||
|
||||
ALWAYS_INLINE T* offset(size_t start) const
|
||||
|
|
Loading…
Reference in a new issue