From 047b5f8b18c74eebcca094e3160aefe80eb77c0f Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Wed, 17 Jan 2024 16:13:53 +0000 Subject: [PATCH] Cache for wxLocale::IsAvailable(). --- common/font/fontconfig.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/common/font/fontconfig.cpp b/common/font/fontconfig.cpp index 0b52c08947..67f71d2d9c 100644 --- a/common/font/fontconfig.cpp +++ b/common/font/fontconfig.cpp @@ -371,10 +371,12 @@ void FONTCONFIG::ListFonts( std::vector& aFonts, const std::string& // GTK, on the other hand, doesn't appear to support wxLocale::IsAvailable(), // so we can't run these checks. + static std::map availableLanguages; + FcStrSet* langStrSet = FcLangSetGetLangs( langSet ); FcStrList* langStrList = FcStrListCreate( langStrSet ); FcChar8* langStr = FcStrListNext( langStrList ); - bool langSupported = false; + bool langSupported = false; if( !langStr ) { @@ -384,9 +386,16 @@ void FONTCONFIG::ListFonts( std::vector& aFonts, const std::string& else while( langStr ) { wxString langWxStr( reinterpret_cast( langStr ) ); - const wxLanguageInfo* langInfo = wxLocale::FindLanguageInfo( langWxStr ); - if( langInfo && wxLocale::IsAvailable( langInfo->Language ) ) + if( availableLanguages.find( langWxStr ) == availableLanguages.end() ) + { + const wxLanguageInfo* langInfo = wxLocale::FindLanguageInfo( langWxStr ); + bool available = langInfo && wxLocale::IsAvailable( langInfo->Language ); + + availableLanguages[ langWxStr ] = available; + } + + if( availableLanguages[ langWxStr ] ) { langSupported = true; break;