sc/source/core/tool/numformat.cxx | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-)
New commits: commit 8705b4ccaa7b8ea28eda95307c9add2b23e0716b Author: Caolán McNamara <caolan.mcnam...@collabora.com> AuthorDate: Tue Sep 26 21:09:02 2023 +0100 Commit: Caolán McNamara <caolan.mcnam...@collabora.com> CommitDate: Wed Sep 27 10:25:49 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/+/157298 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com> 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); }