diff --git a/i18nlangtag/source/languagetag/languagetag.cxx b/i18nlangtag/source/languagetag/languagetag.cxx index 5a922babd5ea..b43efe2625a0 100644 --- a/i18nlangtag/source/languagetag/languagetag.cxx +++ b/i18nlangtag/source/languagetag/languagetag.cxx @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -2822,7 +2823,22 @@ LanguageType LanguageTag::convertToLanguageType( const css::lang::Locale& rLocal if (rLocale.Language.isEmpty() && !bResolveSystem) return LANGUAGE_SYSTEM; - return LanguageTag( rLocale).getLanguageType( bResolveSystem); + if (!bResolveSystem) + { + // single-item cache + static std::mutex gMutex; + static std::optional moCacheKey; + static std::optional moCacheValue; + std::unique_lock l(gMutex); + if (!moCacheKey || *moCacheKey != rLocale) + { + moCacheValue = LanguageTag(rLocale).getLanguageType(false); + moCacheKey = rLocale; + } + return *moCacheValue; + } + else + return LanguageTag( rLocale).getLanguageType( bResolveSystem); }