mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 00:47:45 +00:00
AK: Annotate more AK::Span methods as nodiscard
This commit is contained in:
parent
60efe18a31
commit
59ba316ac6
1 changed files with 20 additions and 18 deletions
38
AK/Span.h
38
AK/Span.h
|
@ -99,11 +99,11 @@ public:
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
ALWAYS_INLINE constexpr const T* data() const { return this->m_values; }
|
[[nodiscard]] ALWAYS_INLINE constexpr const T* data() const { return this->m_values; }
|
||||||
ALWAYS_INLINE constexpr T* data() { return this->m_values; }
|
[[nodiscard]] ALWAYS_INLINE constexpr T* data() { return this->m_values; }
|
||||||
|
|
||||||
ALWAYS_INLINE constexpr const T* offset_pointer(size_t offset) const { return this->m_values + offset; }
|
[[nodiscard]] ALWAYS_INLINE constexpr const T* offset_pointer(size_t offset) const { return this->m_values + offset; }
|
||||||
ALWAYS_INLINE constexpr T* offset_pointer(size_t offset) { return this->m_values + offset; }
|
[[nodiscard]] ALWAYS_INLINE constexpr T* offset_pointer(size_t offset) { return this->m_values + offset; }
|
||||||
|
|
||||||
using ConstIterator = SimpleIterator<const Span, const T>;
|
using ConstIterator = SimpleIterator<const Span, const T>;
|
||||||
using Iterator = SimpleIterator<Span, T>;
|
using Iterator = SimpleIterator<Span, T>;
|
||||||
|
@ -114,9 +114,9 @@ public:
|
||||||
constexpr ConstIterator end() const { return ConstIterator::end(*this); }
|
constexpr ConstIterator end() const { return ConstIterator::end(*this); }
|
||||||
constexpr Iterator end() { return Iterator::end(*this); }
|
constexpr Iterator end() { return Iterator::end(*this); }
|
||||||
|
|
||||||
ALWAYS_INLINE constexpr size_t size() const { return this->m_size; }
|
[[nodiscard]] ALWAYS_INLINE constexpr size_t size() const { return this->m_size; }
|
||||||
ALWAYS_INLINE constexpr bool is_null() const { return this->m_values == nullptr; }
|
[[nodiscard]] ALWAYS_INLINE constexpr bool is_null() const { return this->m_values == nullptr; }
|
||||||
ALWAYS_INLINE constexpr bool is_empty() const { return this->m_size == 0; }
|
[[nodiscard]] ALWAYS_INLINE constexpr bool is_empty() const { return this->m_size == 0; }
|
||||||
|
|
||||||
[[nodiscard]] 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
|
||||||
{
|
{
|
||||||
|
@ -139,7 +139,7 @@ public:
|
||||||
return { this->m_values, min(size(), length) };
|
return { this->m_values, min(size(), length) };
|
||||||
}
|
}
|
||||||
|
|
||||||
ALWAYS_INLINE constexpr T* offset(size_t start) const
|
[[nodiscard]] ALWAYS_INLINE constexpr T* offset(size_t start) const
|
||||||
{
|
{
|
||||||
VERIFY(start < this->m_size);
|
VERIFY(start < this->m_size);
|
||||||
return this->m_values + start;
|
return this->m_values + start;
|
||||||
|
@ -172,7 +172,7 @@ public:
|
||||||
return size();
|
return size();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool constexpr contains_slow(const T& value) const
|
[[nodiscard]] bool constexpr contains_slow(const T& value) const
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < size(); ++i) {
|
for (size_t i = 0; i < size(); ++i) {
|
||||||
if (at(i) == value)
|
if (at(i) == value)
|
||||||
|
@ -181,7 +181,7 @@ public:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool constexpr starts_with(Span<const T> other) const
|
[[nodiscard]] bool constexpr starts_with(Span<const T> other) const
|
||||||
{
|
{
|
||||||
if (size() < other.size())
|
if (size() < other.size())
|
||||||
return false;
|
return false;
|
||||||
|
@ -189,22 +189,24 @@ public:
|
||||||
return TypedTransfer<T>::compare(data(), other.data(), other.size());
|
return TypedTransfer<T>::compare(data(), other.data(), other.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
ALWAYS_INLINE constexpr const T& at(size_t index) const
|
[[nodiscard]] ALWAYS_INLINE constexpr const T& at(size_t index) const
|
||||||
{
|
|
||||||
VERIFY(index < this->m_size);
|
|
||||||
return this->m_values[index];
|
|
||||||
}
|
|
||||||
ALWAYS_INLINE constexpr T& at(size_t index)
|
|
||||||
{
|
{
|
||||||
VERIFY(index < this->m_size);
|
VERIFY(index < this->m_size);
|
||||||
return this->m_values[index];
|
return this->m_values[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
ALWAYS_INLINE constexpr const T& operator[](size_t index) const
|
[[nodiscard]] ALWAYS_INLINE constexpr T& at(size_t index)
|
||||||
|
{
|
||||||
|
VERIFY(index < this->m_size);
|
||||||
|
return this->m_values[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] ALWAYS_INLINE constexpr const T& operator[](size_t index) const
|
||||||
{
|
{
|
||||||
return at(index);
|
return at(index);
|
||||||
}
|
}
|
||||||
ALWAYS_INLINE constexpr T& operator[](size_t index)
|
|
||||||
|
[[nodiscard]] ALWAYS_INLINE constexpr T& operator[](size_t index)
|
||||||
{
|
{
|
||||||
return at(index);
|
return at(index);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue