From f60385b5ec1c29a163651bc5f52dc42990ec0d81 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Fri, 20 Mar 2026 10:44:00 +0100 Subject: [PATCH] [blacklist] use set instead of vector to store blacklist (insert + lookup O(log(n))) --- src/blacklist.cpp | 37 ++++++++++++++++--------------------- src/blacklist.h | 2 +- 2 files changed, 17 insertions(+), 22 deletions(-) diff --git a/src/blacklist.cpp b/src/blacklist.cpp index 76dec40446..a9b5f6e14e 100644 --- a/src/blacklist.cpp +++ b/src/blacklist.cpp @@ -1,16 +1,13 @@ -#include +#include #include #include #include #include #include "blacklist.h" -#include "string_utils.h" #include "file_utils.h" namespace fs = ghc::filesystem; -std::string global_proc_name; -std::string global_engine_name; static std::string get_proc_name() { // Note: It is possible to use GNU program_invocation_short_name. @@ -21,7 +18,11 @@ static std::string get_proc_name() { return get_basename(get_exe_path()); } -static std::vector blacklist { +// Assign global_proc_name once, and use its cached value, it is runtime-constant. +std::string global_proc_name = get_proc_name(); +std::string global_engine_name; + +static std::set blacklist { "Amazon Games UI.exe", "Battle.net.exe", "BethesdaNetLauncher.exe", @@ -67,23 +68,20 @@ static std::vector blacklist { "vulkandriverquery", }; -static std::vector blacklist_engine { +static std::set blacklist_engine { "GTK" }; static bool check_blacklisted() { - std::string proc_name = get_proc_name(); - std::string engine_name = global_engine_name; - global_proc_name = proc_name; - bool blacklisted = std::find(blacklist.begin(), blacklist.end(), proc_name) != blacklist.end(); - blacklisted |= std::find(blacklist_engine.begin(), blacklist_engine.end(), engine_name) != blacklist_engine.end(); + bool blacklisted = blacklist.find(global_proc_name) != blacklist.end(); + bool blacklisted_engine = blacklist_engine.find(global_engine_name) != blacklist_engine.end(); + blacklisted |= blacklisted_engine; static bool printed = false; if(blacklisted && !printed) { printed = true; - SPDLOG_INFO("process '{}' is blacklisted in MangoHud", proc_name); + SPDLOG_INFO("process '{}' is blacklisted in MangoHud", global_proc_name); } - return blacklisted; } @@ -95,13 +93,10 @@ bool is_blacklisted(bool force_recheck) { } void add_blacklist(const std::string& new_item) { - // check if item exits in blacklist before adding new item - if(std::find(blacklist.begin(), blacklist.end(), new_item) != blacklist.end()) { - return; + SPDLOG_DEBUG("add {} to blacklist", new_item); + auto [_, inserted] = blacklist.insert(new_item); + if (inserted) { + // TODO: actually the checking should be done, after __all__ items have been added, right? + is_blacklisted(true); } - - blacklist.push_back (new_item); - is_blacklisted(true); } - - diff --git a/src/blacklist.h b/src/blacklist.h index 087c7167e3..4cf7bfed70 100644 --- a/src/blacklist.h +++ b/src/blacklist.h @@ -5,6 +5,6 @@ bool is_blacklisted(bool force_recheck = false); void add_blacklist(const std::string& proc); extern std::string global_proc_name; -extern std::string global_engine_name; +extern std::string global_engine_name; // set by vulkan.cpp #endif //MANGOHUD_BLACKLIST_H