From bebc19da3253f13ceb5abfe8560cdbdc32ea7d8a Mon Sep 17 00:00:00 2001 From: lizzie Date: Fri, 25 Sep 2026 07:54:49 +0200 Subject: [common] Use `std::make_unique_for_overwrite` in ScratchBuffer, remove polyfill (#4432) Original `make_unique_for_overwrite.h` is well defined acc. to standard https://en.cppreference.com/cpp/memory/unique_ptr/make_unique, but by now most libc++ supports the function, so no need for polyfill. Test that this didn't break anything (for example, Megaman game that has video at the start), or anything using VIC/IPC. Signed-off-by: lizzie - [x] I have read and followed the [Contribution Guidelines](https://git.eden-emu.dev/eden-emu/eden/src/branch/master/CONTRIBUTING.md#code-contributions). - [x] I have read and followed the [AI Policy](https://git.eden-emu.dev/eden-emu/eden/src/branch/master/docs/policies/AI.md) - [x] I have read and followed the [Coding Guidelines](https://git.eden-emu.dev/eden-emu/eden/src/branch/master/docs/policies/Coding.md) to the best of my ability. ------------------- Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/4432 Reviewed-by: MaranBr Reviewed-by: CamilleLaVey --- src/common/CMakeLists.txt | 1 - src/common/make_unique_for_overwrite.h | 27 --------------------------- src/common/scratch_buffer.h | 12 ++++++------ 3 files changed, 6 insertions(+), 34 deletions(-) delete mode 100644 src/common/make_unique_for_overwrite.h (limited to 'src/common') diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 94da1724df..0517f0b9e1 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -76,7 +76,6 @@ add_library( logging.h lz4_compression.cpp lz4_compression.h - make_unique_for_overwrite.h math_util.h memory_detect.cpp memory_detect.h diff --git a/src/common/make_unique_for_overwrite.h b/src/common/make_unique_for_overwrite.h deleted file mode 100644 index 17f81bba4a..0000000000 --- a/src/common/make_unique_for_overwrite.h +++ /dev/null @@ -1,27 +0,0 @@ -// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project -// SPDX-License-Identifier: GPL-2.0-or-later - -#pragma once - -#include -#include - -namespace Common { - -template - requires(!std::is_array_v) -std::unique_ptr make_unique_for_overwrite() { - return std::unique_ptr(new T); -} - -template - requires std::is_unbounded_array_v -std::unique_ptr make_unique_for_overwrite(std::size_t n) { - return std::unique_ptr(new std::remove_extent_t[n]); -} - -template - requires std::is_bounded_array_v -void make_unique_for_overwrite(Args&&...) = delete; - -} // namespace Common diff --git a/src/common/scratch_buffer.h b/src/common/scratch_buffer.h index 8c1f566301..929a65609a 100644 --- a/src/common/scratch_buffer.h +++ b/src/common/scratch_buffer.h @@ -8,8 +8,7 @@ #include #include - -#include "common/make_unique_for_overwrite.h" +#include namespace Common { @@ -38,8 +37,9 @@ public: ScratchBuffer() = default; explicit ScratchBuffer(size_type initial_capacity) - : last_requested_size{initial_capacity}, buffer_capacity{initial_capacity}, - buffer{Common::make_unique_for_overwrite(initial_capacity)} {} + : last_requested_size{initial_capacity} + , buffer_capacity{initial_capacity} + , buffer{std::make_unique_for_overwrite(initial_capacity)} {} ~ScratchBuffer() = default; ScratchBuffer(const ScratchBuffer&) = delete; @@ -64,7 +64,7 @@ public: /// The previously held data will remain intact. void resize(size_type size) { if (size > buffer_capacity) { - auto new_buffer = Common::make_unique_for_overwrite(size); + auto new_buffer = std::make_unique_for_overwrite(size); std::memcpy(new_buffer.get(), buffer.get(), buffer_capacity * sizeof(T)); buffer = std::move(new_buffer); buffer_capacity = size; @@ -77,7 +77,7 @@ public: void resize_destructive(size_type size) { if (size > buffer_capacity) { buffer_capacity = size; - buffer = Common::make_unique_for_overwrite(buffer_capacity); + buffer = std::make_unique_for_overwrite(buffer_capacity); } last_requested_size = size; } -- cgit v1.2.3