From f8dfc74f8ba782ddf9aaac4f0616391b93918d28 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 21 Apr 2021 21:40:42 +0200 Subject: [PATCH] AK: Decorate most of ByteBuffer with [[nodiscard]] --- AK/ByteBuffer.h | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/AK/ByteBuffer.h b/AK/ByteBuffer.h index 039935bc7e..6ad395ed7c 100644 --- a/AK/ByteBuffer.h +++ b/AK/ByteBuffer.h @@ -123,17 +123,17 @@ public: return *this; } - static ByteBuffer create_uninitialized(size_t size) { return ByteBuffer(ByteBufferImpl::create_uninitialized(size)); } - static ByteBuffer create_zeroed(size_t size) { return ByteBuffer(ByteBufferImpl::create_zeroed(size)); } - static ByteBuffer copy(const void* data, size_t size) { return ByteBuffer(ByteBufferImpl::copy(data, size)); } - static ByteBuffer copy(ReadonlyBytes bytes) { return ByteBuffer(ByteBufferImpl::copy(bytes.data(), bytes.size())); } + [[nodiscard]] static ByteBuffer create_uninitialized(size_t size) { return ByteBuffer(ByteBufferImpl::create_uninitialized(size)); } + [[nodiscard]] static ByteBuffer create_zeroed(size_t size) { return ByteBuffer(ByteBufferImpl::create_zeroed(size)); } + [[nodiscard]] static ByteBuffer copy(const void* data, size_t size) { return ByteBuffer(ByteBufferImpl::copy(data, size)); } + [[nodiscard]] static ByteBuffer copy(ReadonlyBytes bytes) { return ByteBuffer(ByteBufferImpl::copy(bytes.data(), bytes.size())); } ~ByteBuffer() { clear(); } void clear() { m_impl = nullptr; } operator bool() const { return !is_null(); } bool operator!() const { return is_null(); } - bool is_null() const { return m_impl == nullptr; } + [[nodiscard]] bool is_null() const { return m_impl == nullptr; } // Disable default implementations that would use surprising integer promotion. bool operator==(const ByteBuffer& other) const; @@ -143,30 +143,30 @@ public: bool operator<(const ByteBuffer& other) const = delete; bool operator>(const ByteBuffer& other) const = delete; - u8& operator[](size_t i) + [[nodiscard]] u8& operator[](size_t i) { VERIFY(m_impl); return (*m_impl)[i]; } - u8 operator[](size_t i) const + [[nodiscard]] u8 operator[](size_t i) const { VERIFY(m_impl); return (*m_impl)[i]; } - bool is_empty() const { return !m_impl || m_impl->is_empty(); } - size_t size() const { return m_impl ? m_impl->size() : 0; } + [[nodiscard]] bool is_empty() const { return !m_impl || m_impl->is_empty(); } + [[nodiscard]] size_t size() const { return m_impl ? m_impl->size() : 0; } - u8* data() { return m_impl ? m_impl->data() : nullptr; } - const u8* data() const { return m_impl ? m_impl->data() : nullptr; } + [[nodiscard]] u8* data() { return m_impl ? m_impl->data() : nullptr; } + [[nodiscard]] const u8* data() const { return m_impl ? m_impl->data() : nullptr; } - Bytes bytes() + [[nodiscard]] Bytes bytes() { if (m_impl) { return m_impl->bytes(); } return {}; } - ReadonlyBytes bytes() const + [[nodiscard]] ReadonlyBytes bytes() const { if (m_impl) { return m_impl->bytes(); @@ -174,14 +174,14 @@ public: return {}; } - Span span() + [[nodiscard]] Span span() { if (m_impl) { return m_impl->span(); } return {}; } - Span span() const + [[nodiscard]] Span span() const { if (m_impl) { return m_impl->span(); @@ -189,13 +189,13 @@ public: return {}; } - u8* offset_pointer(int offset) { return m_impl ? m_impl->offset_pointer(offset) : nullptr; } - const u8* offset_pointer(int offset) const { return m_impl ? m_impl->offset_pointer(offset) : nullptr; } + [[nodiscard]] u8* offset_pointer(int offset) { return m_impl ? m_impl->offset_pointer(offset) : nullptr; } + [[nodiscard]] const u8* offset_pointer(int offset) const { return m_impl ? m_impl->offset_pointer(offset) : nullptr; } - void* end_pointer() { return m_impl ? m_impl->end_pointer() : nullptr; } - const void* end_pointer() const { return m_impl ? m_impl->end_pointer() : nullptr; } + [[nodiscard]] void* end_pointer() { return m_impl ? m_impl->end_pointer() : nullptr; } + [[nodiscard]] const void* end_pointer() const { return m_impl ? m_impl->end_pointer() : nullptr; } - ByteBuffer isolated_copy() const + [[nodiscard]] ByteBuffer isolated_copy() const { if (!m_impl) return {}; @@ -209,7 +209,7 @@ public: m_impl->trim(size); } - ByteBuffer slice(size_t offset, size_t size) const + [[nodiscard]] ByteBuffer slice(size_t offset, size_t size) const { if (is_null()) return {};