diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2023-06-13 22:04:09 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2023-09-27 08:00:21 +0200 |
commit | 79e723cde11d2eba6d45d6c89a3d3109062e675c (patch) | |
tree | 4f7c186d5076db2421b60c39917f1e93607b38e7 | |
parent | 1d7dc53f19d188ae12603ca3cd526eb0a5016cf4 (diff) |
tdf#151946 cache LocaleDataWrapper
because it is a little more expensive these days to create it, since I
made it an immutable type (which is also why we can safely cache it)
Reduces load time from 7s to 1.5s for me
Change-Id: I583381f0ee5494b8edf746b2329ac5751a9e5d86
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153006
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/157301
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
-rw-r--r-- | sc/source/core/tool/numformat.cxx | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/sc/source/core/tool/numformat.cxx b/sc/source/core/tool/numformat.cxx index 8240c1ac6e4f..8b8512339d43 100644 --- a/sc/source/core/tool/numformat.cxx +++ b/sc/source/core/tool/numformat.cxx @@ -25,6 +25,7 @@ #include <svl/numformat.hxx> #include <svl/zformat.hxx> #include <svl/languageoptions.hxx> +#include <optional> namespace sc { @@ -51,9 +52,13 @@ bool NumFmtUtil::isLatinScript( sal_uLong nFormat, ScDocument& rDoc ) aDecSep = ScGlobal::getLocaleData().getNumDecimalSep(); else { - LocaleDataWrapper aLocaleData( - comphelper::getProcessComponentContext(), LanguageTag(nFormatLang)); - aDecSep = aLocaleData.getNumDecimalSep(); + // LocaleDataWrapper can be expensive to construct, so cache the result for + // repeated calls + static std::optional<LocaleDataWrapper> localeCache; + if (!localeCache || localeCache->getLanguageTag().getLanguageType() != nFormatLang) + localeCache.emplace( + comphelper::getProcessComponentContext(), LanguageTag(nFormatLang)); + aDecSep = localeCache->getNumDecimalSep(); } SvtScriptType nScript = rDoc.GetStringScriptType(aDecSep); |