From 11705857cdafbf8c870de9dec1a391691f1df271 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sat, 9 Dec 2017 14:18:31 -0500 Subject: [PATCH] file_sys: std::move the vector in NCCHFile's constructor Avoids making unnecessary copies of the source vector's data. --- src/core/file_sys/archive_ncch.cpp | 5 ++++- src/core/file_sys/archive_ncch.h | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/core/file_sys/archive_ncch.cpp b/src/core/file_sys/archive_ncch.cpp index 24b0f504b2..2c4ed2d450 100644 --- a/src/core/file_sys/archive_ncch.cpp +++ b/src/core/file_sys/archive_ncch.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include "common/common_types.h" #include "common/file_util.h" @@ -83,7 +84,7 @@ ResultVal> NCCHArchive::OpenFile(const Path& path, // Load NCCH .code or icon/banner/logo result = ncch_container.LoadSectionExeFS(openfile_path.exefs_filepath.data(), buffer); - file = std::make_unique(buffer); + file = std::make_unique(std::move(buffer)); } else { LOG_ERROR(Service_FS, "Unknown NCCH archive type %u!", openfile_path.filepath_type); result = Loader::ResultStatus::Error; @@ -193,6 +194,8 @@ u64 NCCHArchive::GetFreeBytes() const { //////////////////////////////////////////////////////////////////////////////////////////////////// +NCCHFile::NCCHFile(std::vector buffer) : file_buffer(std::move(buffer)) {} + ResultVal NCCHFile::Read(const u64 offset, const size_t length, u8* buffer) const { LOG_TRACE(Service_FS, "called offset=%" PRIu64 ", length=%zu", offset, length); size_t length_left = static_cast(data_size - offset); diff --git a/src/core/file_sys/archive_ncch.h b/src/core/file_sys/archive_ncch.h index 0dfbd42419..f2ba888d86 100644 --- a/src/core/file_sys/archive_ncch.h +++ b/src/core/file_sys/archive_ncch.h @@ -51,7 +51,7 @@ protected: // File backend for NCCH files class NCCHFile : public FileBackend { public: - NCCHFile(std::vector buffer) : file_buffer(buffer) {} + explicit NCCHFile(std::vector buffer); ResultVal Read(u64 offset, size_t length, u8* buffer) const override; ResultVal Write(u64 offset, size_t length, bool flush, const u8* buffer) override;