diff options
| author | lizzie <lizzie@eden-emu.dev> | 2026-09-25 07:54:49 +0200 |
|---|---|---|
| committer | crueter <crueter@eden-emu.dev> | 2026-09-25 07:54:49 +0200 |
| commit | bebc19da3253f13ceb5abfe8560cdbdc32ea7d8a (patch) | |
| tree | 3119f32d2873ee0d00ebde7208939045d1edb9dd /src | |
| parent | 99bf8cf51afb7b367cb5003f11a797499c71d13c (diff) | |
[common] Use `std::make_unique_for_overwrite<T>` 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 <lizzie@eden-emu.dev>
- [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 <maranbr@eden-emu.dev>
Reviewed-by: CamilleLaVey <camillelavey99@gmail.com>
Diffstat (limited to 'src')
| -rw-r--r-- | src/common/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | src/common/make_unique_for_overwrite.h | 27 | ||||
| -rw-r--r-- | src/common/scratch_buffer.h | 12 | ||||
| -rw-r--r-- | src/core/file_sys/vfs/vfs_real.cpp | 7 | ||||
| -rw-r--r-- | src/core/file_sys/vfs/vfs_real.h | 11 | ||||
| -rw-r--r-- | src/core/hle/service/psc/ovln/receiver_service.cpp | 4 |
6 files changed, 16 insertions, 46 deletions
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 <memory> -#include <type_traits> - -namespace Common { - -template <class T> - requires(!std::is_array_v<T>) -std::unique_ptr<T> make_unique_for_overwrite() { - return std::unique_ptr<T>(new T); -} - -template <class T> - requires std::is_unbounded_array_v<T> -std::unique_ptr<T> make_unique_for_overwrite(std::size_t n) { - return std::unique_ptr<T>(new std::remove_extent_t<T>[n]); -} - -template <class T, class... Args> - requires std::is_bounded_array_v<T> -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 <iterator> #include <cstring> - -#include "common/make_unique_for_overwrite.h" +#include <memory> 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<T[]>(initial_capacity)} {} + : last_requested_size{initial_capacity} + , buffer_capacity{initial_capacity} + , buffer{std::make_unique_for_overwrite<T[]>(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<T[]>(size); + auto new_buffer = std::make_unique_for_overwrite<T[]>(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<T[]>(buffer_capacity); + buffer = std::make_unique_for_overwrite<T[]>(buffer_capacity); } last_requested_size = size; } diff --git a/src/core/file_sys/vfs/vfs_real.cpp b/src/core/file_sys/vfs/vfs_real.cpp index b04f832cd3..14e0caad3c 100644 --- a/src/core/file_sys/vfs/vfs_real.cpp +++ b/src/core/file_sys/vfs/vfs_real.cpp @@ -109,8 +109,7 @@ VirtualFile RealVfsFilesystem::OpenFileFromEntry(std::string_view path_, std::op auto reference = std::make_unique<FileReference>(); this->InsertReferenceIntoListLocked(*reference); - auto file = std::shared_ptr<RealVfsFile>( - new RealVfsFile(*this, std::move(reference), path, perms, size, std::move(parent_path))); + auto file = std::make_shared<RealVfsFile>(*this, std::move(reference), path, perms, size, std::move(parent_path)); cache[path] = file; return file; @@ -177,7 +176,7 @@ bool RealVfsFilesystem::DeleteFile(std::string_view path_) { VirtualDir RealVfsFilesystem::OpenDirectory(std::string_view path_, OpenMode perms) { const auto path = FS::SanitizePath(path_, FS::DirectorySeparator::PlatformDefault); - return std::shared_ptr<RealVfsDirectory>(new RealVfsDirectory(*this, path, perms)); + return std::make_shared<RealVfsDirectory>(*this, path, perms); } VirtualDir RealVfsFilesystem::CreateDirectory(std::string_view path_, OpenMode perms) { @@ -185,7 +184,7 @@ VirtualDir RealVfsFilesystem::CreateDirectory(std::string_view path_, OpenMode p if (!FS::CreateDirs(path)) { return nullptr; } - return std::shared_ptr<RealVfsDirectory>(new RealVfsDirectory(*this, path, perms)); + return std::make_shared<RealVfsDirectory>(*this, path, perms); } VirtualDir RealVfsFilesystem::CopyDirectory(std::string_view old_path_, diff --git a/src/core/file_sys/vfs/vfs_real.h b/src/core/file_sys/vfs/vfs_real.h index 672126d7ba..a97f7d32ea 100644 --- a/src/core/file_sys/vfs/vfs_real.h +++ b/src/core/file_sys/vfs/vfs_real.h @@ -82,6 +82,9 @@ class RealVfsFile : public VfsFile { friend class RealVfsFilesystem; public: + RealVfsFile(RealVfsFilesystem& base, std::unique_ptr<FileReference> reference, + const std::string& path, OpenMode perms = OpenMode::Read, + std::optional<u64> size = {}, std::optional<std::string> parent_path = {}); ~RealVfsFile() override; std::string GetName() const override; @@ -95,9 +98,6 @@ public: bool Rename(std::string_view name) override; private: - RealVfsFile(RealVfsFilesystem& base, std::unique_ptr<FileReference> reference, - const std::string& path, OpenMode perms = OpenMode::Read, - std::optional<u64> size = {}, std::optional<std::string> parent_path = {}); RealVfsFilesystem& base; std::unique_ptr<FileReference> reference; @@ -113,6 +113,8 @@ class RealVfsDirectory : public VfsDirectory { friend class RealVfsFilesystem; public: + RealVfsDirectory(RealVfsFilesystem& base, const std::string& path, + OpenMode perms = OpenMode::Read); ~RealVfsDirectory() override; VirtualFile GetFileRelative(std::string_view relative_path) const override; @@ -138,9 +140,6 @@ public: std::map<std::string, VfsEntryType, std::less<>> GetEntries() const override; private: - RealVfsDirectory(RealVfsFilesystem& base, const std::string& path, - OpenMode perms = OpenMode::Read); - template <typename T, typename R> std::vector<std::shared_ptr<R>> IterateEntries() const; diff --git a/src/core/hle/service/psc/ovln/receiver_service.cpp b/src/core/hle/service/psc/ovln/receiver_service.cpp index d869325181..3b0b180725 100644 --- a/src/core/hle/service/psc/ovln/receiver_service.cpp +++ b/src/core/hle/service/psc/ovln/receiver_service.cpp @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project +// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project // SPDX-License-Identifier: GPL-3.0-or-later // SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project @@ -24,7 +24,7 @@ IReceiverService::~IReceiverService() = default; Result IReceiverService::OpenReceiver(Out<SharedPointer<IReceiver>> out_receiver) { LOG_DEBUG(Service_PSC, "called"); - *out_receiver = std::shared_ptr<IReceiver>(new IReceiver(system)); + *out_receiver = std::make_shared<IReceiver>(system); R_SUCCEED(); } |
