From 8f183a47dd3dca5247b893960afd09b6f603ae87 Mon Sep 17 00:00:00 2001 From: Zach Hilman Date: Thu, 1 Nov 2018 20:24:32 -0400 Subject: filesystem: Cache RegisteredCacheUnion instead of constructing on demand Prevents unnecessary re-reads of the metadata and unnecessary temporary objects. --- src/core/hle/service/filesystem/filesystem.cpp | 13 ++++++++++--- src/core/hle/service/filesystem/filesystem.h | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/core/hle/service/filesystem/filesystem.cpp b/src/core/hle/service/filesystem/filesystem.cpp index e32a7c48e..ad865751f 100644 --- a/src/core/hle/service/filesystem/filesystem.cpp +++ b/src/core/hle/service/filesystem/filesystem.cpp @@ -319,9 +319,16 @@ ResultVal OpenSDMC() { return sdmc_factory->Open(); } -std::unique_ptr GetUnionContents() { - return std::make_unique(std::vector{ - GetSystemNANDContents(), GetUserNANDContents(), GetSDMCContents()}); +std::shared_ptr registered_cache_union; + +std::shared_ptr GetUnionContents() { + if (registered_cache_union == nullptr) { + registered_cache_union = + std::make_shared(std::vector{ + GetSystemNANDContents(), GetUserNANDContents(), GetSDMCContents()}); + } + + return registered_cache_union; } FileSys::RegisteredCache* GetSystemNANDContents() { diff --git a/src/core/hle/service/filesystem/filesystem.h b/src/core/hle/service/filesystem/filesystem.h index 6ca5c5636..6f3e0cd03 100644 --- a/src/core/hle/service/filesystem/filesystem.h +++ b/src/core/hle/service/filesystem/filesystem.h @@ -47,7 +47,7 @@ ResultVal OpenSaveData(FileSys::SaveDataSpaceId space, FileSys::SaveDataDescriptor save_struct); ResultVal OpenSDMC(); -std::unique_ptr GetUnionContents(); +std::shared_ptr GetUnionContents(); FileSys::RegisteredCache* GetSystemNANDContents(); FileSys::RegisteredCache* GetUserNANDContents(); -- cgit v1.2.3