From a1879ea09991158ba99f76275292db8fd4bcc026 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 31 Jan 2024 12:05:15 -0500 Subject: [PATCH 1/4] GraphicsModGroup: Allow heterogenous lookup for GetMod() Allows using keys that aren't directly std::string as the key. This lets us use std::string_view for the incoming path name, making it more flexible with other string types. --- .../GraphicsModSystem/Config/GraphicsModGroup.cpp | 4 +++- .../GraphicsModSystem/Config/GraphicsModGroup.h | 7 +++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Source/Core/VideoCommon/GraphicsModSystem/Config/GraphicsModGroup.cpp b/Source/Core/VideoCommon/GraphicsModSystem/Config/GraphicsModGroup.cpp index 9ce417e079..2e8459dfe4 100644 --- a/Source/Core/VideoCommon/GraphicsModSystem/Config/GraphicsModGroup.cpp +++ b/Source/Core/VideoCommon/GraphicsModSystem/Config/GraphicsModGroup.cpp @@ -7,6 +7,8 @@ #include #include +#include + #include "Common/CommonPaths.h" #include "Common/FileSearch.h" #include "Common/FileUtil.h" @@ -174,7 +176,7 @@ std::vector& GraphicsModGroupConfig::GetMods() return m_graphics_mods; } -GraphicsModConfig* GraphicsModGroupConfig::GetMod(const std::string& absolute_path) const +GraphicsModConfig* GraphicsModGroupConfig::GetMod(std::string_view absolute_path) const { if (const auto iter = m_path_to_graphics_mod.find(absolute_path); iter != m_path_to_graphics_mod.end()) diff --git a/Source/Core/VideoCommon/GraphicsModSystem/Config/GraphicsModGroup.h b/Source/Core/VideoCommon/GraphicsModSystem/Config/GraphicsModGroup.h index 9614951e96..b2178db3f6 100644 --- a/Source/Core/VideoCommon/GraphicsModSystem/Config/GraphicsModGroup.h +++ b/Source/Core/VideoCommon/GraphicsModSystem/Config/GraphicsModGroup.h @@ -5,10 +5,9 @@ #include #include +#include #include -#include - #include "Common/CommonTypes.h" struct GraphicsModConfig; @@ -34,7 +33,7 @@ public: const std::vector& GetMods() const; std::vector& GetMods(); - GraphicsModConfig* GetMod(const std::string& absolute_path) const; + GraphicsModConfig* GetMod(std::string_view absolute_path) const; const std::string& GetGameID() const; @@ -42,6 +41,6 @@ private: std::string GetPath() const; std::string m_game_id; std::vector m_graphics_mods; - std::map m_path_to_graphics_mod; + std::map> m_path_to_graphics_mod; u32 m_change_count = 0; }; From 81aca79145c1f4618d2f7e3ba41e8840e2d98684 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 31 Jan 2024 12:09:33 -0500 Subject: [PATCH 2/4] GraphicsModListWidget: Pass optional by const reference All we do is read from it, so we don't need to copy the string if we happen to have one. --- Source/Core/DolphinQt/Config/GraphicsModListWidget.cpp | 4 ++-- Source/Core/DolphinQt/Config/GraphicsModListWidget.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/Core/DolphinQt/Config/GraphicsModListWidget.cpp b/Source/Core/DolphinQt/Config/GraphicsModListWidget.cpp index 2151642d2b..f8f0bc86db 100644 --- a/Source/Core/DolphinQt/Config/GraphicsModListWidget.cpp +++ b/Source/Core/DolphinQt/Config/GraphicsModListWidget.cpp @@ -185,7 +185,7 @@ void GraphicsModListWidget::ModItemChanged(QListWidgetItem* item) m_needs_save = true; } -void GraphicsModListWidget::OnModChanged(std::optional absolute_path) +void GraphicsModListWidget::OnModChanged(const std::optional& absolute_path) { ClearLayoutRecursively(m_mod_meta_layout); @@ -198,7 +198,7 @@ void GraphicsModListWidget::OnModChanged(std::optional absolute_pat return; } - GraphicsModConfig* mod = m_mod_group.GetMod(*absolute_path); + const GraphicsModConfig* mod = m_mod_group.GetMod(*absolute_path); if (!mod) return; diff --git a/Source/Core/DolphinQt/Config/GraphicsModListWidget.h b/Source/Core/DolphinQt/Config/GraphicsModListWidget.h index 7b32792cff..ff310af56c 100644 --- a/Source/Core/DolphinQt/Config/GraphicsModListWidget.h +++ b/Source/Core/DolphinQt/Config/GraphicsModListWidget.h @@ -52,7 +52,7 @@ private: void ModSelectionChanged(); void ModItemChanged(QListWidgetItem* item); - void OnModChanged(std::optional absolute_path); + void OnModChanged(const std::optional& absolute_path); void SaveModList(); From ccacda5e2c4aed03ea75ef17d8f73376464a7b00 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 31 Jan 2024 12:20:11 -0500 Subject: [PATCH 3/4] GraphicsModGroup: Simplify try_add_mod() We can use contains() here, and also move the mod config if it's valid instead of copying it, since it contains quite a bit of allocated data. --- .../GraphicsModSystem/Config/GraphicsModGroup.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/Source/Core/VideoCommon/GraphicsModSystem/Config/GraphicsModGroup.cpp b/Source/Core/VideoCommon/GraphicsModSystem/Config/GraphicsModGroup.cpp index 2e8459dfe4..f200604503 100644 --- a/Source/Core/VideoCommon/GraphicsModSystem/Config/GraphicsModGroup.cpp +++ b/Source/Core/VideoCommon/GraphicsModSystem/Config/GraphicsModGroup.cpp @@ -95,15 +95,11 @@ void GraphicsModGroupConfig::Load() GraphicsModConfig::Source source) { auto file = dir + DIR_SEP + "metadata.json"; UnifyPathSeparators(file); - if (known_paths.find(file) != known_paths.end()) - { + if (known_paths.contains(file)) return; - } - const auto mod = GraphicsModConfig::Create(file, source); - if (mod) - { - m_graphics_mods.push_back(*mod); - } + + if (auto mod = GraphicsModConfig::Create(file, source)) + m_graphics_mods.push_back(std::move(*mod)); }; const std::set graphics_mod_user_directories = From 40b050fe3710df4af6b38a338e8a9594714172ce Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 31 Jan 2024 12:27:40 -0500 Subject: [PATCH 4/4] GraphicsModGroup: std::move graphics_mod in Load() The config object is quite heavyweight, so we should move this instead of copying. --- .../VideoCommon/GraphicsModSystem/Config/GraphicsModGroup.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Core/VideoCommon/GraphicsModSystem/Config/GraphicsModGroup.cpp b/Source/Core/VideoCommon/GraphicsModSystem/Config/GraphicsModGroup.cpp index f200604503..0873c09e91 100644 --- a/Source/Core/VideoCommon/GraphicsModSystem/Config/GraphicsModGroup.cpp +++ b/Source/Core/VideoCommon/GraphicsModSystem/Config/GraphicsModGroup.cpp @@ -85,7 +85,7 @@ void GraphicsModGroupConfig::Load() auto mod_full_path = graphics_mod->GetAbsolutePath(); known_paths.insert(std::move(mod_full_path)); - m_graphics_mods.push_back(*graphics_mod); + m_graphics_mods.push_back(std::move(*graphics_mod)); } } }