sc/source/core/tool/numformat.cxx |   11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

New commits:
commit 79e723cde11d2eba6d45d6c89a3d3109062e675c
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Tue Jun 13 22:04:09 2023 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Wed Sep 27 08:00:21 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>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/157301
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>

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);

Reply via email to