From 64869807e2e4604f3d6334feeaf890515e9edb81 Mon Sep 17 00:00:00 2001 From: ameerj <52414509+ameerj@users.noreply.github.com> Date: Mon, 19 Dec 2022 12:30:52 -0500 Subject: tests: Add ScratchBuffer tests --- src/common/scratch_buffer.h | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'src/common') diff --git a/src/common/scratch_buffer.h b/src/common/scratch_buffer.h index afbe2eee1..59bb8a9ea 100644 --- a/src/common/scratch_buffer.h +++ b/src/common/scratch_buffer.h @@ -19,16 +19,16 @@ public: ScratchBuffer() = default; explicit ScratchBuffer(size_t initial_capacity) - : last_requested_size{initial_capacity}, capacity{initial_capacity}, + : last_requested_size{initial_capacity}, buffer_capacity{initial_capacity}, buffer{Common::make_unique_for_overwrite(initial_capacity)} {} ~ScratchBuffer() = default; /// This will only grow the buffer's capacity if size is greater than the current capacity. void resize(size_t size) { - if (size > capacity) { - capacity = size; - buffer = Common::make_unique_for_overwrite(capacity); + if (size > buffer_capacity) { + buffer_capacity = size; + buffer = Common::make_unique_for_overwrite(buffer_capacity); } last_requested_size = size; } @@ -65,9 +65,13 @@ public: return last_requested_size; } + [[nodiscard]] size_t capacity() const noexcept { + return buffer_capacity; + } + private: size_t last_requested_size{}; - size_t capacity{}; + size_t buffer_capacity{}; std::unique_ptr buffer{}; }; -- cgit v1.2.3