sc/source/core/tool/numformat.cxx | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
New commits: commit ce28e756c3dde56b59cf80c7e6f21f305e76eb25 Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Tue Jun 13 22:04:09 2023 +0200 Commit: Xisco Fauli <xiscofa...@libreoffice.org> CommitDate: Fri Jun 16 09:27:50 2023 +0200 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.gran...@collabora.co.uk> (cherry picked from commit e0ef3fed69864530da49cecb09fcc2fcc9acfeaa) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153087 Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org> 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);