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
|
@ -1222,7 +1222,7 @@ void Module::Interface::GetProgramInfoFromCia(Kernel::HLERequestContext& ctx) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
FileSys::TitleMetadata tmd = container.GetTitleMetadata();
|
const FileSys::TitleMetadata& tmd = container.GetTitleMetadata();
|
||||||
TitleInfo title_info = {};
|
TitleInfo title_info = {};
|
||||||
container.Print();
|
container.Print();
|
||||||
|
|
||||||
|
|
|
@ -1381,7 +1381,7 @@ Module::Module(Core::System& system) : system(system) {
|
||||||
change_state_event =
|
change_state_event =
|
||||||
system.Kernel().CreateEvent(Kernel::ResetType::OneShot, "CECD::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);
|
FileSys::ArchiveFactory_SystemSaveData systemsavedata_factory(nand_directory);
|
||||||
|
|
||||||
// Open the SystemSaveData archive 0x00010026
|
// Open the SystemSaveData archive 0x00010026
|
||||||
|
|
|
@ -555,7 +555,7 @@ ResultCode Module::FormatConfig() {
|
||||||
} // namespace Service::CFG
|
} // namespace Service::CFG
|
||||||
|
|
||||||
ResultCode Module::LoadConfigNANDSaveFile() {
|
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);
|
FileSys::ArchiveFactory_SystemSaveData systemsavedata_factory(nand_directory);
|
||||||
|
|
||||||
// Open the SystemSaveData archive 0x00010017
|
// 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) {
|
ResultCode ArchiveManager::DeleteSystemSaveData(u32 high, u32 low) {
|
||||||
// Construct the binary path to the archive first
|
// 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);
|
const std::string& nand_directory = FileUtil::GetUserPath(FileUtil::UserPath::NANDDir);
|
||||||
std::string base_path = FileSys::GetSystemSaveDataContainerPath(nand_directory);
|
const std::string base_path = FileSys::GetSystemSaveDataContainerPath(nand_directory);
|
||||||
std::string systemsavedata_path = FileSys::GetSystemSaveDataPath(base_path, path);
|
const std::string systemsavedata_path = FileSys::GetSystemSaveDataPath(base_path, path);
|
||||||
if (!FileUtil::DeleteDirRecursively(systemsavedata_path))
|
if (!FileUtil::DeleteDirRecursively(systemsavedata_path)) {
|
||||||
return ResultCode(-1); // TODO(Subv): Find the right error code
|
return ResultCode(-1); // TODO(Subv): Find the right error code
|
||||||
|
}
|
||||||
|
|
||||||
return RESULT_SUCCESS;
|
return RESULT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode ArchiveManager::CreateSystemSaveData(u32 high, u32 low) {
|
ResultCode ArchiveManager::CreateSystemSaveData(u32 high, u32 low) {
|
||||||
// Construct the binary path to the archive first
|
// 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);
|
const std::string& nand_directory = FileUtil::GetUserPath(FileUtil::UserPath::NANDDir);
|
||||||
std::string base_path = FileSys::GetSystemSaveDataContainerPath(nand_directory);
|
const std::string base_path = FileSys::GetSystemSaveDataContainerPath(nand_directory);
|
||||||
std::string systemsavedata_path = FileSys::GetSystemSaveDataPath(base_path, path);
|
const std::string systemsavedata_path = FileSys::GetSystemSaveDataPath(base_path, path);
|
||||||
if (!FileUtil::CreateFullPath(systemsavedata_path))
|
if (!FileUtil::CreateFullPath(systemsavedata_path)) {
|
||||||
return ResultCode(-1); // TODO(Subv): Find the right error code
|
return ResultCode(-1); // TODO(Subv): Find the right error code
|
||||||
|
}
|
||||||
|
|
||||||
return RESULT_SUCCESS;
|
return RESULT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -134,7 +134,7 @@ void Module::Interface::CheckNew3DS(Kernel::HLERequestContext& ctx) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void WriteGameCoinData(GameCoin gamecoin_data) {
|
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::ArchiveFactory_ExtSaveData extdata_archive_factory(nand_directory, true);
|
||||||
|
|
||||||
FileSys::Path archive_path(ptm_shared_extdata_id);
|
FileSys::Path archive_path(ptm_shared_extdata_id);
|
||||||
|
@ -167,7 +167,7 @@ static void WriteGameCoinData(GameCoin gamecoin_data) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static GameCoin ReadGameCoinData() {
|
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::ArchiveFactory_ExtSaveData extdata_archive_factory(nand_directory, true);
|
||||||
|
|
||||||
FileSys::Path archive_path(ptm_shared_extdata_id);
|
FileSys::Path archive_path(ptm_shared_extdata_id);
|
||||||
|
@ -197,10 +197,10 @@ static GameCoin ReadGameCoinData() {
|
||||||
Module::Module() {
|
Module::Module() {
|
||||||
// Open the SharedExtSaveData archive 0xF000000B and create the gamecoin.dat file if it doesn't
|
// Open the SharedExtSaveData archive 0xF000000B and create the gamecoin.dat file if it doesn't
|
||||||
// exist
|
// 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::ArchiveFactory_ExtSaveData extdata_archive_factory(nand_directory, true);
|
||||||
FileSys::Path archive_path(ptm_shared_extdata_id);
|
const FileSys::Path archive_path(ptm_shared_extdata_id);
|
||||||
auto archive_result = extdata_archive_factory.Open(archive_path, 0);
|
const auto archive_result = extdata_archive_factory.Open(archive_path, 0);
|
||||||
// If the archive didn't exist, write the default game coin file
|
// If the archive didn't exist, write the default game coin file
|
||||||
if (archive_result.Code() == FileSys::ERR_NOT_FORMATTED) {
|
if (archive_result.Code() == FileSys::ERR_NOT_FORMATTED) {
|
||||||
WriteGameCoinData(default_game_coin);
|
WriteGameCoinData(default_game_coin);
|
||||||
|
|
Loading…
Reference in New Issue