summaryrefslogtreecommitdiff
path: root/src/common/scratch_buffer.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/scratch_buffer.h')
-rw-r--r--src/common/scratch_buffer.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/common/scratch_buffer.h b/src/common/scratch_buffer.h
index 59bb8a9ea..1245a5086 100644
--- a/src/common/scratch_buffer.h
+++ b/src/common/scratch_buffer.h
@@ -25,8 +25,21 @@ public:
25 ~ScratchBuffer() = default; 25 ~ScratchBuffer() = default;
26 26
27 /// This will only grow the buffer's capacity if size is greater than the current capacity. 27 /// This will only grow the buffer's capacity if size is greater than the current capacity.
28 /// The previously held data will remain intact.
28 void resize(size_t size) { 29 void resize(size_t size) {
29 if (size > buffer_capacity) { 30 if (size > buffer_capacity) {
31 auto new_buffer = Common::make_unique_for_overwrite<T[]>(size);
32 std::move(buffer.get(), buffer.get() + buffer_capacity, new_buffer.get());
33 buffer = std::move(new_buffer);
34 buffer_capacity = size;
35 }
36 last_requested_size = size;
37 }
38
39 /// This will only grow the buffer's capacity if size is greater than the current capacity.
40 /// The previously held data will be destroyed if a reallocation occurs.
41 void resize_destructive(size_t size) {
42 if (size > buffer_capacity) {
30 buffer_capacity = size; 43 buffer_capacity = size;
31 buffer = Common::make_unique_for_overwrite<T[]>(buffer_capacity); 44 buffer = Common::make_unique_for_overwrite<T[]>(buffer_capacity);
32 } 45 }
@@ -61,6 +74,10 @@ public:
61 return buffer[i]; 74 return buffer[i];
62 } 75 }
63 76
77 [[nodiscard]] const T& operator[](size_t i) const {
78 return buffer[i];
79 }
80
64 [[nodiscard]] size_t size() const noexcept { 81 [[nodiscard]] size_t size() const noexcept {
65 return last_requested_size; 82 return last_requested_size;
66 } 83 }