summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@collabora.com>2013-11-04 22:52:26 -0500
committerKohei Yoshida <kohei.yoshida@collabora.com>2013-11-06 20:40:21 -0500
commit04532617c7d264411563db24dc359326cc18eda7 (patch)
tree694b89a01cedcbc069ae7ed9e6a3b246a968ebf5 /sc
parenta09f7fddb4e847b35e6d47a45403c649152dd671 (diff)
Avoid duplication of ScTokenArray during formula cell construction.
For slightly less overhead. Change-Id: Ie5861d585d6e22fbd19dfd57edfebae4f4504839
Diffstat (limited to 'sc')
-rw-r--r--sc/inc/documentimport.hxx2
-rw-r--r--sc/inc/formulacell.hxx9
-rw-r--r--sc/source/core/data/documentimport.cxx4
-rw-r--r--sc/source/core/data/formulacell.cxx48
-rw-r--r--sc/source/filter/oox/formulabuffer.cxx6
-rw-r--r--sc/source/filter/oox/worksheethelper.cxx2
6 files changed, 63 insertions, 8 deletions
diff --git a/sc/inc/documentimport.hxx b/sc/inc/documentimport.hxx
index d034292558a8..d2aa99411cfc 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 46a68c448eb1..c2e578b902ff 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 93b43b04e7d7..71387953e0ca 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 15c3b98a5147..b0ffb74fa2bf 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 3dde87b8824b..bc074a29330d 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 fb5eaddc1836..148118b953de 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()