mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-09 09:34:57 +09:00
AK: Mark some Span functions with [[nodiscard]]
I was confused by the trim() API, thinking it would mutate the span it was called on. Mark all const functions that return a new span with [[nodiscard]] so we can catch such mistakes.
This commit is contained in:
parent
a8dbfc3398
commit
050eb5afa8
Notes:
sideshowbarker
2024-07-19 00:44:21 +09:00
Author: https://github.com/awesomekling
Commit: 050eb5afa8
1 changed files with 3 additions and 3 deletions
|
@ -134,18 +134,18 @@ public:
|
||||||
ALWAYS_INLINE constexpr bool is_null() const { return this->m_values == nullptr; }
|
ALWAYS_INLINE constexpr bool is_null() const { return this->m_values == nullptr; }
|
||||||
ALWAYS_INLINE constexpr bool is_empty() const { return this->m_size == 0; }
|
ALWAYS_INLINE constexpr bool is_empty() const { return this->m_size == 0; }
|
||||||
|
|
||||||
ALWAYS_INLINE constexpr Span slice(size_t start, size_t length) const
|
[[nodiscard]] ALWAYS_INLINE constexpr Span slice(size_t start, size_t length) const
|
||||||
{
|
{
|
||||||
ASSERT(start + length <= size());
|
ASSERT(start + length <= size());
|
||||||
return { this->m_values + start, length };
|
return { this->m_values + start, length };
|
||||||
}
|
}
|
||||||
ALWAYS_INLINE constexpr Span slice(size_t start) const
|
[[nodiscard]] ALWAYS_INLINE constexpr Span slice(size_t start) const
|
||||||
{
|
{
|
||||||
ASSERT(start <= size());
|
ASSERT(start <= size());
|
||||||
return { this->m_values + start, size() - start };
|
return { this->m_values + start, size() - start };
|
||||||
}
|
}
|
||||||
|
|
||||||
ALWAYS_INLINE constexpr Span trim(size_t length) const
|
[[nodiscard]] ALWAYS_INLINE constexpr Span trim(size_t length) const
|
||||||
{
|
{
|
||||||
return { this->m_values, min(size(), length) };
|
return { this->m_values, min(size(), length) };
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue