diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2021-07-19 13:18:49 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2021-08-05 09:39:11 +0200 |
commit | 14cfff500e93f0d6cbf8412065feea85c01ea81d (patch) | |
tree | 76e3fb8fbf2b0d8a12c8406d8cf994ea6a37aaff /formula | |
parent | d924ce30e0ca260682bd2aed192b8b1b2ca3e7c0 (diff) |
Pass context and resource string down to boost::locale separately
because this is often on a hot path, and we can avoid the splitting and
joining of strings like this.
Change-Id: Ia36047209368ca53431178c2e8723a18cfe8260a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/119220
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'formula')
-rw-r--r-- | formula/inc/core_resource.hrc | 18 | ||||
-rw-r--r-- | formula/inc/core_resource.hxx | 4 | ||||
-rw-r--r-- | formula/inc/strings.hrc | 2 | ||||
-rw-r--r-- | formula/source/core/api/FormulaCompiler.cxx | 83 | ||||
-rw-r--r-- | formula/source/core/resource/core_resource.cxx | 3 |
5 files changed, 79 insertions, 31 deletions
diff --git a/formula/inc/core_resource.hrc b/formula/inc/core_resource.hrc index 01520f582b1b..ba09355ce284 100644 --- a/formula/inc/core_resource.hrc +++ b/formula/inc/core_resource.hrc @@ -22,7 +22,7 @@ #include <formula/compiler.hxx> #include <utility> -#define NC_(Context, String) reinterpret_cast<char const *>(Context "\004" u8##String) +#define NC_(Context, String) TranslateId(Context, reinterpret_cast<char const *>(u8##String)) /** These English names are used to store/load ODFF as of ODF v1.2. */ // NAMES CAN ONLY BE CHANGED WHEN PROVIDING BACKWARD AND FORWARD COMPATIBILITY @@ -31,7 +31,7 @@ // If there is a reason for another name for some function then add an // *additional* name to be recognized to sc/source/core/tool/compiler.cxx // ScCompiler::IsOpCode() in the if (mxSymbols->isODFF()) block. -const std::pair<const char*, int> RID_STRLIST_FUNCTION_NAMES_ENGLISH_ODFF[] = +const std::pair<const char *, int> RID_STRLIST_FUNCTION_NAMES_ENGLISH_ODFF[] = { { "IF" , SC_OPCODE_IF }, { "IFERROR" , SC_OPCODE_IF_ERROR }, @@ -472,7 +472,7 @@ const std::pair<const char*, int> RID_STRLIST_FUNCTION_NAMES_ENGLISH_ODFF[] = }; /** These function names are used in the OOXML XLSX import/export. */ -const std::pair<const char*, int> RID_STRLIST_FUNCTION_NAMES_ENGLISH_OOXML[] = +const std::pair<const char *, int> RID_STRLIST_FUNCTION_NAMES_ENGLISH_OOXML[] = { { "IF" , SC_OPCODE_IF }, { "IFERROR" , SC_OPCODE_IF_ERROR }, @@ -922,7 +922,7 @@ const std::pair<const char*, int> RID_STRLIST_FUNCTION_NAMES_ENGLISH_OOXML[] = // If there is a reason for another name for some function then add an // *additional* name to be recognized to sc/source/core/tool/compiler.cxx // ScCompiler::IsOpCode() in the else if (mxSymbols->isPODF()) block. -const std::pair<const char*, int> RID_STRLIST_FUNCTION_NAMES_ENGLISH_PODF[] = +const std::pair<const char *, int> RID_STRLIST_FUNCTION_NAMES_ENGLISH_PODF[] = { { "IF" , SC_OPCODE_IF }, { "IFERROR" , SC_OPCODE_IF_ERROR }, @@ -1373,7 +1373,7 @@ const std::pair<const char*, int> RID_STRLIST_FUNCTION_NAMES_ENGLISH_PODF[] = // If there is a reason for another name for some function then add an // *additional* name to be recognized to sc/source/core/tool/compiler.cxx // ScCompiler::IsOpCode(). -const std::pair<const char*, int> RID_STRLIST_FUNCTION_NAMES_ENGLISH_API[] = +const std::pair<const char *, int> RID_STRLIST_FUNCTION_NAMES_ENGLISH_API[] = { { "IF" , SC_OPCODE_IF }, { "IFERROR" , SC_OPCODE_IF_ERROR }, @@ -1822,7 +1822,7 @@ const std::pair<const char*, int> RID_STRLIST_FUNCTION_NAMES_ENGLISH_API[] = should match the [en-US] names of RID_STRLIST_FUNCTION_NAMES below. */ // As such they are a duplicate, but we can not have two string localizations // at the same time. -const std::pair<const char*, int> RID_STRLIST_FUNCTION_NAMES_ENGLISH[] = +const std::pair<const char *, int> RID_STRLIST_FUNCTION_NAMES_ENGLISH[] = { { "IF" , SC_OPCODE_IF }, { "IFERROR" , SC_OPCODE_IF_ERROR }, @@ -2272,7 +2272,7 @@ const std::pair<const char*, int> RID_STRLIST_FUNCTION_NAMES_ENGLISH[] = change has to be mentioned in the release notes, i.e. https://wiki.documentfoundation.org/ReleaseNotes/... */ -const std::pair<const char*, int> RID_STRLIST_FUNCTION_NAMES[] = +const std::pair<TranslateId, int> RID_STRLIST_FUNCTION_NAMES[] = { { NC_("RID_STRLIST_FUNCTION_NAMES", "IF") , SC_OPCODE_IF }, { NC_("RID_STRLIST_FUNCTION_NAMES", "IFERROR") , SC_OPCODE_IF_ERROR }, @@ -2711,10 +2711,10 @@ const std::pair<const char*, int> RID_STRLIST_FUNCTION_NAMES[] = { NC_("RID_STRLIST_FUNCTION_NAMES", "RAND.NV"), SC_OPCODE_RANDOM_NV }, { NC_("RID_STRLIST_FUNCTION_NAMES", "RANDBETWEEN.NV"), SC_OPCODE_RANDBETWEEN_NV }, - { nullptr, -1 } + { {}, -1 } }; -const std::pair<const char*, int> RID_STRLIST_FUNCTION_NAMES_SYMBOLS[] = +const std::pair<const char *, int> RID_STRLIST_FUNCTION_NAMES_SYMBOLS[] = { { "(" , SC_OPCODE_OPEN }, { ")" , SC_OPCODE_CLOSE }, diff --git a/formula/inc/core_resource.hxx b/formula/inc/core_resource.hxx index f8943f603999..f21d8fb25fd5 100644 --- a/formula/inc/core_resource.hxx +++ b/formula/inc/core_resource.hxx @@ -21,8 +21,8 @@ #include <rtl/ustring.hxx> #include <formula/formuladllapi.h> -#include <string_view> +#include <unotools/resmgr.hxx> -FORMULA_DLLPUBLIC OUString ForResId(std::string_view aId); +FORMULA_DLLPUBLIC OUString ForResId(TranslateId aId); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/formula/inc/strings.hrc b/formula/inc/strings.hrc index a54a2f259b95..7bdc7139799a 100644 --- a/formula/inc/strings.hrc +++ b/formula/inc/strings.hrc @@ -19,7 +19,7 @@ #pragma once -#define NC_(Context, String) reinterpret_cast<char const *>(Context "\004" u8##String) +#define NC_(Context, String) TranslateId(Context, reinterpret_cast<char const *>(u8##String)) #define STR_OPTIONAL NC_("STR_OPTIONAL", "(optional)") #define STR_REQUIRED NC_("STR_REQUIRED", "(required)") diff --git a/formula/source/core/api/FormulaCompiler.cxx b/formula/source/core/api/FormulaCompiler.cxx index f7174807f0f4..39a62ebdc1e4 100644 --- a/formula/source/core/api/FormulaCompiler.cxx +++ b/formula/source/core/api/FormulaCompiler.cxx @@ -155,7 +155,9 @@ class OpCodeList { public: - OpCodeList(bool bLocalized, const std::pair<const char*, int>* pSymbols, const FormulaCompiler::NonConstOpCodeMapPtr&, + OpCodeList(const std::pair<const char*, int>* pSymbols, const FormulaCompiler::NonConstOpCodeMapPtr&, + FormulaCompiler::SeparatorType = FormulaCompiler::SeparatorType::SEMICOLON_BASE ); + OpCodeList(const std::pair<TranslateId, int>* pSymbols, const FormulaCompiler::NonConstOpCodeMapPtr&, FormulaCompiler::SeparatorType = FormulaCompiler::SeparatorType::SEMICOLON_BASE ); private: @@ -164,15 +166,43 @@ private: private: FormulaCompiler::SeparatorType meSepType; - const std::pair<const char*, int>* mpSymbols; - bool mbLocalized; + const std::pair<const char*, int>* mpSymbols1; + const std::pair<TranslateId, int>* mpSymbols2; }; -OpCodeList::OpCodeList(bool bLocalized, const std::pair<const char*, int>* pSymbols, const FormulaCompiler::NonConstOpCodeMapPtr& xMap, +OpCodeList::OpCodeList(const std::pair<const char*, int>* pSymbols, const FormulaCompiler::NonConstOpCodeMapPtr& xMap, FormulaCompiler::SeparatorType eSepType) : meSepType(eSepType) - , mpSymbols(pSymbols) - , mbLocalized(bLocalized) + , mpSymbols1(pSymbols) + , mpSymbols2(nullptr) +{ + std::unique_ptr<CharClass> xCharClass( xMap->isEnglish() ? nullptr : createCharClassIfNonEnglishUI()); + const CharClass* pCharClass = xCharClass.get(); + if (meSepType == FormulaCompiler::SeparatorType::RESOURCE_BASE) + { + for (sal_uInt16 i = 0; i <= SC_OPCODE_LAST_OPCODE_ID; ++i) + { + putDefaultOpCode( xMap, i, pCharClass); + } + } + else + { + for (sal_uInt16 i = 0; i <= SC_OPCODE_LAST_OPCODE_ID; ++i) + { + OUString aOpStr; + if ( getOpCodeString( aOpStr, i) ) + xMap->putOpCode( aOpStr, OpCode(i), pCharClass); + else + putDefaultOpCode( xMap, i, pCharClass); + } + } +} + +OpCodeList::OpCodeList(const std::pair<TranslateId, int>* pSymbols, const FormulaCompiler::NonConstOpCodeMapPtr& xMap, + FormulaCompiler::SeparatorType eSepType) + : meSepType(eSepType) + , mpSymbols1(nullptr) + , mpSymbols2(pSymbols) { std::unique_ptr<CharClass> xCharClass( xMap->isEnglish() ? nullptr : createCharClassIfNonEnglishUI()); const CharClass* pCharClass = xCharClass.get(); @@ -235,18 +265,37 @@ bool OpCodeList::getOpCodeString( OUString& rStr, sal_uInt16 nOp ) void OpCodeList::putDefaultOpCode( const FormulaCompiler::NonConstOpCodeMapPtr& xMap, sal_uInt16 nOp, const CharClass* pCharClass ) { - const char* pKey = nullptr; - for (const std::pair<const char*, int>* pSymbol = mpSymbols; pSymbol->first; ++pSymbol) + OUString sKey; + if (mpSymbols1) { - if (nOp == pSymbol->second) + const char* pKey = nullptr; + for (const std::pair<const char*, int>* pSymbol = mpSymbols1; pSymbol->first; ++pSymbol) { - pKey = pSymbol->first; - break; + if (nOp == pSymbol->second) + { + pKey = pSymbol->first; + break; + } } + if (!pKey) + return; + sKey = OUString::createFromAscii(pKey); + } + else + { + TranslateId pKey; + for (const std::pair<TranslateId, int>* pSymbol = mpSymbols2; pSymbol->first; ++pSymbol) + { + if (nOp == pSymbol->second) + { + pKey = pSymbol->first; + break; + } + } + if (!pKey) + return; + sKey = ForResId(pKey); } - if (!pKey) - return; - OUString sKey = !mbLocalized ? OUString::createFromAscii(pKey) : ForResId(pKey); xMap->putOpCode(sKey, OpCode(nOp), pCharClass); } @@ -857,8 +906,8 @@ static void lcl_fillNativeSymbols( FormulaCompiler::NonConstOpCodeMapPtr& xMap, aSymbolMap.mxSymbolMap = std::make_shared<FormulaCompiler::OpCodeMap>( SC_OPCODE_LAST_OPCODE_ID + 1, true, FormulaGrammar::GRAM_NATIVE_UI); - OpCodeList aOpCodeListSymbols(false, RID_STRLIST_FUNCTION_NAMES_SYMBOLS, aSymbolMap.mxSymbolMap); - OpCodeList aOpCodeListNative(true, RID_STRLIST_FUNCTION_NAMES, aSymbolMap.mxSymbolMap); + OpCodeList aOpCodeListSymbols(RID_STRLIST_FUNCTION_NAMES_SYMBOLS, aSymbolMap.mxSymbolMap); + OpCodeList aOpCodeListNative(RID_STRLIST_FUNCTION_NAMES, aSymbolMap.mxSymbolMap); // No AddInMap for native core mapping. } @@ -953,7 +1002,7 @@ void FormulaCompiler::loadSymbols(const std::pair<const char*, int>* pSymbols, F // not Core rxMap = std::make_shared<OpCodeMap>( SC_OPCODE_LAST_OPCODE_ID + 1, eGrammar != FormulaGrammar::GRAM_ODFF, eGrammar ); - OpCodeList aOpCodeList(false, pSymbols, rxMap, eSepType); + OpCodeList aOpCodeList(pSymbols, rxMap, eSepType); fillFromAddInMap( rxMap, eGrammar); // Fill from collection for AddIns not already present. diff --git a/formula/source/core/resource/core_resource.cxx b/formula/source/core/resource/core_resource.cxx index 6a0943aba18f..d18432357984 100644 --- a/formula/source/core/resource/core_resource.cxx +++ b/formula/source/core/resource/core_resource.cxx @@ -16,9 +16,8 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#include <unotools/resmgr.hxx> #include <core_resource.hxx> -OUString ForResId(std::string_view aId) { return Translate::get(aId, Translate::Create("for")); } +OUString ForResId(TranslateId aId) { return Translate::get(aId, Translate::Create("for")); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |