From bf12b5d52c7030b162e7c25b1fc7cddcdf4e4b0d Mon Sep 17 00:00:00 2001 From: Jack Lloyd Date: Wed, 3 Apr 2024 18:50:57 -0400 Subject: [PATCH] Apply constexpr to BufferStuffer --- src/lib/utils/stl_util.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/lib/utils/stl_util.h b/src/lib/utils/stl_util.h index 7f52d60272..32196ec3f4 100644 --- a/src/lib/utils/stl_util.h +++ b/src/lib/utils/stl_util.h @@ -198,13 +198,13 @@ class BufferSlicer final { */ class BufferStuffer { public: - BufferStuffer(std::span buffer) : m_buffer(buffer) {} + constexpr BufferStuffer(std::span buffer) : m_buffer(buffer) {} /** * @returns a span for the next @p bytes bytes in the concatenated buffer. * Checks that the buffer is not exceded. */ - std::span next(size_t bytes) { + constexpr std::span next(size_t bytes) { BOTAN_STATE_CHECK(m_buffer.size() >= bytes); auto result = m_buffer.first(bytes); @@ -213,7 +213,7 @@ class BufferStuffer { } template - std::span next() { + constexpr std::span next() { BOTAN_STATE_CHECK(m_buffer.size() >= bytes); auto result = m_buffer.first(); @@ -229,21 +229,21 @@ class BufferStuffer { /** * @returns a reference to the next single byte in the buffer */ - uint8_t& next_byte() { return next(1)[0]; } + constexpr uint8_t& next_byte() { return next(1)[0]; } - void append(std::span buffer) { + constexpr void append(std::span buffer) { auto sink = next(buffer.size()); std::copy(buffer.begin(), buffer.end(), sink.begin()); } - void append(uint8_t b, size_t repeat = 1) { + constexpr void append(uint8_t b, size_t repeat = 1) { auto sink = next(repeat); std::fill(sink.begin(), sink.end(), b); } - bool full() const { return m_buffer.empty(); } + constexpr bool full() const { return m_buffer.empty(); } - size_t remaining_capacity() const { return m_buffer.size(); } + constexpr size_t remaining_capacity() const { return m_buffer.size(); } private: std::span m_buffer;