summaryrefslogtreecommitdiff
path: root/src/core/loader/nax.cpp
diff options
context:
space:
mode:
authorGravatar Lioncash2018-09-19 14:13:00 -0400
committerGravatar Lioncash2018-09-19 14:22:37 -0400
commit45195a51a76b3000e028234f619a4d15bff443eb (patch)
tree5261c2ea094b4022505cd8e6f64911f877304ebd /src/core/loader/nax.cpp
parentnax: Avoid unnecessary calls to AsNCA() in IdentifyType() (diff)
downloadyuzu-45195a51a76b3000e028234f619a4d15bff443eb.tar.gz
yuzu-45195a51a76b3000e028234f619a4d15bff443eb.tar.xz
yuzu-45195a51a76b3000e028234f619a4d15bff443eb.zip
nax: Avoid re-parsing NAX data with GetFileType()
An instance of the NAX apploader already has an existing NAX instance in memory. Calling directly into IdentifyType() directly would re-parse the whole file again into yet another NAX instance, only to toss it away again. This gets rid of unnecessary/redundant file parsing and allocations.
Diffstat (limited to 'src/core/loader/nax.cpp')
-rw-r--r--src/core/loader/nax.cpp28
1 files changed, 18 insertions, 10 deletions
diff --git a/src/core/loader/nax.cpp b/src/core/loader/nax.cpp
index 02a0d5ba7..5d4380684 100644
--- a/src/core/loader/nax.cpp
+++ b/src/core/loader/nax.cpp
@@ -11,16 +11,8 @@
11#include "core/loader/nca.h" 11#include "core/loader/nca.h"
12 12
13namespace Loader { 13namespace Loader {
14 14namespace {
15AppLoader_NAX::AppLoader_NAX(FileSys::VirtualFile file) 15FileType IdentifyTypeImpl(const FileSys::NAX& nax) {
16 : AppLoader(file), nax(std::make_unique<FileSys::NAX>(file)),
17 nca_loader(std::make_unique<AppLoader_NCA>(nax->GetDecrypted())) {}
18
19AppLoader_NAX::~AppLoader_NAX() = default;
20
21FileType AppLoader_NAX::IdentifyType(const FileSys::VirtualFile& file) {
22 FileSys::NAX nax(file);
23
24 if (nax.GetStatus() != ResultStatus::Success) { 16 if (nax.GetStatus() != ResultStatus::Success) {
25 return FileType::Error; 17 return FileType::Error;
26 } 18 }
@@ -32,6 +24,22 @@ FileType AppLoader_NAX::IdentifyType(const FileSys::VirtualFile& file) {
32 24
33 return FileType::NAX; 25 return FileType::NAX;
34} 26}
27} // Anonymous namespace
28
29AppLoader_NAX::AppLoader_NAX(FileSys::VirtualFile file)
30 : AppLoader(file), nax(std::make_unique<FileSys::NAX>(file)),
31 nca_loader(std::make_unique<AppLoader_NCA>(nax->GetDecrypted())) {}
32
33AppLoader_NAX::~AppLoader_NAX() = default;
34
35FileType AppLoader_NAX::IdentifyType(const FileSys::VirtualFile& file) {
36 const FileSys::NAX nax(file);
37 return IdentifyTypeImpl(nax);
38}
39
40FileType AppLoader_NAX::GetFileType() {
41 return IdentifyTypeImpl(*nax);
42}
35 43
36ResultStatus AppLoader_NAX::Load(Kernel::SharedPtr<Kernel::Process>& process) { 44ResultStatus AppLoader_NAX::Load(Kernel::SharedPtr<Kernel::Process>& process) {
37 if (is_loaded) { 45 if (is_loaded) {