fs_user: std::move vectors where applicable

Allows removing some allocation churn in some locations by moving
std::vectors into Path where applicable.
This commit is contained in:
Lioncash 2020-05-04 11:48:04 -04:00
parent 36809b2e2e
commit ba2ae9616a
8 changed files with 73 additions and 72 deletions

View file

@ -12,10 +12,10 @@
namespace FileSys {
Path::Path(LowPathType type, const std::vector<u8>& data) : type(type) {
Path::Path(LowPathType type, std::vector<u8> data) : type(type) {
switch (type) {
case LowPathType::Binary: {
binary = data;
binary = std::move(data);
break;
}

View file

@ -45,7 +45,7 @@ public:
template <std::size_t size>
Path(const std::array<u8, size>& binary_data)
: type(LowPathType::Binary), binary(binary_data.begin(), binary_data.end()) {}
Path(LowPathType type, const std::vector<u8>& data);
Path(LowPathType type, std::vector<u8> data);
LowPathType GetType() const {
return type;

View file

@ -56,8 +56,8 @@ Path MakeNCCHArchivePath(u64 tid, Service::FS::MediaType media_type) {
path.media_type = static_cast<u32_le>(media_type);
path.unknown = 0;
std::vector<u8> archive(sizeof(path));
std::memcpy(&archive[0], &path, sizeof(path));
return FileSys::Path(archive);
std::memcpy(archive.data(), &path, sizeof(path));
return FileSys::Path(std::move(archive));
}
Path MakeNCCHFilePath(NCCHFileOpenType open_type, u32 content_index, NCCHFilePathType filepath_type,
@ -68,8 +68,8 @@ Path MakeNCCHFilePath(NCCHFileOpenType open_type, u32 content_index, NCCHFilePat
path.filepath_type = filepath_type;
path.exefs_filepath = exefs_filepath;
std::vector<u8> file(sizeof(path));
std::memcpy(&file[0], &path, sizeof(path));
return FileSys::Path(file);
std::memcpy(file.data(), &path, sizeof(path));
return FileSys::Path(std::move(file));
}
ResultVal<std::unique_ptr<FileBackend>> NCCHArchive::OpenFile(const Path& path,

View file

@ -49,7 +49,7 @@ Path ConstructSystemSaveDataBinaryPath(u32 high, u32 low) {
for (unsigned i = 0; i < 4; ++i)
binary_path.push_back((low >> (8 * i)) & 0xFF);
return {binary_path};
return {std::move(binary_path)};
}
ArchiveFactory_SystemSaveData::ArchiveFactory_SystemSaveData(const std::string& nand_path)