sc/source/core/tool/numformat.cxx |   35 ++++++++++++++++++-----------------
 1 file changed, 18 insertions(+), 17 deletions(-)

New commits:
commit f1e7d9726b09aeb8f0aece65a98298f4ef9022ed
Author:     Caolán McNamara <caolan.mcnam...@collabora.com>
AuthorDate: Tue Sep 26 21:09:02 2023 +0100
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Wed Sep 27 14:00:33 2023 +0200

    perf: NumFmtUtil::isLatinScript doesn't need to copy OUString
    
    the original const OUString& from LocaleDataWrapper::getNumDecimalSep is
    sufficient
    
    aDecSep OUString dtor appeared as 2% of a sampled session
    
    Change-Id: Ib9408b32443eb6ba66a9dfc32a9179941c67bdf9
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/157299
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/sc/source/core/tool/numformat.cxx 
b/sc/source/core/tool/numformat.cxx
index 8b8512339d43..c69da6de4e3b 100644
--- a/sc/source/core/tool/numformat.cxx
+++ b/sc/source/core/tool/numformat.cxx
@@ -27,6 +27,23 @@
 #include <svl/languageoptions.hxx>
 #include <optional>
 
+namespace
+{
+    const OUString& getNumDecimalSep(const SvNumberformat& rFormat)
+    {
+        LanguageType nFormatLang = rFormat.GetLanguage();
+        if (nFormatLang == LANGUAGE_SYSTEM)
+            return ScGlobal::getLocaleData().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));
+        return localeCache->getNumDecimalSep();
+    }
+}
+
 namespace sc {
 
 bool NumFmtUtil::isLatinScript( const ScPatternAttr& rPat, ScDocument& rDoc )
@@ -45,23 +62,7 @@ bool NumFmtUtil::isLatinScript( sal_uLong nFormat, 
ScDocument& rDoc )
 
     // The standard format is all-latin if the decimal separator doesn't
     // have a different script type
-
-    OUString aDecSep;
-    LanguageType nFormatLang = pFormat->GetLanguage();
-    if (nFormatLang == LANGUAGE_SYSTEM)
-        aDecSep = ScGlobal::getLocaleData().getNumDecimalSep();
-    else
-    {
-        // 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);
+    SvtScriptType nScript = 
rDoc.GetStringScriptType(getNumDecimalSep(*pFormat));
     return (nScript == SvtScriptType::NONE || nScript == SvtScriptType::LATIN);
 }
 

Reply via email to