Avoid duplication of ScTokenArray during formula cell construction.
For slightly less overhead.
Change-Id: Ie5861d585d6e22fbd19dfd57edfebae4f4504839
diff --git a/sc/inc/documentimport.hxx b/sc/inc/documentimport.hxx
index d034292..d2aa994 100644
--- a/sc/inc/documentimport.hxx
+++ b/sc/inc/documentimport.hxx
@@ -67,7 +67,7 @@ public:
void setStringCell(const ScAddress& rPos, const OUString& rStr);
void setEditCell(const ScAddress& rPos, EditTextObject* pEditText);
void setFormulaCell(const ScAddress& rPos, const OUString& rFormula, formula::FormulaGrammar::Grammar eGrammar);
void setFormulaCell(const ScAddress& rPos, const ScTokenArray& rArray);
void setFormulaCell(const ScAddress& rPos, ScTokenArray* pArray);
void setFormulaCell(const ScAddress& rPos, ScFormulaCell* pCell);
void setMatrixCells(
diff --git a/sc/inc/formulacell.hxx b/sc/inc/formulacell.hxx
index 46a68c4..c2e578b 100644
--- a/sc/inc/formulacell.hxx
+++ b/sc/inc/formulacell.hxx
@@ -153,6 +153,15 @@ public:
ScFormulaCell( ScDocument* pDoc, const ScAddress& rPos );
/**
* Transfer the ownership of the passed token array instance to the
* formula cell being constructed. The caller <i>must not</i> pass a NULL
* token array pointer.
*/
ScFormulaCell( ScDocument* pDoc, const ScAddress& rPos, ScTokenArray* pArray,
const formula::FormulaGrammar::Grammar eGrammar = formula::FormulaGrammar::GRAM_DEFAULT,
sal_uInt8 cMatInd = MM_NONE );
ScFormulaCell( ScDocument* pDoc, const ScAddress& rPos, const ScTokenArray& rArray,
const formula::FormulaGrammar::Grammar eGrammar = formula::FormulaGrammar::GRAM_DEFAULT,
sal_uInt8 cMatInd = MM_NONE );
diff --git a/sc/source/core/data/documentimport.cxx b/sc/source/core/data/documentimport.cxx
index 93b43b0..7138795 100644
--- a/sc/source/core/data/documentimport.cxx
+++ b/sc/source/core/data/documentimport.cxx
@@ -202,7 +202,7 @@ void ScDocumentImport::setFormulaCell(
rCells.set(pBlockPos->miCellPos, rPos.Row(), new ScFormulaCell(&mpImpl->mrDoc, rPos, rFormula, eGrammar));
}
void ScDocumentImport::setFormulaCell(const ScAddress& rPos, const ScTokenArray& rArray)
void ScDocumentImport::setFormulaCell(const ScAddress& rPos, ScTokenArray* pArray)
{
ScTable* pTab = mpImpl->mrDoc.FetchTable(rPos.Tab());
if (!pTab)
@@ -216,7 +216,7 @@ void ScDocumentImport::setFormulaCell(const ScAddress& rPos, const ScTokenArray&
sc::CellStoreType& rCells = pTab->aCol[rPos.Col()].maCells;
pBlockPos->miCellPos =
rCells.set(pBlockPos->miCellPos, rPos.Row(), new ScFormulaCell(&mpImpl->mrDoc, rPos, rArray));
rCells.set(pBlockPos->miCellPos, rPos.Row(), new ScFormulaCell(&mpImpl->mrDoc, rPos, pArray));
}
void ScDocumentImport::setFormulaCell(const ScAddress& rPos, ScFormulaCell* pCell)
diff --git a/sc/source/core/data/formulacell.cxx b/sc/source/core/data/formulacell.cxx
index 15c3b98..b0ffb74 100644
--- a/sc/source/core/data/formulacell.cxx
+++ b/sc/source/core/data/formulacell.cxx
@@ -487,6 +487,54 @@ ScFormulaCell::ScFormulaCell( ScDocument* pDoc, const ScAddress& rPos,
}
ScFormulaCell::ScFormulaCell(
ScDocument* pDoc, const ScAddress& rPos, ScTokenArray* pArray,
const FormulaGrammar::Grammar eGrammar, sal_uInt8 cMatInd ) :
eTempGrammar( eGrammar),
pCode(pArray),
pDocument( pDoc ),
pPrevious(0),
pNext(0),
pPreviousTrack(0),
pNextTrack(0),
nSeenInIteration(0),
cMatrixFlag ( cMatInd ),
nFormatType ( NUMBERFORMAT_NUMBER ),
bDirty( true ),
bChanged( false ),
bRunning( false ),
bCompile( false ),
bSubTotal( false ),
bIsIterCell( false ),
bInChangeTrack( false ),
bTableOpDirty( false ),
bNeedListening( false ),
mbNeedsNumberFormat( false ),
aPos( rPos )
{
assert(pArray); // Never pass a NULL pointer here.
// Generate RPN token array.
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);
pCode->GenHash();
}
ScFormulaCell::ScFormulaCell(
ScDocument* pDoc, const ScAddress& rPos, const ScTokenArray& rArray,
const FormulaGrammar::Grammar eGrammar, sal_uInt8 cMatInd ) :
eTempGrammar( eGrammar),
diff --git a/sc/source/filter/oox/formulabuffer.cxx b/sc/source/filter/oox/formulabuffer.cxx
index 3dde87b..bc074a2 100644
--- a/sc/source/filter/oox/formulabuffer.cxx
+++ b/sc/source/filter/oox/formulabuffer.cxx
@@ -27,8 +27,6 @@
#include "externalrefmgr.hxx"
#include "oox/token/tokens.hxx"
#include <boost/scoped_ptr.hpp>
using namespace com::sun::star;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::table;
@@ -99,11 +97,11 @@ void FormulaBuffer::applyCellFormulas( const std::vector< TokenAddressItem >& rV
ScExternalRefManager::ApiGuard aExtRefGuard(&rDoc.getDoc());
ScCompiler aCompiler(&rDoc.getDoc(), aPos);
aCompiler.SetGrammar(formula::FormulaGrammar::GRAM_ENGLISH_XL_OOX);
boost::scoped_ptr<ScTokenArray> pCode(aCompiler.CompileString(it->maTokenStr));
ScTokenArray* pCode = aCompiler.CompileString(it->maTokenStr);
if (!pCode)
continue;
rDoc.setFormulaCell(aPos, *pCode);
rDoc.setFormulaCell(aPos, pCode);
}
}
diff --git a/sc/source/filter/oox/worksheethelper.cxx b/sc/source/filter/oox/worksheethelper.cxx
index fb5eadd..148118b 100644
--- a/sc/source/filter/oox/worksheethelper.cxx
+++ b/sc/source/filter/oox/worksheethelper.cxx
@@ -1583,7 +1583,7 @@ void WorksheetHelper::putFormulaTokens( const CellAddress& rAddress, const ApiTo
ScAddress aCellPos;
ScUnoConversion::FillScAddress( aCellPos, rAddress );
ScTokenConversion::ConvertToTokenArray(rDoc.getDoc(), aTokenArray, rTokens);
rDoc.setFormulaCell(aCellPos, aTokenArray);
rDoc.setFormulaCell(aCellPos, new ScTokenArray(aTokenArray));
}
void WorksheetHelper::initializeWorksheetImport()