From 861279d3989c4a9a8dbedf3a1d14f17fc1aa84fd Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Sat, 7 Mar 2020 21:20:06 -0800 Subject: [PATCH] fs: prefer make_unique to operator new --- .../include/stratosphere/fs/fs_remote_filesystem.hpp | 4 ++-- libraries/libstratosphere/source/fs/fs_bis.cpp | 6 +++--- libraries/libstratosphere/source/fs/fs_code.cpp | 2 +- libraries/libstratosphere/source/fs/fs_content.cpp | 2 +- libraries/libstratosphere/source/fs/fs_content_storage.cpp | 4 ++-- libraries/libstratosphere/source/fs/fs_data.cpp | 4 ++-- libraries/libstratosphere/source/fs/fs_game_card.cpp | 4 ++-- libraries/libstratosphere/source/fs/fs_romfs_filesystem.cpp | 4 ++-- libraries/libstratosphere/source/fs/fs_sd_card.cpp | 2 +- libraries/libstratosphere/source/fs/fs_system_save_data.cpp | 2 +- libraries/libstratosphere/source/fs/fsa/fs_registrar.cpp | 6 +++--- .../libstratosphere/source/fs/fsa/fs_user_filesystem.cpp | 2 +- 12 files changed, 21 insertions(+), 21 deletions(-) diff --git a/libraries/libstratosphere/include/stratosphere/fs/fs_remote_filesystem.hpp b/libraries/libstratosphere/include/stratosphere/fs/fs_remote_filesystem.hpp index 7ead1606e..824fc8432 100644 --- a/libraries/libstratosphere/include/stratosphere/fs/fs_remote_filesystem.hpp +++ b/libraries/libstratosphere/include/stratosphere/fs/fs_remote_filesystem.hpp @@ -170,7 +170,7 @@ namespace ams::fs { FsFile f; R_TRY(fsFsOpenFile(std::addressof(this->base_fs), sf_path.str, mode, &f)); - std::unique_ptr file(new RemoteFile(f)); + auto file = std::make_unique(f); R_UNLESS(file != nullptr, fs::ResultAllocationFailureInNew()); *out_file = std::move(file); @@ -184,7 +184,7 @@ namespace ams::fs { FsDir d; R_TRY(fsFsOpenDirectory(std::addressof(this->base_fs), sf_path.str, mode, &d)); - std::unique_ptr dir(new RemoteDirectory(d)); + auto dir = std::make_unique(d); R_UNLESS(dir != nullptr, fs::ResultAllocationFailureInNew()); *out_dir = std::move(dir); diff --git a/libraries/libstratosphere/source/fs/fs_bis.cpp b/libraries/libstratosphere/source/fs/fs_bis.cpp index b906be79d..a90ee12b8 100644 --- a/libraries/libstratosphere/source/fs/fs_bis.cpp +++ b/libraries/libstratosphere/source/fs/fs_bis.cpp @@ -54,11 +54,11 @@ namespace ams::fs { R_TRY(fsOpenBisFileSystem(std::addressof(fs), static_cast<::FsBisPartitionId>(id), "")); /* Allocate a new mountname generator. */ - std::unique_ptr generator(new BisCommonMountNameGenerator(id)); + auto generator = std::make_unique(id); R_UNLESS(generator != nullptr, fs::ResultAllocationFailureInBisA()); /* Allocate a new filesystem wrapper. */ - std::unique_ptr fsa(new RemoteFileSystem(fs)); + auto fsa = std::make_unique(fs); R_UNLESS(fsa != nullptr, fs::ResultAllocationFailureInBisB()); /* Register. */ @@ -112,7 +112,7 @@ namespace ams::fs { R_TRY(fsOpenBisStorage(std::addressof(s), static_cast<::FsBisPartitionId>(id))); /* Allocate a new storage wrapper. */ - std::unique_ptr storage(new RemoteStorage(s)); + auto storage = std::make_unique(s); R_UNLESS(storage != nullptr, fs::ResultAllocationFailureInBisC()); *out = std::move(storage); diff --git a/libraries/libstratosphere/source/fs/fs_code.cpp b/libraries/libstratosphere/source/fs/fs_code.cpp index 51cb20b72..83e9b5c5d 100644 --- a/libraries/libstratosphere/source/fs/fs_code.cpp +++ b/libraries/libstratosphere/source/fs/fs_code.cpp @@ -34,7 +34,7 @@ namespace ams::fs { R_TRY(fsldrOpenCodeFileSystem(program_id.value, sf_path.str, std::addressof(fs))); /* Allocate a new filesystem wrapper. */ - std::unique_ptr fsa(new RemoteFileSystem(fs)); + auto fsa = std::make_unique(fs); R_UNLESS(fsa != nullptr, fs::ResultAllocationFailureInCodeA()); /* Register. */ diff --git a/libraries/libstratosphere/source/fs/fs_content.cpp b/libraries/libstratosphere/source/fs/fs_content.cpp index d4abe6170..fc14c9602 100644 --- a/libraries/libstratosphere/source/fs/fs_content.cpp +++ b/libraries/libstratosphere/source/fs/fs_content.cpp @@ -36,7 +36,7 @@ namespace ams::fs { R_TRY(fsOpenFileSystemWithId(std::addressof(fs), id, static_cast<::FsFileSystemType>(type), path)); /* Allocate a new filesystem wrapper. */ - std::unique_ptr fsa(new RemoteFileSystem(fs)); + auto fsa = std::make_unique(fs); R_UNLESS(fsa != nullptr, fs::ResultAllocationFailureInContentA()); /* Register. */ diff --git a/libraries/libstratosphere/source/fs/fs_content_storage.cpp b/libraries/libstratosphere/source/fs/fs_content_storage.cpp index 59147333b..5e778eb3c 100644 --- a/libraries/libstratosphere/source/fs/fs_content_storage.cpp +++ b/libraries/libstratosphere/source/fs/fs_content_storage.cpp @@ -79,11 +79,11 @@ namespace ams::fs { } /* Allocate a new filesystem wrapper. */ - std::unique_ptr fsa(new RemoteFileSystem(fs)); + auto fsa = std::make_unique(fs); R_UNLESS(fsa != nullptr, fs::ResultAllocationFailureInContentStorageA()); /* Allocate a new mountname generator. */ - std::unique_ptr generator(new ContentStorageCommonMountNameGenerator(id)); + auto generator = std::make_unique(id); R_UNLESS(generator != nullptr, fs::ResultAllocationFailureInContentStorageB()); /* Register. */ diff --git a/libraries/libstratosphere/source/fs/fs_data.cpp b/libraries/libstratosphere/source/fs/fs_data.cpp index 4d7135b34..150097d67 100644 --- a/libraries/libstratosphere/source/fs/fs_data.cpp +++ b/libraries/libstratosphere/source/fs/fs_data.cpp @@ -27,7 +27,7 @@ namespace ams::fs::impl { R_CONVERT(ncm::ResultContentMetaNotFound, fs::ResultTargetNotFound()); } R_END_TRY_CATCH; - std::unique_ptr storage(new RemoteStorage(s)); + auto storage = std::make_unique(s); R_UNLESS(storage != nullptr, fs::ResultAllocationFailureInDataA()); *out = std::move(storage); @@ -38,7 +38,7 @@ namespace ams::fs::impl { std::unique_ptr storage; R_TRY(OpenDataStorageByDataId(std::addressof(storage), data_id, storage_id)); - std::unique_ptr fs(new RomFsFileSystem()); + auto fs = std::make_unique(); R_UNLESS(fs != nullptr, fs::ResultAllocationFailureInDataB()); R_TRY(fs->Initialize(std::move(storage), cache_buffer, cache_size, use_cache)); diff --git a/libraries/libstratosphere/source/fs/fs_game_card.cpp b/libraries/libstratosphere/source/fs/fs_game_card.cpp index 97c5ddb4a..d2ac95235 100644 --- a/libraries/libstratosphere/source/fs/fs_game_card.cpp +++ b/libraries/libstratosphere/source/fs/fs_game_card.cpp @@ -73,11 +73,11 @@ namespace ams::fs { R_TRY(fsOpenGameCardFileSystem(std::addressof(fs), std::addressof(_hnd), static_cast<::FsGameCardPartition>(partition))); /* Allocate a new filesystem wrapper. */ - std::unique_ptr fsa(new RemoteFileSystem(fs)); + auto fsa = std::make_unique(fs); R_UNLESS(fsa != nullptr, fs::ResultAllocationFailureInGameCardC()); /* Allocate a new mountname generator. */ - std::unique_ptr generator(new GameCardCommonMountNameGenerator(handle, partition)); + auto generator = std::make_unique(handle, partition); R_UNLESS(generator != nullptr, fs::ResultAllocationFailureInGameCardD()); /* Register. */ diff --git a/libraries/libstratosphere/source/fs/fs_romfs_filesystem.cpp b/libraries/libstratosphere/source/fs/fs_romfs_filesystem.cpp index 78c22c7df..95b24835a 100644 --- a/libraries/libstratosphere/source/fs/fs_romfs_filesystem.cpp +++ b/libraries/libstratosphere/source/fs/fs_romfs_filesystem.cpp @@ -486,7 +486,7 @@ namespace ams::fs { RomFileTable::FileInfo file_info; R_TRY(this->GetFileInfo(std::addressof(file_info), path)); - std::unique_ptr file(new RomFsFile(this, this->entry_size + file_info.offset.Get(), this->entry_size + file_info.offset.Get() + file_info.size.Get())); + auto file = std::make_unique(this, this->entry_size + file_info.offset.Get(), this->entry_size + file_info.offset.Get() + file_info.size.Get()); R_UNLESS(file != nullptr, fs::ResultAllocationFailureInRomFsFileSystemB()); *out_file = std::move(file); @@ -503,7 +503,7 @@ namespace ams::fs { R_CONVERT(fs::ResultDbmInvalidOperation, fs::ResultPathNotFound()) } R_END_TRY_CATCH; - std::unique_ptr dir(new RomFsDirectory(this, find, mode)); + auto dir = std::make_unique(this, find, mode); R_UNLESS(dir != nullptr, fs::ResultAllocationFailureInRomFsFileSystemC()); *out_dir = std::move(dir); diff --git a/libraries/libstratosphere/source/fs/fs_sd_card.cpp b/libraries/libstratosphere/source/fs/fs_sd_card.cpp index cb20560da..04798db8a 100644 --- a/libraries/libstratosphere/source/fs/fs_sd_card.cpp +++ b/libraries/libstratosphere/source/fs/fs_sd_card.cpp @@ -27,7 +27,7 @@ namespace ams::fs { R_TRY(fsOpenSdCardFileSystem(std::addressof(fs))); /* Allocate a new filesystem wrapper. */ - std::unique_ptr fsa(new RemoteFileSystem(fs)); + auto fsa = std::make_unique(fs); R_UNLESS(fsa != nullptr, fs::ResultAllocationFailureInSdCardA()); /* Register. */ diff --git a/libraries/libstratosphere/source/fs/fs_system_save_data.cpp b/libraries/libstratosphere/source/fs/fs_system_save_data.cpp index c4802cbfe..89e888db3 100644 --- a/libraries/libstratosphere/source/fs/fs_system_save_data.cpp +++ b/libraries/libstratosphere/source/fs/fs_system_save_data.cpp @@ -33,7 +33,7 @@ namespace ams::fs { R_TRY(fsOpenSaveDataFileSystemBySystemSaveDataId(std::addressof(fs), static_cast<::FsSaveDataSpaceId>(space_id), reinterpret_cast(std::addressof(attribute)))); /* Allocate a new filesystem wrapper. */ - std::unique_ptr fsa(new RemoteFileSystem(fs)); + auto fsa = std::make_unique(fs); R_UNLESS(fsa != nullptr, fs::ResultAllocationFailureInSystemSaveDataA()); /* Register. */ diff --git a/libraries/libstratosphere/source/fs/fsa/fs_registrar.cpp b/libraries/libstratosphere/source/fs/fsa/fs_registrar.cpp index 43c4d843a..d416bfd69 100644 --- a/libraries/libstratosphere/source/fs/fsa/fs_registrar.cpp +++ b/libraries/libstratosphere/source/fs/fsa/fs_registrar.cpp @@ -20,21 +20,21 @@ namespace ams::fs::fsa { Result Register(const char *name, std::unique_ptr &&fs) { - std::unique_ptr accessor(new impl::FileSystemAccessor(name, std::move(fs))); + auto accessor = std::make_unique(name, std::move(fs)); R_UNLESS(accessor != nullptr, fs::ResultAllocationFailureInRegisterA()); return impl::Register(std::move(accessor)); } Result Register(const char *name, std::unique_ptr &&fs, std::unique_ptr &&generator) { - std::unique_ptr accessor(new impl::FileSystemAccessor(name, std::move(fs), std::move(generator))); + auto accessor = std::make_unique(name, std::move(fs), std::move(generator)); R_UNLESS(accessor != nullptr, fs::ResultAllocationFailureInRegisterB()); return impl::Register(std::move(accessor)); } Result Register(const char *name, std::unique_ptr &&fs, std::unique_ptr &&generator, bool use_data_cache, bool use_path_cache, bool support_multi_commit) { - std::unique_ptr accessor(new impl::FileSystemAccessor(name, std::move(fs), std::move(generator))); + auto accessor = std::make_unique(name, std::move(fs), std::move(generator)); R_UNLESS(accessor != nullptr, fs::ResultAllocationFailureInRegisterB()); accessor->SetFileDataCacheAttachable(use_data_cache); diff --git a/libraries/libstratosphere/source/fs/fsa/fs_user_filesystem.cpp b/libraries/libstratosphere/source/fs/fsa/fs_user_filesystem.cpp index 07129968e..b4c77cda7 100644 --- a/libraries/libstratosphere/source/fs/fsa/fs_user_filesystem.cpp +++ b/libraries/libstratosphere/source/fs/fsa/fs_user_filesystem.cpp @@ -169,7 +169,7 @@ namespace ams::fs { Result OpenFile(FileHandle *out, std::unique_ptr &&file, int mode) { R_UNLESS(out != nullptr, fs::ResultNullptrArgument()); - std::unique_ptr file_accessor(new impl::FileAccessor(std::move(file), nullptr, static_cast(mode))); + auto file_accessor = std::make_unique(std::move(file), nullptr, static_cast(mode)); R_UNLESS(file_accessor != nullptr, fs::ResultAllocationFailureInNew()); out->handle = file_accessor.release();