From 2dbda86cca1301b81a4232a6f0c03559da5ed7f4 Mon Sep 17 00:00:00 2001 From: Luboš Luňák Date: Wed, 7 Nov 2018 16:01:30 +0100 Subject: make ScInterpreterContext also accessible without passing it around MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit E.g. ScModelObj::GetFormatter() can be rather deep in the call chain and it just doesn't make sense to pass ScInterpreterContext* to all the relevant places (and it's a question if it makes sense to pass it around at all, googling shows that thread_local is not really _that_ slow). Change-Id: I9114ef8a10d82a10968391718099edccde7a2663 Reviewed-on: https://gerrit.libreoffice.org/63184 Tested-by: Jenkins Reviewed-by: Luboš Luňák --- sc/inc/document.hxx | 11 +++++++++-- sc/source/core/data/documen8.cxx | 2 ++ sc/source/ui/unoobj/docuno.cxx | 3 ++- 3 files changed, 13 insertions(+), 3 deletions(-) (limited to 'sc') diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx index 6fe442954901..22ce96e010ef 100644 --- a/sc/inc/document.hxx +++ b/sc/inc/document.hxx @@ -275,9 +275,11 @@ const sal_uInt8 SC_DDE_IGNOREMODE = 255; /// For usage in FindDdeLink() struct ScDocumentThreadSpecific { ScRecursionHelper* pRecursionHelper; // information for recursive and iterative cell formulas + ScInterpreterContext* pContext; // references the context passed around for easier access - ScDocumentThreadSpecific() : - pRecursionHelper(nullptr) + ScDocumentThreadSpecific() + : pRecursionHelper(nullptr) + , pContext(nullptr) { } @@ -582,6 +584,11 @@ public: maInterpreterContext.mpFormatter = GetFormatTable(); return maInterpreterContext; } + // Uses thread_local. + ScInterpreterContext& GetThreadedContext() const + { + return IsThreadedGroupCalcInProgress() ? *maThreadSpecific.pContext : GetNonThreadedContext(); + } void SetupFromNonThreadedContext( ScInterpreterContext& threadedContext, int threadNumber ); void MergeBackIntoNonThreadedContext( ScInterpreterContext& threadedContext, int threadNumber ); void SetThreadedGroupCalcInProgress( bool set ) { (void)this; ScGlobal::bThreadedGroupCalcInProgress = set; } diff --git a/sc/source/core/data/documen8.cxx b/sc/source/core/data/documen8.cxx index 84df9ff48195..943be7200a68 100644 --- a/sc/source/core/data/documen8.cxx +++ b/sc/source/core/data/documen8.cxx @@ -415,10 +415,12 @@ const ScDocumentThreadSpecific& ScDocument::CalculateInColumnInThread( ScInterpr assert(IsThreadedGroupCalcInProgress()); + maThreadSpecific.pContext = &rContext; maThreadSpecific.SetupFromNonThreadedData(maNonThreaded); pTab->CalculateInColumnInThread(rContext, rTopPos.Col(), rTopPos.Row(), nLen, nThisThread, nThreadsTotal); assert(IsThreadedGroupCalcInProgress()); + maThreadSpecific.pContext = nullptr; return maThreadSpecific; } diff --git a/sc/source/ui/unoobj/docuno.cxx b/sc/source/ui/unoobj/docuno.cxx index 255e1a4ef3f4..22d75e24c58c 100644 --- a/sc/source/ui/unoobj/docuno.cxx +++ b/sc/source/ui/unoobj/docuno.cxx @@ -425,7 +425,8 @@ uno::Reference< uno::XAggregation> const & ScModelObj::GetFormatter() osl_atomic_increment( &m_refCount ); // we need a reference to SvNumberFormatsSupplierObj during queryInterface, // otherwise it'll be deleted - uno::Reference xFormatter(new SvNumberFormatsSupplierObj(pDocShell->GetDocument().GetFormatTable() )); + uno::Reference xFormatter( + new SvNumberFormatsSupplierObj(pDocShell->GetDocument().GetThreadedContext().GetFormatTable() )); { xNumberAgg.set(uno::Reference( xFormatter, uno::UNO_QUERY )); // extra block to force deletion of the temporary before setDelegator -- cgit