diff options
author | ameerj <52414509+ameerj@users.noreply.github.com> | 2022-12-19 12:30:52 -0500 |
---|---|---|
committer | ameerj <52414509+ameerj@users.noreply.github.com> | 2022-12-19 18:08:04 -0500 |
commit | 64869807e2e4604f3d6334feeaf890515e9edb81 (patch) | |
tree | 5af972e67d4713d1a10919e100985e2383225680 /src/common/scratch_buffer.h | |
parent | 61e4f2d931449e60d8d720862997ac565fce6634 (diff) |
tests: Add ScratchBuffer tests
Diffstat (limited to 'src/common/scratch_buffer.h')
-rw-r--r-- | src/common/scratch_buffer.h | 14 |
1 files changed, 9 insertions, 5 deletions
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<T[]>(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<T[]>(capacity); + if (size > buffer_capacity) { + buffer_capacity = size; + buffer = Common::make_unique_for_overwrite<T[]>(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<T[]> buffer{}; }; |