citra-emu
/
citra
Archived
1
0
Fork 0

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.
This commit is contained in:
Lioncash 2017-12-09 14:12:04 -05:00
parent af45f2b2de
commit 370d77f13a
5 changed files with 15 additions and 9 deletions

View File

@ -76,7 +76,7 @@ ResultVal<std::unique_ptr<FileBackend>> NCCHArchive::OpenFile(const Path& path,
u64 romfs_size = 0; u64 romfs_size = 0;
result = ncch_container.ReadRomFS(romfs_file, romfs_offset, romfs_size); result = ncch_container.ReadRomFS(romfs_file, romfs_offset, romfs_size);
file = std::make_unique<IVFCFile>(romfs_file, romfs_offset, romfs_size); file = std::make_unique<IVFCFile>(std::move(romfs_file), romfs_offset, romfs_size);
} else if (filepath_type == NCCHFilePathType::Code || } else if (filepath_type == NCCHFilePathType::Code ||
filepath_type == NCCHFilePathType::ExeFS) { filepath_type == NCCHFilePathType::ExeFS) {
std::vector<u8> buffer; std::vector<u8> buffer;

View File

@ -3,6 +3,7 @@
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include <tuple> #include <tuple>
#include <utility>
#include "core/file_sys/archive_other_savedata.h" #include "core/file_sys/archive_other_savedata.h"
#include "core/file_sys/errors.h" #include "core/file_sys/errors.h"
#include "core/hle/kernel/process.h" #include "core/hle/kernel/process.h"
@ -60,7 +61,7 @@ ResultVal<std::tuple<MediaType, u64>> ParsePathGeneral(const Path& path) {
ArchiveFactory_OtherSaveDataPermitted::ArchiveFactory_OtherSaveDataPermitted( ArchiveFactory_OtherSaveDataPermitted::ArchiveFactory_OtherSaveDataPermitted(
std::shared_ptr<ArchiveSource_SDSaveData> sd_savedata) std::shared_ptr<ArchiveSource_SDSaveData> sd_savedata)
: sd_savedata_source(sd_savedata) {} : sd_savedata_source(std::move(sd_savedata)) {}
ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_OtherSaveDataPermitted::Open( ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_OtherSaveDataPermitted::Open(
const Path& path) { const Path& path) {
@ -98,7 +99,7 @@ ResultVal<ArchiveFormatInfo> ArchiveFactory_OtherSaveDataPermitted::GetFormatInf
ArchiveFactory_OtherSaveDataGeneral::ArchiveFactory_OtherSaveDataGeneral( ArchiveFactory_OtherSaveDataGeneral::ArchiveFactory_OtherSaveDataGeneral(
std::shared_ptr<ArchiveSource_SDSaveData> sd_savedata) std::shared_ptr<ArchiveSource_SDSaveData> sd_savedata)
: sd_savedata_source(sd_savedata) {} : sd_savedata_source(std::move(sd_savedata)) {}
ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_OtherSaveDataGeneral::Open( ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_OtherSaveDataGeneral::Open(
const Path& path) { const Path& path) {

View File

@ -2,6 +2,7 @@
// Licensed under GPLv2 or any later version // Licensed under GPLv2 or any later version
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include <utility>
#include "core/file_sys/archive_savedata.h" #include "core/file_sys/archive_savedata.h"
#include "core/hle/kernel/process.h" #include "core/hle/kernel/process.h"
@ -12,7 +13,7 @@ namespace FileSys {
ArchiveFactory_SaveData::ArchiveFactory_SaveData( ArchiveFactory_SaveData::ArchiveFactory_SaveData(
std::shared_ptr<ArchiveSource_SDSaveData> sd_savedata) std::shared_ptr<ArchiveSource_SDSaveData> sd_savedata)
: sd_savedata_source(sd_savedata) {} : sd_savedata_source(std::move(sd_savedata)) {}
ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_SaveData::Open(const Path& path) { ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_SaveData::Open(const Path& path) {
return sd_savedata_source->Open(Kernel::g_current_process->codeset->program_id); return sd_savedata_source->Open(Kernel::g_current_process->codeset->program_id);

View File

@ -4,6 +4,7 @@
#include <cstring> #include <cstring>
#include <memory> #include <memory>
#include <utility>
#include "common/common_types.h" #include "common/common_types.h"
#include "common/logging/log.h" #include "common/logging/log.h"
#include "core/file_sys/ivfc_archive.h" #include "core/file_sys/ivfc_archive.h"
@ -13,6 +14,9 @@
namespace FileSys { namespace FileSys {
IVFCArchive::IVFCArchive(std::shared_ptr<FileUtil::IOFile> file, u64 offset, u64 size)
: romfs_file(std::move(file)), data_offset(offset), data_size(size) {}
std::string IVFCArchive::GetName() const { std::string IVFCArchive::GetName() const {
return "IVFC"; return "IVFC";
} }
@ -85,6 +89,9 @@ u64 IVFCArchive::GetFreeBytes() const {
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
IVFCFile::IVFCFile(std::shared_ptr<FileUtil::IOFile> file, u64 offset, u64 size)
: romfs_file(std::move(file)), data_offset(offset), data_size(size) {}
ResultVal<size_t> IVFCFile::Read(const u64 offset, const size_t length, u8* buffer) const { ResultVal<size_t> IVFCFile::Read(const u64 offset, const size_t length, u8* buffer) const {
LOG_TRACE(Service_FS, "called offset=%llu, length=%zu", offset, length); LOG_TRACE(Service_FS, "called offset=%llu, length=%zu", offset, length);
romfs_file->Seek(data_offset + offset, SEEK_SET); romfs_file->Seek(data_offset + offset, SEEK_SET);

View File

@ -7,7 +7,6 @@
#include <cstddef> #include <cstddef>
#include <memory> #include <memory>
#include <string> #include <string>
#include <vector>
#include "common/common_types.h" #include "common/common_types.h"
#include "common/file_util.h" #include "common/file_util.h"
#include "core/file_sys/archive_backend.h" #include "core/file_sys/archive_backend.h"
@ -27,8 +26,7 @@ namespace FileSys {
*/ */
class IVFCArchive : public ArchiveBackend { class IVFCArchive : public ArchiveBackend {
public: public:
IVFCArchive(std::shared_ptr<FileUtil::IOFile> file, u64 offset, u64 size) IVFCArchive(std::shared_ptr<FileUtil::IOFile> file, u64 offset, u64 size);
: romfs_file(file), data_offset(offset), data_size(size) {}
std::string GetName() const override; std::string GetName() const override;
@ -52,8 +50,7 @@ protected:
class IVFCFile : public FileBackend { class IVFCFile : public FileBackend {
public: public:
IVFCFile(std::shared_ptr<FileUtil::IOFile> file, u64 offset, u64 size) IVFCFile(std::shared_ptr<FileUtil::IOFile> file, u64 offset, u64 size);
: romfs_file(file), data_offset(offset), data_size(size) {}
ResultVal<size_t> Read(u64 offset, size_t length, u8* buffer) const override; ResultVal<size_t> Read(u64 offset, size_t length, u8* buffer) const override;
ResultVal<size_t> Write(u64 offset, size_t length, bool flush, const u8* buffer) override; ResultVal<size_t> Write(u64 offset, size_t length, bool flush, const u8* buffer) override;