From 6636f3ff4717886f48b7cd238cd75315952cb112 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 9 Oct 2018 14:22:31 -0400 Subject: patch_manager: Return a std::unique_ptr from ParseControlNCA() and GetControlMetadata() instead of a std::shared_ptr Neither of these functions require the use of shared ownership of the returned pointer. This makes it more difficult to create reference cycles with, and makes the interface more generic, as std::shared_ptr instances can be created from a std::unique_ptr, but the vice-versa isn't possible. This also alters relevant functions to take NCA arguments by const reference rather than a const reference to a std::shared_ptr. These functions don't alter the ownership of the memory used by the NCA instance, so we can make the interface more generic by not assuming anything about the type of smart pointer the NCA is contained within and make it the caller's responsibility to ensure the supplied NCA is valid. --- src/core/file_sys/patch_manager.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'src/core/file_sys/patch_manager.cpp') diff --git a/src/core/file_sys/patch_manager.cpp b/src/core/file_sys/patch_manager.cpp index b14d7cb0a..019caebe9 100644 --- a/src/core/file_sys/patch_manager.cpp +++ b/src/core/file_sys/patch_manager.cpp @@ -345,23 +345,22 @@ std::map> PatchManager::GetPatchVersionNam return out; } -std::pair, VirtualFile> PatchManager::GetControlMetadata() const { +std::pair, VirtualFile> PatchManager::GetControlMetadata() const { const auto& installed{Service::FileSystem::GetUnionContents()}; const auto base_control_nca = installed->GetEntry(title_id, ContentRecordType::Control); if (base_control_nca == nullptr) return {}; - return ParseControlNCA(base_control_nca); + return ParseControlNCA(*base_control_nca); } -std::pair, VirtualFile> PatchManager::ParseControlNCA( - const std::shared_ptr& nca) const { - const auto base_romfs = nca->GetRomFS(); +std::pair, VirtualFile> PatchManager::ParseControlNCA(const NCA& nca) const { + const auto base_romfs = nca.GetRomFS(); if (base_romfs == nullptr) return {}; - const auto romfs = PatchRomFS(base_romfs, nca->GetBaseIVFCOffset(), ContentRecordType::Control); + const auto romfs = PatchRomFS(base_romfs, nca.GetBaseIVFCOffset(), ContentRecordType::Control); if (romfs == nullptr) return {}; @@ -373,7 +372,7 @@ std::pair, VirtualFile> PatchManager::ParseControlNCA( if (nacp_file == nullptr) nacp_file = extracted->GetFile("Control.nacp"); - const auto nacp = nacp_file == nullptr ? nullptr : std::make_shared(nacp_file); + auto nacp = nacp_file == nullptr ? nullptr : std::make_unique(nacp_file); VirtualFile icon_file; for (const auto& language : FileSys::LANGUAGE_NAMES) { @@ -382,6 +381,6 @@ std::pair, VirtualFile> PatchManager::ParseControlNCA( break; } - return {nacp, icon_file}; + return {std::move(nacp), icon_file}; } } // namespace FileSys -- cgit v1.2.3