Kaydet (Commit) 04532617 authored tarafından Kohei Yoshida's avatar Kohei Yoshida

Avoid duplication of ScTokenArray during formula cell construction.

For slightly less overhead.

Change-Id: Ie5861d585d6e22fbd19dfd57edfebae4f4504839
üst a09f7fdd
...@@ -67,7 +67,7 @@ public: ...@@ -67,7 +67,7 @@ public:
void setStringCell(const ScAddress& rPos, const OUString& rStr); void setStringCell(const ScAddress& rPos, const OUString& rStr);
void setEditCell(const ScAddress& rPos, EditTextObject* pEditText); 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 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 setFormulaCell(const ScAddress& rPos, ScFormulaCell* pCell);
void setMatrixCells( void setMatrixCells(
......
...@@ -153,6 +153,15 @@ public: ...@@ -153,6 +153,15 @@ public:
ScFormulaCell( ScDocument* pDoc, const ScAddress& rPos ); 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, ScFormulaCell( ScDocument* pDoc, const ScAddress& rPos, const ScTokenArray& rArray,
const formula::FormulaGrammar::Grammar eGrammar = formula::FormulaGrammar::GRAM_DEFAULT, const formula::FormulaGrammar::Grammar eGrammar = formula::FormulaGrammar::GRAM_DEFAULT,
sal_uInt8 cMatInd = MM_NONE ); sal_uInt8 cMatInd = MM_NONE );
......
...@@ -202,7 +202,7 @@ void ScDocumentImport::setFormulaCell( ...@@ -202,7 +202,7 @@ void ScDocumentImport::setFormulaCell(
rCells.set(pBlockPos->miCellPos, rPos.Row(), new ScFormulaCell(&mpImpl->mrDoc, rPos, rFormula, eGrammar)); 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()); ScTable* pTab = mpImpl->mrDoc.FetchTable(rPos.Tab());
if (!pTab) if (!pTab)
...@@ -216,7 +216,7 @@ void ScDocumentImport::setFormulaCell(const ScAddress& rPos, const ScTokenArray& ...@@ -216,7 +216,7 @@ void ScDocumentImport::setFormulaCell(const ScAddress& rPos, const ScTokenArray&
sc::CellStoreType& rCells = pTab->aCol[rPos.Col()].maCells; sc::CellStoreType& rCells = pTab->aCol[rPos.Col()].maCells;
pBlockPos->miCellPos = 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) void ScDocumentImport::setFormulaCell(const ScAddress& rPos, ScFormulaCell* pCell)
......
...@@ -486,6 +486,54 @@ ScFormulaCell::ScFormulaCell( ScDocument* pDoc, const ScAddress& rPos, ...@@ -486,6 +486,54 @@ ScFormulaCell::ScFormulaCell( ScDocument* pDoc, const ScAddress& rPos,
pCode = new ScTokenArray; pCode = new ScTokenArray;
} }
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( ScFormulaCell::ScFormulaCell(
ScDocument* pDoc, const ScAddress& rPos, const ScTokenArray& rArray, ScDocument* pDoc, const ScAddress& rPos, const ScTokenArray& rArray,
const FormulaGrammar::Grammar eGrammar, sal_uInt8 cMatInd ) : const FormulaGrammar::Grammar eGrammar, sal_uInt8 cMatInd ) :
......
...@@ -27,8 +27,6 @@ ...@@ -27,8 +27,6 @@
#include "externalrefmgr.hxx" #include "externalrefmgr.hxx"
#include "oox/token/tokens.hxx" #include "oox/token/tokens.hxx"
#include <boost/scoped_ptr.hpp>
using namespace com::sun::star; using namespace com::sun::star;
using namespace ::com::sun::star::uno; using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::table; using namespace ::com::sun::star::table;
...@@ -99,11 +97,11 @@ void FormulaBuffer::applyCellFormulas( const std::vector< TokenAddressItem >& rV ...@@ -99,11 +97,11 @@ void FormulaBuffer::applyCellFormulas( const std::vector< TokenAddressItem >& rV
ScExternalRefManager::ApiGuard aExtRefGuard(&rDoc.getDoc()); ScExternalRefManager::ApiGuard aExtRefGuard(&rDoc.getDoc());
ScCompiler aCompiler(&rDoc.getDoc(), aPos); ScCompiler aCompiler(&rDoc.getDoc(), aPos);
aCompiler.SetGrammar(formula::FormulaGrammar::GRAM_ENGLISH_XL_OOX); 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) if (!pCode)
continue; continue;
rDoc.setFormulaCell(aPos, *pCode); rDoc.setFormulaCell(aPos, pCode);
} }
} }
......
...@@ -1583,7 +1583,7 @@ void WorksheetHelper::putFormulaTokens( const CellAddress& rAddress, const ApiTo ...@@ -1583,7 +1583,7 @@ void WorksheetHelper::putFormulaTokens( const CellAddress& rAddress, const ApiTo
ScAddress aCellPos; ScAddress aCellPos;
ScUnoConversion::FillScAddress( aCellPos, rAddress ); ScUnoConversion::FillScAddress( aCellPos, rAddress );
ScTokenConversion::ConvertToTokenArray(rDoc.getDoc(), aTokenArray, rTokens); ScTokenConversion::ConvertToTokenArray(rDoc.getDoc(), aTokenArray, rTokens);
rDoc.setFormulaCell(aCellPos, aTokenArray); rDoc.setFormulaCell(aCellPos, new ScTokenArray(aTokenArray));
} }
void WorksheetHelper::initializeWorksheetImport() void WorksheetHelper::initializeWorksheetImport()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment