diff options
| author | 2022-12-19 12:30:52 -0500 | |
|---|---|---|
| committer | 2022-12-19 18:08:04 -0500 | |
| commit | 64869807e2e4604f3d6334feeaf890515e9edb81 (patch) | |
| tree | 5af972e67d4713d1a10919e100985e2383225680 /src/common/scratch_buffer.h | |
| parent | dma_pusher: Rework command_headers usage (diff) | |
| download | yuzu-64869807e2e4604f3d6334feeaf890515e9edb81.tar.gz yuzu-64869807e2e4604f3d6334feeaf890515e9edb81.tar.xz yuzu-64869807e2e4604f3d6334feeaf890515e9edb81.zip | |
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: | |||
| 19 | ScratchBuffer() = default; | 19 | ScratchBuffer() = default; |
| 20 | 20 | ||
| 21 | explicit ScratchBuffer(size_t initial_capacity) | 21 | explicit ScratchBuffer(size_t initial_capacity) |
| 22 | : last_requested_size{initial_capacity}, capacity{initial_capacity}, | 22 | : last_requested_size{initial_capacity}, buffer_capacity{initial_capacity}, |
| 23 | buffer{Common::make_unique_for_overwrite<T[]>(initial_capacity)} {} | 23 | buffer{Common::make_unique_for_overwrite<T[]>(initial_capacity)} {} |
| 24 | 24 | ||
| 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 | void resize(size_t size) { | 28 | void resize(size_t size) { |
| 29 | if (size > capacity) { | 29 | if (size > buffer_capacity) { |
| 30 | capacity = size; | 30 | buffer_capacity = size; |
| 31 | buffer = Common::make_unique_for_overwrite<T[]>(capacity); | 31 | buffer = Common::make_unique_for_overwrite<T[]>(buffer_capacity); |
| 32 | } | 32 | } |
| 33 | last_requested_size = size; | 33 | last_requested_size = size; |
| 34 | } | 34 | } |
| @@ -65,9 +65,13 @@ public: | |||
| 65 | return last_requested_size; | 65 | return last_requested_size; |
| 66 | } | 66 | } |
| 67 | 67 | ||
| 68 | [[nodiscard]] size_t capacity() const noexcept { | ||
| 69 | return buffer_capacity; | ||
| 70 | } | ||
| 71 | |||
| 68 | private: | 72 | private: |
| 69 | size_t last_requested_size{}; | 73 | size_t last_requested_size{}; |
| 70 | size_t capacity{}; | 74 | size_t buffer_capacity{}; |
| 71 | std::unique_ptr<T[]> buffer{}; | 75 | std::unique_ptr<T[]> buffer{}; |
| 72 | }; | 76 | }; |
| 73 | 77 | ||