From 370d77f13a2af4ddee48c0d74418ea732799f7d5 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sat, 9 Dec 2017 14:12:04 -0500 Subject: [PATCH] file_sys: std::move std::shared_ptr instances in constructors where applicable By default, a regular copy requires an atomic increment and decrement. A move avoids this from occurring, which makes sense when the constructor is taking the shared_ptr by value. --- src/core/file_sys/archive_ncch.cpp | 2 +- src/core/file_sys/archive_other_savedata.cpp | 5 +++-- src/core/file_sys/archive_savedata.cpp | 3 ++- src/core/file_sys/ivfc_archive.cpp | 7 +++++++ src/core/file_sys/ivfc_archive.h | 7 ++----- 5 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/core/file_sys/archive_ncch.cpp b/src/core/file_sys/archive_ncch.cpp index 07d7967d9..24b0f504b 100644 --- a/src/core/file_sys/archive_ncch.cpp +++ b/src/core/file_sys/archive_ncch.cpp @@ -76,7 +76,7 @@ ResultVal> NCCHArchive::OpenFile(const Path& path, u64 romfs_size = 0; result = ncch_container.ReadRomFS(romfs_file, romfs_offset, romfs_size); - file = std::make_unique(romfs_file, romfs_offset, romfs_size); + file = std::make_unique(std::move(romfs_file), romfs_offset, romfs_size); } else if (filepath_type == NCCHFilePathType::Code || filepath_type == NCCHFilePathType::ExeFS) { std::vector buffer; diff --git a/src/core/file_sys/archive_other_savedata.cpp b/src/core/file_sys/archive_other_savedata.cpp index d3cf080da..1977585b5 100644 --- a/src/core/file_sys/archive_other_savedata.cpp +++ b/src/core/file_sys/archive_other_savedata.cpp @@ -3,6 +3,7 @@ // Refer to the license.txt file included. #include +#include #include "core/file_sys/archive_other_savedata.h" #include "core/file_sys/errors.h" #include "core/hle/kernel/process.h" @@ -60,7 +61,7 @@ ResultVal> ParsePathGeneral(const Path& path) { ArchiveFactory_OtherSaveDataPermitted::ArchiveFactory_OtherSaveDataPermitted( std::shared_ptr sd_savedata) - : sd_savedata_source(sd_savedata) {} + : sd_savedata_source(std::move(sd_savedata)) {} ResultVal> ArchiveFactory_OtherSaveDataPermitted::Open( const Path& path) { @@ -98,7 +99,7 @@ ResultVal ArchiveFactory_OtherSaveDataPermitted::GetFormatInf ArchiveFactory_OtherSaveDataGeneral::ArchiveFactory_OtherSaveDataGeneral( std::shared_ptr sd_savedata) - : sd_savedata_source(sd_savedata) {} + : sd_savedata_source(std::move(sd_savedata)) {} ResultVal> ArchiveFactory_OtherSaveDataGeneral::Open( const Path& path) { diff --git a/src/core/file_sys/archive_savedata.cpp b/src/core/file_sys/archive_savedata.cpp index 61f7654f7..d551f590f 100644 --- a/src/core/file_sys/archive_savedata.cpp +++ b/src/core/file_sys/archive_savedata.cpp @@ -2,6 +2,7 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. +#include #include "core/file_sys/archive_savedata.h" #include "core/hle/kernel/process.h" @@ -12,7 +13,7 @@ namespace FileSys { ArchiveFactory_SaveData::ArchiveFactory_SaveData( std::shared_ptr sd_savedata) - : sd_savedata_source(sd_savedata) {} + : sd_savedata_source(std::move(sd_savedata)) {} ResultVal> ArchiveFactory_SaveData::Open(const Path& path) { return sd_savedata_source->Open(Kernel::g_current_process->codeset->program_id); diff --git a/src/core/file_sys/ivfc_archive.cpp b/src/core/file_sys/ivfc_archive.cpp index 07dcf010d..7cd09ed07 100644 --- a/src/core/file_sys/ivfc_archive.cpp +++ b/src/core/file_sys/ivfc_archive.cpp @@ -4,6 +4,7 @@ #include #include +#include #include "common/common_types.h" #include "common/logging/log.h" #include "core/file_sys/ivfc_archive.h" @@ -13,6 +14,9 @@ namespace FileSys { +IVFCArchive::IVFCArchive(std::shared_ptr file, u64 offset, u64 size) + : romfs_file(std::move(file)), data_offset(offset), data_size(size) {} + std::string IVFCArchive::GetName() const { return "IVFC"; } @@ -85,6 +89,9 @@ u64 IVFCArchive::GetFreeBytes() const { //////////////////////////////////////////////////////////////////////////////////////////////////// +IVFCFile::IVFCFile(std::shared_ptr file, u64 offset, u64 size) + : romfs_file(std::move(file)), data_offset(offset), data_size(size) {} + ResultVal IVFCFile::Read(const u64 offset, const size_t length, u8* buffer) const { LOG_TRACE(Service_FS, "called offset=%llu, length=%zu", offset, length); romfs_file->Seek(data_offset + offset, SEEK_SET); diff --git a/src/core/file_sys/ivfc_archive.h b/src/core/file_sys/ivfc_archive.h index 53a2637a6..768084036 100644 --- a/src/core/file_sys/ivfc_archive.h +++ b/src/core/file_sys/ivfc_archive.h @@ -7,7 +7,6 @@ #include #include #include -#include #include "common/common_types.h" #include "common/file_util.h" #include "core/file_sys/archive_backend.h" @@ -27,8 +26,7 @@ namespace FileSys { */ class IVFCArchive : public ArchiveBackend { public: - IVFCArchive(std::shared_ptr file, u64 offset, u64 size) - : romfs_file(file), data_offset(offset), data_size(size) {} + IVFCArchive(std::shared_ptr file, u64 offset, u64 size); std::string GetName() const override; @@ -52,8 +50,7 @@ protected: class IVFCFile : public FileBackend { public: - IVFCFile(std::shared_ptr file, u64 offset, u64 size) - : romfs_file(file), data_offset(offset), data_size(size) {} + IVFCFile(std::shared_ptr file, u64 offset, u64 size); ResultVal Read(u64 offset, size_t length, u8* buffer) const override; ResultVal Write(u64 offset, size_t length, bool flush, const u8* buffer) override;