sc/inc/formulacell.hxx | 6 ++++ sc/source/core/data/formulacell.cxx | 41 +++++++++++++++++++-------------- sc/source/filter/excel/excform.cxx | 4 +++ sc/source/filter/oox/formulabuffer.cxx | 3 ++ sc/source/filter/orcus/interface.cxx | 2 + 5 files changed, 38 insertions(+), 18 deletions(-)
New commits: commit 7514df659bc12509880f7b74cd9a7820c96526fb Author: Kohei Yoshida <kohei.yosh...@gmail.com> Date: Mon Aug 12 21:51:33 2013 -0400 Compile token array only once per formula group. Change-Id: I70694ee8834b1b2f2ebdfaa90582ccfb19db0210 diff --git a/sc/inc/formulacell.hxx b/sc/inc/formulacell.hxx index 2e7c724..985aebe 100644 --- a/sc/inc/formulacell.hxx +++ b/sc/inc/formulacell.hxx @@ -51,13 +51,17 @@ struct SC_DLLPUBLIC ScFormulaCellGroup : boost::noncopyable ScTokenArray* mpCode; SCROW mnStart; // Start offset of that cell SCROW mnLength; // How many of these do we have ? - bool mbInvariant; + short mnFormatType; + bool mbInvariant:1; + bool mbSubTotal:1; sc::GroupCalcState meCalcState; ScFormulaCellGroup(); ~ScFormulaCellGroup(); void setCode( const ScTokenArray& rCode ); + void compileCode( + ScDocument& rDoc, const ScAddress& rPos, formula::FormulaGrammar::Grammar eGram ); }; inline void intrusive_ptr_add_ref(const ScFormulaCellGroup *p) diff --git a/sc/source/core/data/formulacell.cxx b/sc/source/core/data/formulacell.cxx index 1e120ee..f40e5a5 100644 --- a/sc/source/core/data/formulacell.cxx +++ b/sc/source/core/data/formulacell.cxx @@ -387,7 +387,9 @@ ScFormulaCellGroup::ScFormulaCellGroup() : mpCode(NULL), mnStart(0), mnLength(0), + mnFormatType(NUMBERFORMAT_NUMBER), mbInvariant(false), + mbSubTotal(false), meCalcState(sc::GroupCalcEnabled) { } @@ -405,6 +407,26 @@ void ScFormulaCellGroup::setCode( const ScTokenArray& rCode ) mpCode->GenHash(); } +void ScFormulaCellGroup::compileCode( + ScDocument& rDoc, const ScAddress& rPos, FormulaGrammar::Grammar eGram ) +{ + if (!mpCode) + return; + + if (mpCode->GetLen() && !mpCode->GetCodeError() && !mpCode->GetCodeLen()) + { + ScCompiler aComp(&rDoc, rPos, *mpCode); + aComp.SetGrammar(eGram); + mbSubTotal = aComp.CompileTokenArray(); + mnFormatType = aComp.GetNumFormatType(); + } + else + { + mpCode->Reset(); + mbSubTotal = mpCode->GetNextOpCodeRPN(ocSubTotal) != NULL; + } +} + // ============================================================================ ScFormulaCell::ScFormulaCell( ScDocument* pDoc, const ScAddress& rPos, @@ -500,12 +522,12 @@ ScFormulaCell::ScFormulaCell( pNextTrack(0), nSeenInIteration(0), cMatrixFlag ( cInd ), - nFormatType ( NUMBERFORMAT_NUMBER ), + nFormatType(xGroup->mnFormatType), bDirty(false), bChanged( false ), bRunning( false ), bCompile( false ), - bSubTotal( false ), + bSubTotal(xGroup->mbSubTotal), bIsIterCell( false ), bInChangeTrack( false ), bTableOpDirty( false ), @@ -513,21 +535,6 @@ ScFormulaCell::ScFormulaCell( mbNeedsNumberFormat( false ), aPos( rPos ) { - // UPN-Array generation - if( pCode->GetLen() && !pCode->GetCodeError() && !pCode->GetCodeLen() ) - { - ScCompiler aComp( pDocument, aPos, *pCode); - aComp.SetGrammar(eTempGrammar); - bSubTotal = aComp.CompileTokenArray(); - nFormatType = aComp.GetNumFormatType(); - } - else - { - pCode->Reset(); - if ( pCode->GetNextOpCodeRPN( ocSubTotal ) ) - bSubTotal = true; - } - if (bSubTotal) pDocument->AddSubTotalCell(this); } diff --git a/sc/source/filter/excel/excform.cxx b/sc/source/filter/excel/excform.cxx index e236dad..e9f5cf6 100644 --- a/sc/source/filter/excel/excform.cxx +++ b/sc/source/filter/excel/excform.cxx @@ -118,6 +118,10 @@ void ImportExcel::Formula( if (!xGroup) return; + if (xGroup->mnStart == aScPos.Row()) + // Generate code for the top cell only. + xGroup->compileCode(*pD, aScPos, formula::FormulaGrammar::GRAM_DEFAULT); + ScFormulaCell* pCell = new ScFormulaCell(pD, aScPos, xGroup); pD->EnsureTable(aScPos.Tab()); bool bInserted = pD->SetGroupFormulaCell(aScPos, pCell); diff --git a/sc/source/filter/oox/formulabuffer.cxx b/sc/source/filter/oox/formulabuffer.cxx index e4277c0..dce36d7 100644 --- a/sc/source/filter/oox/formulabuffer.cxx +++ b/sc/source/filter/oox/formulabuffer.cxx @@ -200,6 +200,9 @@ void FormulaBuffer::applySharedFormulas( sal_Int32 nTab ) ScAddress aPos; ScUnoConversion::FillScAddress(aPos, rAddr); + if (xGroup->mnStart == aPos.Row()) + // Generate code for the top cell only. + xGroup->compileCode(rDoc, aPos, formula::FormulaGrammar::GRAM_DEFAULT); ScFormulaCell* pCell = new ScFormulaCell(&rDoc, aPos, xGroup); bool bInserted = rDoc.SetGroupFormulaCell(aPos, pCell); diff --git a/sc/source/filter/orcus/interface.cxx b/sc/source/filter/orcus/interface.cxx index 495715f..6c9512a 100644 --- a/sc/source/filter/orcus/interface.cxx +++ b/sc/source/filter/orcus/interface.cxx @@ -387,6 +387,8 @@ void ScOrcusSheet::set_shared_formula( if (!xGroup) return; + // Generate code for the top cell only. + xGroup->compileCode(mrDoc.getDoc(), aPos, formula::FormulaGrammar::GRAM_DEFAULT); ScFormulaCell* pCell = new ScFormulaCell(&mrDoc.getDoc(), aPos, xGroup); mrDoc.setFormulaCell(aPos, pCell); cellInserted(); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits