mirror of
https://github.com/citra-emu/citra.git
synced 2024-12-18 15:00:04 +00:00
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:
parent
af45f2b2de
commit
370d77f13a
@ -76,7 +76,7 @@ ResultVal<std::unique_ptr<FileBackend>> NCCHArchive::OpenFile(const Path& path,
|
||||
u64 romfs_size = 0;
|
||||
|
||||
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 ||
|
||||
filepath_type == NCCHFilePathType::ExeFS) {
|
||||
std::vector<u8> buffer;
|
||||
|
@ -3,6 +3,7 @@
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include <tuple>
|
||||
#include <utility>
|
||||
#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<std::tuple<MediaType, u64>> ParsePathGeneral(const Path& path) {
|
||||
|
||||
ArchiveFactory_OtherSaveDataPermitted::ArchiveFactory_OtherSaveDataPermitted(
|
||||
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(
|
||||
const Path& path) {
|
||||
@ -98,7 +99,7 @@ ResultVal<ArchiveFormatInfo> ArchiveFactory_OtherSaveDataPermitted::GetFormatInf
|
||||
|
||||
ArchiveFactory_OtherSaveDataGeneral::ArchiveFactory_OtherSaveDataGeneral(
|
||||
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(
|
||||
const Path& path) {
|
||||
|
@ -2,6 +2,7 @@
|
||||
// Licensed under GPLv2 or any later version
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include <utility>
|
||||
#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<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) {
|
||||
return sd_savedata_source->Open(Kernel::g_current_process->codeset->program_id);
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#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<FileUtil::IOFile> 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<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 {
|
||||
LOG_TRACE(Service_FS, "called offset=%llu, length=%zu", offset, length);
|
||||
romfs_file->Seek(data_offset + offset, SEEK_SET);
|
||||
|
@ -7,7 +7,6 @@
|
||||
#include <cstddef>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#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<FileUtil::IOFile> file, u64 offset, u64 size)
|
||||
: romfs_file(file), data_offset(offset), data_size(size) {}
|
||||
IVFCArchive(std::shared_ptr<FileUtil::IOFile> file, u64 offset, u64 size);
|
||||
|
||||
std::string GetName() const override;
|
||||
|
||||
@ -52,8 +50,7 @@ protected:
|
||||
|
||||
class IVFCFile : public FileBackend {
|
||||
public:
|
||||
IVFCFile(std::shared_ptr<FileUtil::IOFile> file, u64 offset, u64 size)
|
||||
: romfs_file(file), data_offset(offset), data_size(size) {}
|
||||
IVFCFile(std::shared_ptr<FileUtil::IOFile> file, u64 offset, u64 size);
|
||||
|
||||
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;
|
||||
|
Loading…
Reference in New Issue
Block a user