From bd8bc1e251c9e2d50c94d8fa198f0b3663bd42c3 Mon Sep 17 00:00:00 2001 From: BZLZHH Date: Sat, 21 Feb 2026 22:30:50 +0800 Subject: [PATCH] [Improvement] (MG_ConfigLoader): Destroy map after init. --- MobileGL/ConfigLoader.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/MobileGL/ConfigLoader.cpp b/MobileGL/ConfigLoader.cpp index 7084701e..44f2b659 100644 --- a/MobileGL/ConfigLoader.cpp +++ b/MobileGL/ConfigLoader.cpp @@ -9,14 +9,19 @@ #include "Config.h" namespace MobileGL::MG_ConfigLoader { - static UnorderedMap acceptedEnvVariablesMap; + static UniquePtr> acceptedEnvVariablesMap; static Bool IsAcceptedPrefix(const String& key) { return (key.compare(0, 6, "LIBGL_") == 0 || key.compare(0, 9, "MOBILEGL_") == 0); } inline void InitializeAcceptedEnvVariables() { - acceptedEnvVariablesMap.clear(); + if (!acceptedEnvVariablesMap) { + acceptedEnvVariablesMap = MakeUnique>(); + } else { + acceptedEnvVariablesMap->clear(); + } + char** envPtr = nullptr; #ifdef _WIN32 @@ -35,15 +40,16 @@ namespace MobileGL::MG_ConfigLoader { String value = entry.substr(pos + 1); if (IsAcceptedPrefix(key)) { - acceptedEnvVariablesMap[key] = value; + (*acceptedEnvVariablesMap)[key] = value; + MGLOG_D("Config: Accepted env variable: %s=%s", key.c_str(), value.c_str()); } } } } inline void QueryEnvVariable(const String& key, String& outValue, const String& defaultValue) { - auto it = acceptedEnvVariablesMap.find(key); - if (it != acceptedEnvVariablesMap.end()) { + auto it = acceptedEnvVariablesMap->find(key); + if (it != acceptedEnvVariablesMap->end()) { outValue = it->second; } else { outValue = defaultValue; @@ -71,5 +77,8 @@ namespace MobileGL::MG_ConfigLoader { InitializeAcceptedEnvVariables(); InitBackendType(); + + // Destroy the map since we won't need it anymore + acceptedEnvVariablesMap.reset(); } } // namespace MobileGL::MG_ConfigLoader