sc/source/core/data/formulacell.cxx | 2 +- sc/source/core/data/global.cxx | 2 -- sc/source/core/inc/interpre.hxx | 10 ++-------- sc/source/core/tool/interpr4.cxx | 31 +------------------------------ 4 files changed, 4 insertions(+), 41 deletions(-)
New commits: commit 058e98ee2f4f8289d6b1d4c5110fdf271e788600 Author: Noel Grandin <[email protected]> AuthorDate: Fri Mar 6 16:42:27 2026 +0200 Commit: Noel Grandin <[email protected]> CommitDate: Sat Mar 7 11:13:19 2026 +0100 tdf#166226 speed up stack operations in ScInterpreter There is no need to allocate this separately. Shaves 10% off the load time here. Change-Id: Ie70b1cf78aee4689e7369a9320c29223a0f19877 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/201133 Reviewed-by: Noel Grandin <[email protected]> Tested-by: Jenkins diff --git a/sc/source/core/data/formulacell.cxx b/sc/source/core/data/formulacell.cxx index f19baa4274b2..020315a20c85 100644 --- a/sc/source/core/data/formulacell.cxx +++ b/sc/source/core/data/formulacell.cxx @@ -5033,7 +5033,7 @@ bool ScFormulaCell::InterpretFormulaGroupThreading(sc::FormulaLogger::GroupScope { context = aContextGetterGuard.GetInterpreterContextForThreadIdx(i); assert(!context->pInterpreter); - aInterpreters[i].reset(new ScInterpreter(this, rDocument, *context, mxGroup->mpTopCell->aPos, *pCode, true)); + aInterpreters[i].reset(new ScInterpreter(this, rDocument, *context, mxGroup->mpTopCell->aPos, *pCode)); context->pInterpreter = aInterpreters[i].get(); rDocument.SetupContextFromNonThreadedContext(*context, i); rThreadPool.pushTask(std::make_unique<Executor>(aTag, i, nThreadCount, &rDocument, context, mxGroup->mpTopCell->aPos, diff --git a/sc/source/core/data/global.cxx b/sc/source/core/data/global.cxx index 764c51c062ae..4e3202900b3b 100644 --- a/sc/source/core/data/global.cxx +++ b/sc/source/core/data/global.cxx @@ -16,7 +16,6 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ - #include <scitems.hxx> #include <svx/algitem.hxx> #include <editeng/brushitem.hxx> @@ -557,7 +556,6 @@ void ScGlobal::Clear() maInputHandlerFunctionNames.clear(); ScParameterClassification::Exit(); ScCompiler::DeInit(); - ScInterpreter::GlobalExit(); // Delete static Stack xEmptyBrushItem.reset(); xButtonBrushItem.reset(); diff --git a/sc/source/core/inc/interpre.hxx b/sc/source/core/inc/interpre.hxx index 58fc09fffbd3..706bc766d810 100644 --- a/sc/source/core/inc/interpre.hxx +++ b/sc/source/core/inc/interpre.hxx @@ -208,8 +208,6 @@ public: static void SetGlobalConfig(const ScCalcConfig& rConfig); static const ScCalcConfig& GetGlobalConfig(); - static void GlobalExit(); // called by ScGlobal::Clear() - /** Detect if string should be used as regular expression or wildcard expression or literal string. */ @@ -235,9 +233,6 @@ private: static ScCalcConfig& GetOrCreateGlobalConfig(); static ScCalcConfig *mpGlobalConfig; - static thread_local std::unique_ptr<ScTokenStack> pGlobalStack; - static thread_local bool bGlobalStackInUse; - ScCalcConfig maCalcConfig; formula::FormulaTokenIterator aCode; ScAddress aPos; @@ -253,8 +248,7 @@ private: ScFormulaCell* pMyFormulaCell; // the cell of this formula expression const formula::FormulaToken* pCur; // current token - ScTokenStack* pStackObj; // contains the stacks - const formula::FormulaToken ** pStack; // the current stack + const formula::FormulaToken* pStack[ MAXSTACK ]; // the current stack FormulaError nGlobalError; // global (local to this formula expression) error sal_uInt16 sp; // stack pointer sal_uInt16 maxsp; // the maximal used stack pointer @@ -1124,7 +1118,7 @@ private: public: ScInterpreter( ScFormulaCell* pCell, ScDocument& rDoc, ScInterpreterContext& rContext, - const ScAddress&, ScTokenArray&, bool bForGroupThreading = false ); + const ScAddress&, ScTokenArray& ); ~ScInterpreter(); // Used only for threaded formula-groups. diff --git a/sc/source/core/tool/interpr4.cxx b/sc/source/core/tool/interpr4.cxx index 7342222d3e04..0f5be10cefcd 100644 --- a/sc/source/core/tool/interpr4.cxx +++ b/sc/source/core/tool/interpr4.cxx @@ -80,9 +80,6 @@ using namespace formula; #define ADDIN_MAXSTRLEN 256 -thread_local std::unique_ptr<ScTokenStack> ScInterpreter::pGlobalStack; -thread_local bool ScInterpreter::bGlobalStackInUse = false; - // document access functions void ScInterpreter::ReplaceCell( ScAddress& rPos ) @@ -3799,7 +3796,7 @@ void ScInterpreter::ScTTT() } ScInterpreter::ScInterpreter( ScFormulaCell* pCell, ScDocument& rDoc, ScInterpreterContext& rContext, - const ScAddress& rPos, ScTokenArray& r, bool bForGroupThreading ) + const ScAddress& rPos, ScTokenArray& r ) : aCode(r) , aPos(rPos) , pArr(&r) @@ -3834,30 +3831,10 @@ ScInterpreter::ScInterpreter( ScFormulaCell* pCell, ScDocument& rDoc, ScInterpre } else bMatrixFormula = false; - - // Let's not use the global stack while formula-group-threading. - // as it complicates its life-cycle mgmt since for threading formula-groups, - // ScInterpreter is preallocated (in main thread) for each worker thread. - if (!bGlobalStackInUse && !bForGroupThreading) - { - bGlobalStackInUse = true; - if (!pGlobalStack) - pGlobalStack.reset(new ScTokenStack); - pStackObj = pGlobalStack.get(); - } - else - { - pStackObj = new ScTokenStack; - } - pStack = pStackObj->pPointer; } ScInterpreter::~ScInterpreter() { - if ( pStackObj == pGlobalStack.get() ) - bGlobalStackInUse = false; - else - delete pStackObj; } void ScInterpreter::Init( ScFormulaCell* pCell, const ScAddress& rPos, ScTokenArray& rTokArray ) @@ -3912,12 +3889,6 @@ void ScInterpreter::MergeCalcConfig() maCalcConfig.MergeDocumentSpecific( mrDoc.GetCalcConfig()); } -void ScInterpreter::GlobalExit() -{ - OSL_ENSURE(!bGlobalStackInUse, "who is still using the TokenStack?"); - pGlobalStack.reset(); -} - namespace { double applyImplicitIntersection(const sc::RangeMatrix& rMat, const ScAddress& rPos)
