tdf#158556 avoid a ton of temporary OUString
Change-Id: I5256210d73eb54d4e6ea98b68c1e9eabf8770ccd Reviewed-on: https://gerrit.libreoffice.org/c/core/+/172525 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
This commit is contained in:
@@ -23,6 +23,7 @@
|
||||
#include <atomic>
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
#include <optional>
|
||||
#include <string_view>
|
||||
#include <unordered_set>
|
||||
|
||||
@@ -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<lang::Locale> moCacheKey;
|
||||
static std::optional<LanguageType> 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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user