diff options
author | ameerj <52414509+ameerj@users.noreply.github.com> | 2022-12-20 04:40:50 +0100 |
---|---|---|
committer | ameerj <52414509+ameerj@users.noreply.github.com> | 2022-12-20 04:40:50 +0100 |
commit | c6590ad07b384762fd90ee8852796ec681a69286 (patch) | |
tree | c0d8d2d157f3bb4be01331f2da459c0f68ca4d7b /src/common/scratch_buffer.h | |
parent | tests: Add ScratchBuffer tests (diff) | |
download | yuzu-c6590ad07b384762fd90ee8852796ec681a69286.tar yuzu-c6590ad07b384762fd90ee8852796ec681a69286.tar.gz yuzu-c6590ad07b384762fd90ee8852796ec681a69286.tar.bz2 yuzu-c6590ad07b384762fd90ee8852796ec681a69286.tar.lz yuzu-c6590ad07b384762fd90ee8852796ec681a69286.tar.xz yuzu-c6590ad07b384762fd90ee8852796ec681a69286.tar.zst yuzu-c6590ad07b384762fd90ee8852796ec681a69286.zip |
Diffstat (limited to 'src/common/scratch_buffer.h')
-rw-r--r-- | src/common/scratch_buffer.h | 17 |
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: ~ScratchBuffer() = default; /// This will only grow the buffer's capacity if size is greater than the current capacity. + /// The previously held data will remain intact. void resize(size_t size) { if (size > buffer_capacity) { + auto new_buffer = Common::make_unique_for_overwrite<T[]>(size); + std::move(buffer.get(), buffer.get() + buffer_capacity, new_buffer.get()); + buffer = std::move(new_buffer); + buffer_capacity = size; + } + last_requested_size = size; + } + + /// This will only grow the buffer's capacity if size is greater than the current capacity. + /// The previously held data will be destroyed if a reallocation occurs. + void resize_destructive(size_t size) { + if (size > buffer_capacity) { buffer_capacity = size; buffer = Common::make_unique_for_overwrite<T[]>(buffer_capacity); } @@ -61,6 +74,10 @@ public: return buffer[i]; } + [[nodiscard]] const T& operator[](size_t i) const { + return buffer[i]; + } + [[nodiscard]] size_t size() const noexcept { return last_requested_size; } |