service: Resolve trivially avoidable copies (#5237)
* am/am: Avoid redundant copy in GetProgramInfoFromCia() We can just use a reference to the title metadata. Avoids copying several data entries and std::vector instances that don't need to be copied. * hle/service: Avoid redundant copying of std::string GetUserPath() returns the path as a reference, so we can make use of said reference to avoid making copies.
This commit is contained in:
parent
e54b640e0b
commit
8014c67faa
5 changed files with 22 additions and 18 deletions
|
@ -1222,7 +1222,7 @@ void Module::Interface::GetProgramInfoFromCia(Kernel::HLERequestContext& ctx) {
|
|||
return;
|
||||
}
|
||||
|
||||
FileSys::TitleMetadata tmd = container.GetTitleMetadata();
|
||||
const FileSys::TitleMetadata& tmd = container.GetTitleMetadata();
|
||||
TitleInfo title_info = {};
|
||||
container.Print();
|
||||
|
||||
|
|
|
@ -1381,7 +1381,7 @@ Module::Module(Core::System& system) : system(system) {
|
|||
change_state_event =
|
||||
system.Kernel().CreateEvent(Kernel::ResetType::OneShot, "CECD::change_state_event");
|
||||
|
||||
std::string nand_directory = FileUtil::GetUserPath(FileUtil::UserPath::NANDDir);
|
||||
const std::string& nand_directory = FileUtil::GetUserPath(FileUtil::UserPath::NANDDir);
|
||||
FileSys::ArchiveFactory_SystemSaveData systemsavedata_factory(nand_directory);
|
||||
|
||||
// Open the SystemSaveData archive 0x00010026
|
||||
|
|
|
@ -555,7 +555,7 @@ ResultCode Module::FormatConfig() {
|
|||
} // namespace Service::CFG
|
||||
|
||||
ResultCode Module::LoadConfigNANDSaveFile() {
|
||||
std::string nand_directory = FileUtil::GetUserPath(FileUtil::UserPath::NANDDir);
|
||||
const std::string& nand_directory = FileUtil::GetUserPath(FileUtil::UserPath::NANDDir);
|
||||
FileSys::ArchiveFactory_SystemSaveData systemsavedata_factory(nand_directory);
|
||||
|
||||
// Open the SystemSaveData archive 0x00010017
|
||||
|
|
|
@ -267,25 +267,29 @@ ResultCode ArchiveManager::DeleteExtSaveData(MediaType media_type, u32 high, u32
|
|||
|
||||
ResultCode ArchiveManager::DeleteSystemSaveData(u32 high, u32 low) {
|
||||
// Construct the binary path to the archive first
|
||||
FileSys::Path path = FileSys::ConstructSystemSaveDataBinaryPath(high, low);
|
||||
const FileSys::Path path = FileSys::ConstructSystemSaveDataBinaryPath(high, low);
|
||||
|
||||
std::string nand_directory = FileUtil::GetUserPath(FileUtil::UserPath::NANDDir);
|
||||
std::string base_path = FileSys::GetSystemSaveDataContainerPath(nand_directory);
|
||||
std::string systemsavedata_path = FileSys::GetSystemSaveDataPath(base_path, path);
|
||||
if (!FileUtil::DeleteDirRecursively(systemsavedata_path))
|
||||
const std::string& nand_directory = FileUtil::GetUserPath(FileUtil::UserPath::NANDDir);
|
||||
const std::string base_path = FileSys::GetSystemSaveDataContainerPath(nand_directory);
|
||||
const std::string systemsavedata_path = FileSys::GetSystemSaveDataPath(base_path, path);
|
||||
if (!FileUtil::DeleteDirRecursively(systemsavedata_path)) {
|
||||
return ResultCode(-1); // TODO(Subv): Find the right error code
|
||||
}
|
||||
|
||||
return RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
ResultCode ArchiveManager::CreateSystemSaveData(u32 high, u32 low) {
|
||||
// Construct the binary path to the archive first
|
||||
FileSys::Path path = FileSys::ConstructSystemSaveDataBinaryPath(high, low);
|
||||
const FileSys::Path path = FileSys::ConstructSystemSaveDataBinaryPath(high, low);
|
||||
|
||||
std::string nand_directory = FileUtil::GetUserPath(FileUtil::UserPath::NANDDir);
|
||||
std::string base_path = FileSys::GetSystemSaveDataContainerPath(nand_directory);
|
||||
std::string systemsavedata_path = FileSys::GetSystemSaveDataPath(base_path, path);
|
||||
if (!FileUtil::CreateFullPath(systemsavedata_path))
|
||||
const std::string& nand_directory = FileUtil::GetUserPath(FileUtil::UserPath::NANDDir);
|
||||
const std::string base_path = FileSys::GetSystemSaveDataContainerPath(nand_directory);
|
||||
const std::string systemsavedata_path = FileSys::GetSystemSaveDataPath(base_path, path);
|
||||
if (!FileUtil::CreateFullPath(systemsavedata_path)) {
|
||||
return ResultCode(-1); // TODO(Subv): Find the right error code
|
||||
}
|
||||
|
||||
return RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
|
|
|
@ -134,7 +134,7 @@ void Module::Interface::CheckNew3DS(Kernel::HLERequestContext& ctx) {
|
|||
}
|
||||
|
||||
static void WriteGameCoinData(GameCoin gamecoin_data) {
|
||||
std::string nand_directory = FileUtil::GetUserPath(FileUtil::UserPath::NANDDir);
|
||||
const std::string& nand_directory = FileUtil::GetUserPath(FileUtil::UserPath::NANDDir);
|
||||
FileSys::ArchiveFactory_ExtSaveData extdata_archive_factory(nand_directory, true);
|
||||
|
||||
FileSys::Path archive_path(ptm_shared_extdata_id);
|
||||
|
@ -167,7 +167,7 @@ static void WriteGameCoinData(GameCoin gamecoin_data) {
|
|||
}
|
||||
|
||||
static GameCoin ReadGameCoinData() {
|
||||
std::string nand_directory = FileUtil::GetUserPath(FileUtil::UserPath::NANDDir);
|
||||
const std::string& nand_directory = FileUtil::GetUserPath(FileUtil::UserPath::NANDDir);
|
||||
FileSys::ArchiveFactory_ExtSaveData extdata_archive_factory(nand_directory, true);
|
||||
|
||||
FileSys::Path archive_path(ptm_shared_extdata_id);
|
||||
|
@ -197,10 +197,10 @@ static GameCoin ReadGameCoinData() {
|
|||
Module::Module() {
|
||||
// Open the SharedExtSaveData archive 0xF000000B and create the gamecoin.dat file if it doesn't
|
||||
// exist
|
||||
std::string nand_directory = FileUtil::GetUserPath(FileUtil::UserPath::NANDDir);
|
||||
const std::string& nand_directory = FileUtil::GetUserPath(FileUtil::UserPath::NANDDir);
|
||||
FileSys::ArchiveFactory_ExtSaveData extdata_archive_factory(nand_directory, true);
|
||||
FileSys::Path archive_path(ptm_shared_extdata_id);
|
||||
auto archive_result = extdata_archive_factory.Open(archive_path, 0);
|
||||
const FileSys::Path archive_path(ptm_shared_extdata_id);
|
||||
const auto archive_result = extdata_archive_factory.Open(archive_path, 0);
|
||||
// If the archive didn't exist, write the default game coin file
|
||||
if (archive_result.Code() == FileSys::ERR_NOT_FORMATTED) {
|
||||
WriteGameCoinData(default_game_coin);
|
||||
|
|
Loading…
Reference in a new issue