[Libreoffice-commits] .: Branch 'feature/gsoc-calc-perf2' - sc/source
Daniel Bankston
dbank at kemper.freedesktop.org
Sun Jul 8 09:28:25 PDT 2012
sc/source/core/tool/formularesult.cxx | 15 ++++---
sc/source/filter/xml/xmlcelli.cxx | 56 +++++++++++++++++----------
sc/source/filter/xml/xmlsubti.cxx | 69 ++++++----------------------------
sc/source/filter/xml/xmlsubti.hxx | 43 ++++-----------------
4 files changed, 68 insertions(+), 115 deletions(-)
New commits:
commit 9e639de0f9a7db8fb9cc48ca1e8036bb8f910811
Author: Daniel Bankston <daniel.e.bankston at gmail.com>
Date: Sun Jul 8 11:26:52 2012 -0500
Use cached formula results for matrices
Change-Id: Ia77a94184c3d598f16a2f51d996f4c7058d9e303
diff --git a/sc/source/core/tool/formularesult.cxx b/sc/source/core/tool/formularesult.cxx
index 9606899..3b94481 100644
--- a/sc/source/core/tool/formularesult.cxx
+++ b/sc/source/core/tool/formularesult.cxx
@@ -398,11 +398,16 @@ void ScFormulaResult::SetHybridDouble( double f )
ResetToDefaults();
if (mbToken && mpToken)
{
- String aString( GetString());
- String aFormula( GetHybridFormula());
- mpToken->DecRef();
- mpToken = new ScHybridCellToken( f, aString, aFormula);
- mpToken->IncRef();
+ if(GetType() == formula::svMatrixCell)
+ SetDouble(f);
+ else
+ {
+ String aString( GetString());
+ String aFormula( GetHybridFormula());
+ mpToken->DecRef();
+ mpToken = new ScHybridCellToken( f, aString, aFormula);
+ mpToken->IncRef();
+ }
}
else
{
diff --git a/sc/source/filter/xml/xmlcelli.cxx b/sc/source/filter/xml/xmlcelli.cxx
index 212f03e..67ca9c7 100644
--- a/sc/source/filter/xml/xmlcelli.cxx
+++ b/sc/source/filter/xml/xmlcelli.cxx
@@ -355,8 +355,7 @@ SvXMLImportContext *ScXMLTableRowCellContext::CreateChildContext( sal_uInt16 nPr
ScAddress aCellPos = rXMLImport.GetTables().GetCurrentCellPos();
- if( ((nCellType == util::NumberFormat::TEXT) || bFormulaTextResult) &&
- !rXMLImport.GetTables().IsPartOfMatrix(aCellPos.Col(), aCellPos.Row()) )
+ if( ((nCellType == util::NumberFormat::TEXT) || bFormulaTextResult) )
{
if (!bHasTextImport)
{
@@ -746,7 +745,7 @@ void ScXMLTableRowCellContext::AddTextCellToDoc( const ScAddress& rCurrentPos,
const SCCOL nCurrentCol, const ::boost::optional< rtl::OUString >& pOUText )
{
bool bDoIncrement = true;
- if( rXMLImport.GetTables().IsPartOfMatrix(rCurrentPos.Col(), rCurrentPos.Row()) )
+ if( rXMLImport.GetTables().IsPartOfMatrix(rCurrentPos) )
{
ScBaseCell* pCell = rXMLImport.GetDocument()->GetCell( rCurrentPos );
bDoIncrement = ( pCell && pCell->GetCellType() == CELLTYPE_FORMULA );
@@ -761,6 +760,7 @@ void ScXMLTableRowCellContext::AddTextCellToDoc( const ScAddress& rCurrentPos,
pFCell->SetHybridString( *pOUText );
else
bDoIncrement = false;
+ pFCell->SetFormatType( nCellType );
pFCell->ResetDirty();
}
}
@@ -789,7 +789,7 @@ void ScXMLTableRowCellContext::AddTextCellToDoc( const ScAddress& rCurrentPos,
void ScXMLTableRowCellContext::AddNumberCellToDoc( const ScAddress& rCurrentPos )
{
- if( rXMLImport.GetTables().IsPartOfMatrix(rCurrentPos.Col(), rCurrentPos.Row()) )
+ if( rXMLImport.GetTables().IsPartOfMatrix(rCurrentPos) )
{
ScBaseCell* pCell = rXMLImport.GetDocument()->GetCell( rCurrentPos );
if ( pCell && pCell->GetCellType() == CELLTYPE_FORMULA )
@@ -996,15 +996,6 @@ void ScXMLTableRowCellContext::AddNonFormulaCells( const ScAddress& rCellPos )
}
}
-namespace{
-
-bool isErrOrNA(const rtl::OUString& rStr)
-{
- return (rStr.indexOf("Err:") > -1) || (rStr.indexOf("#N/A") > -1);
-}
-
-}
-
void ScXMLTableRowCellContext::AddNonMatrixFormulaCell( const ScAddress& rCellPos )
{
ScDocument* pDoc = rXMLImport.GetDocument();
@@ -1015,10 +1006,6 @@ void ScXMLTableRowCellContext::AddNonMatrixFormulaCell( const ScAddress& rCellPo
::boost::scoped_ptr<ScExternalRefManager::ApiGuard> pExtRefGuard;
pExtRefGuard.reset(new ScExternalRefManager::ApiGuard(pDoc));
- //if this is an "Err:###" or "#N/A" then use text:p value
- if( bFormulaTextResult && pOUTextContent && isErrOrNA(*pOUTextContent) )
- pOUTextValue.reset(*pOUTextContent);
-
ScBaseCell* pNewCell = NULL;
if ( !aText.isEmpty() )
@@ -1065,6 +1052,15 @@ void ScXMLTableRowCellContext::AddNonMatrixFormulaCell( const ScAddress& rCellPo
}
}
+namespace{
+
+bool isErrOrNA(const rtl::OUString& rStr)
+{
+ return (rStr.indexOf("Err:") > -1) || (rStr.indexOf("#N/A") > -1);
+}
+
+}
+
void ScXMLTableRowCellContext::AddFormulaCell( const ScAddress& rCellPos )
{
if( cellExists(rCellPos) )
@@ -1072,9 +1068,13 @@ void ScXMLTableRowCellContext::AddFormulaCell( const ScAddress& rCellPos )
SetContentValidation( rCellPos );
OSL_ENSURE(((nColsRepeated == 1) && (nRepeatedRows == 1)), "repeated cells with formula not possible now");
rXMLImport.GetStylesImportHelper()->AddCell(rCellPos);
- if (!bIsMatrix)
- AddNonMatrixFormulaCell( rCellPos );
- else
+
+ //if this is an "Err:###" or "#N/A" then use text:p value
+ if( bFormulaTextResult && pOUTextContent && isErrOrNA(*pOUTextContent) )
+ pOUTextValue.reset(*pOUTextContent);
+
+ //add matrix
+ if(bIsMatrix)
{
if (nMatrixCols > 0 && nMatrixRows > 0)
{
@@ -1083,8 +1083,24 @@ void ScXMLTableRowCellContext::AddFormulaCell( const ScAddress& rCellPos )
rCellPos.Col() + nMatrixCols - 1,
rCellPos.Row() + nMatrixRows - 1,
pOUFormula->first, pOUFormula->second, eGrammar);
+
+ //add the cached formula result of the first matrix position
+ ScFormulaCell* pFCell =
+ static_cast<ScFormulaCell*>( rXMLImport.GetDocument()->GetCell(rCellPos) );
+ if(pFCell)
+ {
+ if( bFormulaTextResult && pOUTextValue && !pOUTextValue->isEmpty() )
+ pFCell->SetHybridString( *pOUTextValue );
+ else
+ pFCell->SetHybridDouble( fValue );
+ pFCell->SetFormatType( nCellType );
+ pFCell->ResetDirty();
+ }
}
}
+ else
+ AddNonMatrixFormulaCell( rCellPos );
+
SetAnnotation( rCellPos );
SetDetectiveObj( rCellPos );
SetCellRangeSource( rCellPos );
diff --git a/sc/source/filter/xml/xmlsubti.cxx b/sc/source/filter/xml/xmlsubti.cxx
index 7825bbf..c5a5eeb 100644
--- a/sc/source/filter/xml/xmlsubti.cxx
+++ b/sc/source/filter/xml/xmlsubti.cxx
@@ -207,18 +207,7 @@ void ScMyTables::DeleteTable()
rImport.GetStylesImportHelper()->SetStylesToRanges();
rImport.SetStylesToRangesFinished();
- //#i48793#; has to be set before protection
- if (!aMatrixRangeList.empty())
- {
- ScMyMatrixRangeList::iterator aItr = aMatrixRangeList.begin();
- ScMyMatrixRangeList::iterator aEndItr = aMatrixRangeList.end();
- while(aItr != aEndItr)
- {
- SetMatrix(aItr->aScRange, aItr->sFormula, aItr->sFormulaNmsp, aItr->eGrammar);
- ++aItr;
- }
- aMatrixRangeList.clear();
- }
+ maMatrixRangeList.RemoveAll();
if (rImport.GetDocument() && maProtectionData.mbProtected)
{
@@ -294,62 +283,30 @@ void ScMyTables::AddMatrixRange(
nStartColumn, nStartRow, maCurrentCellPos.Tab(),
nEndColumn, nEndRow, maCurrentCellPos.Tab()
);
- ScMatrixRange aMRange(aScRange, rFormula, rFormulaNmsp, eGrammar);
- aMatrixRangeList.push_back(aMRange);
-}
-bool ScMyTables::IsPartOfMatrix(const SCCOL nColumn, const SCROW nRow)
-{
- bool bResult(false);
- if (!aMatrixRangeList.empty())
- {
- ScMyMatrixRangeList::iterator aItr(aMatrixRangeList.begin());
- ScMyMatrixRangeList::iterator aEndItr(aMatrixRangeList.end());
- bool bReady(false);
- while(!bReady && aItr != aEndItr)
- {
- if (maCurrentCellPos.Tab() > aItr->aScRange.aStart.Tab())
- {
- OSL_FAIL("should never hapen, because the list should be cleared in DeleteTable");
- aItr = aMatrixRangeList.erase(aItr);
- }
- else if ((nRow > aItr->aScRange.aEnd.Row()) && (nColumn > aItr->aScRange.aEnd.Col()))
- {
- SetMatrix(aItr->aScRange, aItr->sFormula, aItr->sFormulaNmsp, aItr->eGrammar);
- aItr = aMatrixRangeList.erase(aItr);
- }
- else if (nColumn < aItr->aScRange.aStart.Col())
- bReady = true;
- else if ( nColumn >= aItr->aScRange.aStart.Col() && nColumn <= aItr->aScRange.aEnd.Col() &&
- nRow >= aItr->aScRange.aStart.Row() && nRow <= aItr->aScRange.aEnd.Row() )
- {
- bReady = true;
- bResult = true;
- }
- else
- ++aItr;
- }
- }
- return bResult;
-}
+ maMatrixRangeList.Append(aScRange);
-void ScMyTables::SetMatrix(const ScRange& rScRange, const rtl::OUString& rFormula,
- const rtl::OUString& rFormulaNmsp, const formula::FormulaGrammar::Grammar eGrammar)
-{
ScDocument* pDoc = rImport.GetDocument();
ScMarkData aMark;
- aMark.SetMarkArea( rScRange );
- aMark.SelectTable( rScRange.aStart.Tab(), sal_True );
+ aMark.SetMarkArea( aScRange );
+ aMark.SelectTable( aScRange.aStart.Tab(), sal_True );
ScTokenArray* pCode = new ScTokenArray;
pCode->AddStringXML( rFormula );
if( (eGrammar == formula::FormulaGrammar::GRAM_EXTERNAL) && !rFormulaNmsp.isEmpty() )
pCode->AddStringXML( rFormulaNmsp );
pDoc->InsertMatrixFormula(
- rScRange.aStart.Col(), rScRange.aStart.Row(),
- rScRange.aEnd.Col(), rScRange.aEnd.Row(),
+ aScRange.aStart.Col(), aScRange.aStart.Row(),
+ aScRange.aEnd.Col(), aScRange.aEnd.Row(),
aMark, EMPTY_STRING, pCode, eGrammar );
delete pCode;
pDoc->IncXMLImportedFormulaCount( rFormula.getLength() );
}
+bool ScMyTables::IsPartOfMatrix(const ScAddress& rScAddress) const
+{
+ if (!maMatrixRangeList.empty())
+ return maMatrixRangeList.In(rScAddress);
+ return false;
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/filter/xml/xmlsubti.hxx b/sc/source/filter/xml/xmlsubti.hxx
index 3f98af9..e080cfd 100644
--- a/sc/source/filter/xml/xmlsubti.hxx
+++ b/sc/source/filter/xml/xmlsubti.hxx
@@ -40,28 +40,10 @@
#include "XMLTableShapeResizer.hxx"
#include "formula/grammar.hxx"
#include "tabprotection.hxx"
-
-#include <vector>
-#include <list>
-#include <boost/ptr_container/ptr_vector.hpp>
+#include "rangelst.hxx"
class ScXMLImport;
-struct ScMatrixRange
-{
- rtl::OUString sFormula;
- rtl::OUString sFormulaNmsp;
- formula::FormulaGrammar::Grammar eGrammar;
- ScRange aScRange;
- ScMatrixRange(const ScRange& rScRange, const rtl::OUString& rFormula, const rtl::OUString& rFormulaNmsp, const formula::FormulaGrammar::Grammar eGrammarP) :
- sFormula(rFormula),
- sFormulaNmsp(rFormulaNmsp),
- eGrammar(eGrammarP),
- aScRange(rScRange)
- {
- }
-};
-
struct ScXMLTabProtectionData
{
::rtl::OUString maPassword;
@@ -77,8 +59,6 @@ struct ScXMLTabProtectionData
class ScMyTables
{
private:
- typedef std::list<ScMatrixRange> ScMyMatrixRangeList;
-
ScXMLImport& rImport;
ScMyOLEFixer aFixupOLEs;
@@ -89,8 +69,8 @@ private:
::com::sun::star::uno::Reference < ::com::sun::star::drawing::XShapes > xShapes;
rtl::OUString sCurrentSheetName;
ScAddress maCurrentCellPos;
+ ScRangeList maMatrixRangeList;
ScXMLTabProtectionData maProtectionData;
- ScMyMatrixRangeList aMatrixRangeList;
sal_Int32 nCurrentColStylePos;
sal_Int16 nCurrentDrawPage;
sal_Int16 nCurrentXShapes;
@@ -132,18 +112,13 @@ public:
const rtl::OUString &rRangeList);
void AddMatrixRange( const SCCOL nStartColumn,
- const SCROW nStartRow,
- const SCCOL nEndColumn,
- const SCROW nEndRow,
- const rtl::OUString& rFormula,
- const rtl::OUString& rFormulaNmsp,
- const formula::FormulaGrammar::Grammar );
-
- bool IsPartOfMatrix( const SCCOL nColumn, const SCROW nRow);
- void SetMatrix( const ScRange& rScRange,
- const rtl::OUString& rFormula,
- const rtl::OUString& rFormulaNmsp,
- const formula::FormulaGrammar::Grammar );
+ const SCROW nStartRow,
+ const SCCOL nEndColumn,
+ const SCROW nEndRow,
+ const rtl::OUString& rFormula,
+ const rtl::OUString& rFormulaNmsp,
+ const formula::FormulaGrammar::Grammar );
+ bool IsPartOfMatrix( const ScAddress& rScAddress) const;
};
#endif
More information about the Libreoffice-commits
mailing list