sc/inc/interpretercontext.hxx | 11 +++++++++++ sc/source/core/data/dociter.cxx | 2 +- sc/source/core/data/document.cxx | 2 +- sc/source/core/tool/interpr4.cxx | 2 +- sc/source/core/tool/interpr6.cxx | 2 +- sc/source/core/tool/interpretercontext.cxx | 19 +++++++++++++++++++ 6 files changed, 34 insertions(+), 4 deletions(-)
New commits: commit c2d8341ee392949274b901abfd44d9645d2e4e36 Author: Dennis Francis <dennis.fran...@collabora.com> AuthorDate: Tue Oct 15 08:32:22 2019 +0530 Commit: Dennis Francis <dennis.fran...@collabora.com> CommitDate: Thu Oct 17 08:09:30 2019 +0200 Cache last used number-format-type in interpreter-context if in cpu-threaded mode so that we can avoid the unnecessary locked SvNumberFormatter::GetType() calls (Mapping between NF index and NF-type does not change while formula-group-threading is running). Change-Id: I648bc08c885da845f0b09cd57013cc1c23e01a61 Reviewed-on: https://gerrit.libreoffice.org/80848 Tested-by: Jenkins Reviewed-by: Dennis Francis <dennis.fran...@collabora.com> diff --git a/sc/inc/interpretercontext.hxx b/sc/inc/interpretercontext.hxx index b46a23f4e6a0..4ed6b3c66c4a 100644 --- a/sc/inc/interpretercontext.hxx +++ b/sc/inc/interpretercontext.hxx @@ -25,6 +25,7 @@ class ScDocument; class SvNumberFormatter; struct ScLookupCacheMap; class ScInterpreter; +enum class SvNumFormatType : sal_Int16; // SetNumberFormat() is not thread-safe, so calls to it need to be delayed to the main thread. struct DelayedSetNumberFormat @@ -34,6 +35,13 @@ struct DelayedSetNumberFormat sal_uInt32 mnNumberFormat; }; +struct NFIndexAndFmtType +{ + sal_uInt32 nIndex; + SvNumFormatType eType : 16; + bool bIsValid : 1; +}; + class ScInterpreterContextPool; struct ScInterpreterContext @@ -69,6 +77,8 @@ struct ScInterpreterContext return mpFormatter; } + SvNumFormatType GetNumberFormatType(sal_uInt32 nFIndex) const; + private: friend class ScInterpreterContextPool; void ResetTokens(); @@ -77,6 +87,7 @@ private: void ClearLookupCache(); void initFormatTable(); SvNumberFormatter* mpFormatter; + mutable NFIndexAndFmtType maNFTypeCache; }; class ScThreadedInterpreterContextGetterGuard; diff --git a/sc/source/core/data/dociter.cxx b/sc/source/core/data/dociter.cxx index 70362f342b21..3c8e369a575a 100644 --- a/sc/source/core/data/dociter.cxx +++ b/sc/source/core/data/dociter.cxx @@ -273,7 +273,7 @@ void ScValueIterator::GetCurNumFmtInfo( const ScInterpreterContext& rContext, Sv SCROW nCurRow = GetRow(); const ScColumn* pCol = &(pDoc->maTabs[mnTab])->aCol[mnCol]; nNumFmtIndex = pCol->GetNumberFormat(rContext, nCurRow); - nNumFmtType = rContext.GetFormatTable()->GetType( nNumFmtIndex ); + nNumFmtType = rContext.GetNumberFormatType( nNumFmtIndex ); bNumValid = true; } diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx index cc961b20b1a4..82224b23ecb3 100644 --- a/sc/source/core/data/document.cxx +++ b/sc/source/core/data/document.cxx @@ -3692,7 +3692,7 @@ void ScDocument::GetNumberFormatInfo( const ScInterpreterContext& rContext, SvNu if ( nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab] ) { nIndex = maTabs[nTab]->GetNumberFormat( rContext, rPos ); - nType = rContext.GetFormatTable()->GetType( nIndex ); + nType = rContext.GetNumberFormatType( nIndex ); } else { diff --git a/sc/source/core/tool/interpr4.cxx b/sc/source/core/tool/interpr4.cxx index 544a9ab11d0a..fc419d4a5935 100644 --- a/sc/source/core/tool/interpr4.cxx +++ b/sc/source/core/tool/interpr4.cxx @@ -223,7 +223,7 @@ double ScInterpreter::GetCellValueOrZero( const ScAddress& rPos, ScRefCellValue& { fValue = rCell.mfValue; nCurFmtIndex = pDok->GetNumberFormat( mrContext, rPos ); - nCurFmtType = pFormatter->GetType( nCurFmtIndex ); + nCurFmtType = mrContext.GetNumberFormatType( nCurFmtIndex ); if ( bCalcAsShown && fValue != 0.0 ) fValue = pDok->RoundValueAsShown( fValue, nCurFmtIndex, &mrContext ); } diff --git a/sc/source/core/tool/interpr6.cxx b/sc/source/core/tool/interpr6.cxx index 3a77be206acc..c2655fceb3d7 100644 --- a/sc/source/core/tool/interpr6.cxx +++ b/sc/source/core/tool/interpr6.cxx @@ -850,7 +850,7 @@ void ScInterpreter::IterateParameters( ScIterFunc eFunc, bool bTextAsZero ) nFuncFmtIndex = aAction.getNumberFormat(); } - nFuncFmtType = mrContext.GetFormatTable()->GetType( nFuncFmtIndex ); + nFuncFmtType = mrContext.GetNumberFormatType( nFuncFmtIndex ); } else { diff --git a/sc/source/core/tool/interpretercontext.cxx b/sc/source/core/tool/interpretercontext.cxx index b997effe13c4..77d2feadce6a 100644 --- a/sc/source/core/tool/interpretercontext.cxx +++ b/sc/source/core/tool/interpretercontext.cxx @@ -18,6 +18,7 @@ */ #include <interpretercontext.hxx> +#include <svl/zforlist.hxx> #include <document.hxx> #include <formula/token.hxx> @@ -68,6 +69,24 @@ void ScInterpreterContext::ClearLookupCache() mScLookupCache = nullptr; } +SvNumFormatType ScInterpreterContext::GetNumberFormatType(sal_uInt32 nFIndex) const +{ + if (!mpDoc->IsThreadedGroupCalcInProgress()) + { + return mpFormatter->GetType(nFIndex); + } + + if (maNFTypeCache.bIsValid && maNFTypeCache.nIndex == nFIndex) + { + return maNFTypeCache.eType; + } + + maNFTypeCache.nIndex = nFIndex; + maNFTypeCache.eType = mpFormatter->GetType(nFIndex); + maNFTypeCache.bIsValid = true; + return maNFTypeCache.eType; +} + /* ScInterpreterContextPool */ // Threaded version _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits