mirror of
https://github.com/Lime3DS/Lime3DS.git
synced 2024-11-27 12:04:16 +01:00
file_sys: std::move the vector in NCCHFile's constructor
Avoids making unnecessary copies of the source vector's data.
This commit is contained in:
parent
370d77f13a
commit
11705857cd
@ -5,6 +5,7 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cinttypes>
|
#include <cinttypes>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
#include "common/file_util.h"
|
#include "common/file_util.h"
|
||||||
@ -83,7 +84,7 @@ ResultVal<std::unique_ptr<FileBackend>> NCCHArchive::OpenFile(const Path& path,
|
|||||||
|
|
||||||
// Load NCCH .code or icon/banner/logo
|
// Load NCCH .code or icon/banner/logo
|
||||||
result = ncch_container.LoadSectionExeFS(openfile_path.exefs_filepath.data(), buffer);
|
result = ncch_container.LoadSectionExeFS(openfile_path.exefs_filepath.data(), buffer);
|
||||||
file = std::make_unique<NCCHFile>(buffer);
|
file = std::make_unique<NCCHFile>(std::move(buffer));
|
||||||
} else {
|
} else {
|
||||||
LOG_ERROR(Service_FS, "Unknown NCCH archive type %u!", openfile_path.filepath_type);
|
LOG_ERROR(Service_FS, "Unknown NCCH archive type %u!", openfile_path.filepath_type);
|
||||||
result = Loader::ResultStatus::Error;
|
result = Loader::ResultStatus::Error;
|
||||||
@ -193,6 +194,8 @@ u64 NCCHArchive::GetFreeBytes() const {
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
NCCHFile::NCCHFile(std::vector<u8> buffer) : file_buffer(std::move(buffer)) {}
|
||||||
|
|
||||||
ResultVal<size_t> NCCHFile::Read(const u64 offset, const size_t length, u8* buffer) const {
|
ResultVal<size_t> NCCHFile::Read(const u64 offset, const size_t length, u8* buffer) const {
|
||||||
LOG_TRACE(Service_FS, "called offset=%" PRIu64 ", length=%zu", offset, length);
|
LOG_TRACE(Service_FS, "called offset=%" PRIu64 ", length=%zu", offset, length);
|
||||||
size_t length_left = static_cast<size_t>(data_size - offset);
|
size_t length_left = static_cast<size_t>(data_size - offset);
|
||||||
|
@ -51,7 +51,7 @@ protected:
|
|||||||
// File backend for NCCH files
|
// File backend for NCCH files
|
||||||
class NCCHFile : public FileBackend {
|
class NCCHFile : public FileBackend {
|
||||||
public:
|
public:
|
||||||
NCCHFile(std::vector<u8> buffer) : file_buffer(buffer) {}
|
explicit NCCHFile(std::vector<u8> buffer);
|
||||||
|
|
||||||
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;
|
||||||
|
Loading…
Reference in New Issue
Block a user