summaryrefslogtreecommitdiff
path: root/formula/source
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2021-07-19 13:18:49 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2021-08-05 09:39:11 +0200
commit14cfff500e93f0d6cbf8412065feea85c01ea81d (patch)
tree76e3fb8fbf2b0d8a12c8406d8cf994ea6a37aaff /formula/source
parentd924ce30e0ca260682bd2aed192b8b1b2ca3e7c0 (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/source')
-rw-r--r--formula/source/core/api/FormulaCompiler.cxx83
-rw-r--r--formula/source/core/resource/core_resource.cxx3
2 files changed, 67 insertions, 19 deletions
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: */