diff options
author | Eike Rathke <erack@redhat.com> | 2022-08-02 22:34:46 +0200 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2022-08-03 00:08:18 +0200 |
commit | 86b2bfd34a4f07c54f03c8c8dfe48e0810834628 (patch) | |
tree | 98955eba0892909ad6ba21d1d9faf0a7c26c9761 /sc | |
parent | 8dc76b13458fac1a30787f8bbab117a4a9508ab5 (diff) |
Avoid multiple conversions to LanguageTag, specifically in loops
Change-Id: I47a969d7476df32e0c9d525d416467c59358d9ce
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137712
Reviewed-by: Eike Rathke <erack@redhat.com>
Tested-by: Jenkins
Diffstat (limited to 'sc')
-rw-r--r-- | sc/inc/addincol.hxx | 3 | ||||
-rw-r--r-- | sc/source/core/tool/addincol.cxx | 12 | ||||
-rw-r--r-- | sc/source/core/tool/compiler.cxx | 6 |
3 files changed, 12 insertions, 9 deletions
diff --git a/sc/inc/addincol.hxx b/sc/inc/addincol.hxx index 2602624da287..14af12006637 100644 --- a/sc/inc/addincol.hxx +++ b/sc/inc/addincol.hxx @@ -42,6 +42,7 @@ namespace com::sun::star::uno { class XInterface; } class SfxObjectShell; class ScUnoAddInFuncData; class ScFuncDesc; +class LanguageTag; typedef std::unordered_map< OUString, const ScUnoAddInFuncData* > ScAddInHashMap; @@ -123,7 +124,7 @@ public: const OString& GetHelpId() const { return sHelpId; } const ::std::vector< LocalizedName >& GetCompNames() const; - bool GetExcelName( LanguageType eDestLang, OUString& rRetExcelName, + bool GetExcelName( const LanguageTag& rDestLang, OUString& rRetExcelName, bool bFallbackToAny = true ) const; void SetFunction( const css::uno::Reference< css::reflection::XIdlMethod>& rNewFunc, diff --git a/sc/source/core/tool/addincol.cxx b/sc/source/core/tool/addincol.cxx index 7ccf8b6c5c32..ea2184233f62 100644 --- a/sc/source/core/tool/addincol.cxx +++ b/sc/source/core/tool/addincol.cxx @@ -138,13 +138,12 @@ void ScUnoAddInFuncData::SetCompNames( ::std::vector< ScUnoAddInFuncData::Locali bCompInitialized = true; } -bool ScUnoAddInFuncData::GetExcelName( LanguageType eDestLang, OUString& rRetExcelName, bool bFallbackToAny ) const +bool ScUnoAddInFuncData::GetExcelName( const LanguageTag& rDestLang, OUString& rRetExcelName, bool bFallbackToAny ) const { const ::std::vector<LocalizedName>& rCompNames = GetCompNames(); if ( !rCompNames.empty() ) { - LanguageTag aLanguageTag( eDestLang); - const OUString& aSearch( aLanguageTag.getBcp47()); + const OUString& aSearch( rDestLang.getBcp47()); // First, check exact match without fallback overhead. ::std::vector<LocalizedName>::const_iterator itNames = std::find_if(rCompNames.begin(), rCompNames.end(), @@ -157,7 +156,7 @@ bool ScUnoAddInFuncData::GetExcelName( LanguageType eDestLang, OUString& rRetExc // Second, try match of fallback search with fallback locales, // appending also 'en-US' and 'en' to search if not queried. - ::std::vector< OUString > aFallbackSearch( aLanguageTag.getFallbackStrings( true)); + ::std::vector< OUString > aFallbackSearch( rDestLang.getFallbackStrings( true)); if (aSearch != "en-US") { aFallbackSearch.emplace_back("en-US"); @@ -582,7 +581,7 @@ bool ScUnoAddInCollection::GetExcelName( const OUString& rCalcName, { const ScUnoAddInFuncData* pFuncData = GetFuncData( rCalcName ); if ( pFuncData ) - return pFuncData->GetExcelName( eDestLang, rRetExcelName); + return pFuncData->GetExcelName( LanguageTag( eDestLang), rRetExcelName); return false; } @@ -770,6 +769,7 @@ void ScUnoAddInCollection::ReadFromAddIn( const uno::Reference<uno::XInterface>& if ( !pEnglishHashMap ) pEnglishHashMap.reset( new ScAddInHashMap ); + const LanguageTag aEnglishLanguageTag(LANGUAGE_ENGLISH_US); const uno::Reference<reflection::XIdlMethod>* pArray = aMethods.getConstArray(); for (tools::Long nFuncPos=0; nFuncPos<nNewCount; nFuncPos++) { @@ -932,7 +932,7 @@ void ScUnoAddInCollection::ReadFromAddIn( const uno::Reference<uno::XInterface>& pData ); OUString aEnglishName; - if (!pData->GetExcelName( LANGUAGE_ENGLISH_US, aEnglishName, false /*bFallbackToAny*/)) + if (!pData->GetExcelName( aEnglishLanguageTag, aEnglishName, false /*bFallbackToAny*/)) SAL_WARN("sc.core", "no English name for " << aLocalName << " " << aFuncName); else { diff --git a/sc/source/core/tool/compiler.cxx b/sc/source/core/tool/compiler.cxx index 14ae448f06b9..0de38ad001b2 100644 --- a/sc/source/core/tool/compiler.cxx +++ b/sc/source/core/tool/compiler.cxx @@ -148,6 +148,7 @@ void ScCompiler::fillFromAddInCollectionUpperName( const NonConstOpCodeMapPtr& x void ScCompiler::fillFromAddInCollectionEnglishName( const NonConstOpCodeMapPtr& xMap ) const { + const LanguageTag aEnglishLanguageTag(LANGUAGE_ENGLISH_US); ScUnoAddInCollection* pColl = ScGlobal::GetAddInCollection(); tools::Long nCount = pColl->GetFuncCount(); for (tools::Long i=0; i < nCount; ++i) @@ -156,7 +157,7 @@ void ScCompiler::fillFromAddInCollectionEnglishName( const NonConstOpCodeMapPtr& if (pFuncData) { OUString aName; - if (pFuncData->GetExcelName( LANGUAGE_ENGLISH_US, aName)) + if (pFuncData->GetExcelName( aEnglishLanguageTag, aName)) xMap->putExternalSoftly( aName, pFuncData->GetOriginalName()); else xMap->putExternalSoftly( pFuncData->GetUpperName(), @@ -5505,6 +5506,7 @@ void ScCompiler::fillAddInToken(::std::vector< css::sheet::FormulaOpCodeMapEntry sheet::FormulaOpCodeMapEntry aEntry; aEntry.Token.OpCode = ocExternal; + const LanguageTag aEnglishLanguageTag(LANGUAGE_ENGLISH_US); ScUnoAddInCollection* pColl = ScGlobal::GetAddInCollection(); const tools::Long nCount = pColl->GetFuncCount(); for (tools::Long i=0; i < nCount; ++i) @@ -5515,7 +5517,7 @@ void ScCompiler::fillAddInToken(::std::vector< css::sheet::FormulaOpCodeMapEntry if ( _bIsEnglish ) { OUString aName; - if (pFuncData->GetExcelName( LANGUAGE_ENGLISH_US, aName)) + if (pFuncData->GetExcelName( aEnglishLanguageTag, aName)) aEntry.Name = aName; else aEntry.Name = pFuncData->GetUpperName(); |