From bb9947fe0ef1e86ea882d7419b85c17ed6654f67 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 18 Jun 2020 05:27:54 -0400 Subject: [PATCH] CGameProject: Make use of std::string_view where applicable Makes a few functions have non-allocating arguments --- src/Core/CAudioManager.cpp | 2 +- src/Core/GameProject/CGameProject.cpp | 20 +++++++++----------- src/Core/GameProject/CGameProject.h | 5 +++-- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/Core/CAudioManager.cpp b/src/Core/CAudioManager.cpp index ab2c0aa4..64ca2589 100644 --- a/src/Core/CAudioManager.cpp +++ b/src/Core/CAudioManager.cpp @@ -39,7 +39,7 @@ void CAudioManager::LoadAssets() } // Load audio lookup table + sfx name list - const TString AudioLookupName = (mpProject->Game() < EGame::EchoesDemo ? "sound_lookup" : "sound_lookup_ATBL"); + const std::string_view AudioLookupName = mpProject->Game() < EGame::EchoesDemo ? "sound_lookup" : "sound_lookup_ATBL"; const CAssetID AudioLookupID = mpProject->FindNamedResource(AudioLookupName); if (AudioLookupID.IsValid()) diff --git a/src/Core/GameProject/CGameProject.cpp b/src/Core/GameProject/CGameProject.cpp index 68a17f07..afe87f23 100644 --- a/src/Core/GameProject/CGameProject.cpp +++ b/src/Core/GameProject/CGameProject.cpp @@ -148,7 +148,7 @@ void CGameProject::GetWorldList(std::list& rOut) const } } -CAssetID CGameProject::FindNamedResource(const TString& rkName) const +CAssetID CGameProject::FindNamedResource(std::string_view name) const { for (const auto& pkg : mPackages) { @@ -156,7 +156,7 @@ CAssetID CGameProject::FindNamedResource(const TString& rkName) const { const SNamedResource& rkRes = pkg->NamedResourceByIndex(iRes); - if (rkRes.Name == rkName) + if (rkRes.Name == name) return rkRes.ID; } } @@ -164,17 +164,15 @@ CAssetID CGameProject::FindNamedResource(const TString& rkName) const return CAssetID::InvalidID(mGame); } -CPackage* CGameProject::FindPackage(const TString& rkName) const +CPackage* CGameProject::FindPackage(std::string_view name) const { - for (const auto& pPackage : mPackages) - { - if (pPackage->Name() == rkName) - { - return pPackage.get(); - } - } + const auto iter = std::find_if(mPackages.begin(), mPackages.end(), + [name](const auto& package) { return package->Name() == name; }); - return nullptr; + if (iter == mPackages.cend()) + return nullptr; + + return iter->get(); } std::unique_ptr CGameProject::CreateProjectForExport( diff --git a/src/Core/GameProject/CGameProject.h b/src/Core/GameProject/CGameProject.h index b53caee5..f00cdbaf 100644 --- a/src/Core/GameProject/CGameProject.h +++ b/src/Core/GameProject/CGameProject.h @@ -14,6 +14,7 @@ #include #include #include +#include namespace nod { class DiscWii; } @@ -57,8 +58,8 @@ public: bool BuildISO(const TString& rkIsoPath, IProgressNotifier *pProgress); bool MergeISO(const TString& rkIsoPath, nod::DiscWii *pOriginalIso, IProgressNotifier *pProgress); void GetWorldList(std::list& rOut) const; - CAssetID FindNamedResource(const TString& rkName) const; - CPackage* FindPackage(const TString& rkName) const; + CAssetID FindNamedResource(std::string_view name) const; + CPackage* FindPackage(std::string_view name) const; // Static static std::unique_ptr CreateProjectForExport(