summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@gmail.com>2013-08-12 21:51:33 -0400
committerKohei Yoshida <kohei.yoshida@gmail.com>2013-08-12 21:52:28 -0400
commit7514df659bc12509880f7b74cd9a7820c96526fb (patch)
treea63eb3636758235048af0b78c0b32b57073e51a2 /sc
parent84c4c6a901a90dda1514071455db682a000b1934 (diff)
Compile token array only once per formula group.
Change-Id: I70694ee8834b1b2f2ebdfaa90582ccfb19db0210
Diffstat (limited to 'sc')
-rw-r--r--sc/inc/formulacell.hxx6
-rw-r--r--sc/source/core/data/formulacell.cxx41
-rw-r--r--sc/source/filter/excel/excform.cxx4
-rw-r--r--sc/source/filter/oox/formulabuffer.cxx3
-rw-r--r--sc/source/filter/orcus/interface.cxx2
5 files changed, 38 insertions, 18 deletions
diff --git a/sc/inc/formulacell.hxx b/sc/inc/formulacell.hxx
index 2e7c724c7257..985aebe5f4bf 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 1e120ee53bcd..f40e5a53bde5 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 e236dad91077..e9f5cf626327 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 e4277c0b714d..dce36d7feaae 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 495715f9644e..6c9512a2f360 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();