diff options
author | Daniel Bankston <daniel.e.bankston@gmail.com> | 2012-06-18 15:50:38 -0500 |
---|---|---|
committer | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2012-06-20 11:01:25 +0200 |
commit | f012dba24249f1a500613de0fabf4f847534da5c (patch) | |
tree | a2f0db5c1b425ace61d5f06e723bc7216b6ba5a0 /sc | |
parent | ade70c0e36bf8d8daf674ded0a4d23c422293000 (diff) |
Simplify table ODS import logic to improve performance
- Removed subtable import logic since sc core doesn't support it.
- Simplified the overall table import logic.
Should have an overall table import performance increase.
Change-Id: I79d27470321bf17f7ef16becd7cb6aa840491f80
Diffstat (limited to 'sc')
-rw-r--r-- | sc/source/filter/xml/xmlcoli.cxx | 1 | ||||
-rw-r--r-- | sc/source/filter/xml/xmlsubti.cxx | 263 | ||||
-rw-r--r-- | sc/source/filter/xml/xmlsubti.hxx | 61 |
3 files changed, 35 insertions, 290 deletions
diff --git a/sc/source/filter/xml/xmlcoli.cxx b/sc/source/filter/xml/xmlcoli.cxx index 9be1a1966b16..624fa1dbd518 100644 --- a/sc/source/filter/xml/xmlcoli.cxx +++ b/sc/source/filter/xml/xmlcoli.cxx @@ -167,7 +167,6 @@ void ScXMLTableColContext::EndElement() if ( sCellStyleName.isEmpty() ) sCellStyleName = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Default" )); - GetScImport().GetTables().AddColCount(nColCount); GetScImport().GetTables().AddColStyle(nColCount, sCellStyleName); } diff --git a/sc/source/filter/xml/xmlsubti.cxx b/sc/source/filter/xml/xmlsubti.cxx index 9eb1d1022a25..feb8435a985f 100644 --- a/sc/source/filter/xml/xmlsubti.cxx +++ b/sc/source/filter/xml/xmlsubti.cxx @@ -59,88 +59,8 @@ #include <memory> using ::std::auto_ptr; - -//------------------------------------------------------------------ - using namespace com::sun::star; -ScMyTableData::ScMyTableData(SCTAB nSheet, SCCOL nCol, SCROW nRow) - : maTableCellPos(nCol, nRow, nSheet), - nColsPerCol(nDefaultColCount, 1), - nRealCols(nDefaultColCount + 1, 0), - nRowsPerRow(nDefaultRowCount, 1), - nRealRows(nDefaultRowCount + 1, 0), - nChangedCols() -{ - for (sal_Int32 i = 0; i < 3; ++i) - nRealCols[i] = i; - for (sal_Int32 j = 0; j < 3; ++j) - nRealRows[j] = j; - - nSpannedCols = 1; - nColCount = 0; - nSubTableSpanned = 1; -} - -ScMyTableData::~ScMyTableData() -{ -} - -void ScMyTableData::AddRow() -{ - maTableCellPos.SetRow( maTableCellPos.Row() + 1 ); - if (static_cast<sal_uInt32>(maTableCellPos.Row()) >= nRowsPerRow.size()) - { - nRowsPerRow.resize(nRowsPerRow.size() + nDefaultRowCount, 1); - nRealRows.resize(nRowsPerRow.size() + nDefaultRowCount + 1, 0); - } - nRealRows[maTableCellPos.Row() + 1] = nRealRows[maTableCellPos.Row()] + nRowsPerRow[maTableCellPos.Row()]; -} - -void ScMyTableData::AddColumn() -{ - maTableCellPos.SetCol( maTableCellPos.Col() + 1 ); - if (static_cast<sal_uInt32>(maTableCellPos.Col()) >= nColsPerCol.size()) - { - nColsPerCol.resize(nColsPerCol.size() + nDefaultColCount, 1); - nRealCols.resize(nColsPerCol.size() + nDefaultColCount + 1, 0); - } - nRealCols[maTableCellPos.Col() + 1] = nRealCols[maTableCellPos.Col()] + nColsPerCol[maTableCellPos.Col()]; -} - -sal_Int32 ScMyTableData::GetRealCols(const sal_Int32 nIndex, const bool /* bIsNormal */) const -{ - return (nIndex < 0) ? 0 : nRealCols[nIndex]; -} - -sal_Int32 ScMyTableData::GetChangedCols(const sal_Int32 nFromIndex, const sal_Int32 nToIndex) const -{ - ScMysalIntList::const_iterator i(nChangedCols.begin()); - ScMysalIntList::const_iterator endi(nChangedCols.end()); - while ((i != endi) && ((*i < nToIndex) && !(*i >= nFromIndex))) - ++i; - if (i == endi) - return -1; - else - if ((*i >= nFromIndex) && (*i < nToIndex)) - return *i; - else - return -1; -} - -void ScMyTableData::SetChangedCols(const sal_Int32 nValue) -{ - ScMysalIntList::iterator i(nChangedCols.begin()); - ScMysalIntList::iterator endi(nChangedCols.end()); - while ((i != endi) && (*i < nValue)) - { - ++i; - } - if ((i == endi) || (*i != nValue)) - nChangedCols.insert(i, nValue); -} - -/*******************************************************************************************************************************/ ScXMLTabProtectionData::ScXMLTabProtectionData() : meHash1(PASSHASH_SHA1), @@ -154,11 +74,10 @@ ScXMLTabProtectionData::ScXMLTabProtectionData() : ScMyTables::ScMyTables(ScXMLImport& rTempImport) : rImport(rTempImport), aFixupOLEs(rTempImport), + maCellPos(ScAddress::INITIALIZE_INVALID), nCurrentColStylePos(0), nCurrentDrawPage( -1 ), - nCurrentXShapes( -1 ), - nCurrentSheet( -1 ), - pCurrentTab(NULL) + nCurrentXShapes( -1 ) { } @@ -196,22 +115,23 @@ void ScMyTables::NewSheet(const rtl::OUString& sTableName, const rtl::OUString& { nCurrentColStylePos = 0; sCurrentSheetName = sTableName; - maTables.clear(); - pCurrentTab = NULL; - ++nCurrentSheet; + //reset cols and rows for new sheet, but increment tab + maCellPos.SetCol(-1); + maCellPos.SetRow(-1); + maCellPos.SetTab(maCellPos.Tab() + 1); maProtectionData = rProtectData; ScDocument *pDoc = ScXMLConverter::GetScDocument(rImport.GetModel()); // The document contains one sheet when created. So for the first // sheet, we only need to set its name. - if (nCurrentSheet > 0) + if (maCellPos.Tab() > 0) pDoc->AppendTabOnLoad(sTableName); else - pDoc->SetTabNameOnLoad(nCurrentSheet, sTableName); + pDoc->SetTabNameOnLoad(maCellPos.Tab(), sTableName); rImport.SetTableStyle(sStyleName); - xCurrentSheet = getCurrentSheet(rImport.GetModel(), nCurrentSheet); + xCurrentSheet = getCurrentSheet(rImport.GetModel(), maCellPos.Tab()); if (xCurrentSheet.is()) { // We need to set the current cell range here regardless of @@ -220,10 +140,6 @@ void ScMyTables::NewSheet(const rtl::OUString& sTableName, const rtl::OUString& SetTableStyle(sStyleName); } } - - maTables.push_back(new ScMyTableData(nCurrentSheet)); - pCurrentTab = & maTables.back(); - pCurrentTab->SetSpannedCols(1); } void ScMyTables::SetTableStyle(const rtl::OUString& sStyleName) @@ -256,7 +172,7 @@ void ScMyTables::SetTableStyle(const rtl::OUString& sStyleName) pStyle->FillPropertySet(xProperties); ScSheetSaveData* pSheetData = ScModelObj::getImplementation(rImport.GetModel())->GetSheetSaveData(); - pSheetData->AddTableStyle( sStyleName, ScAddress( 0, 0, nCurrentSheet ) ); + pSheetData->AddTableStyle( sStyleName, ScAddress( 0, 0, maCellPos.Tab() ) ); } } } @@ -264,42 +180,10 @@ void ScMyTables::SetTableStyle(const rtl::OUString& sStyleName) } } -void ScMyTables::NewRow() -{ - size_t n = maTables.size(); - if (n <= 1) - return; - - if (pCurrentTab->GetRealRows(pCurrentTab->GetRow()) > - maTables[n-2].GetRowsPerRow(maTables[n-2].GetRow()) - 1) - { - if (GetRealScCellPos().Col() > 0) - rImport.GetStylesImportHelper()->InsertRow(GetRealScCellPos().Row(), nCurrentSheet, rImport.GetDocument()); - - for (size_t i = n - 1; i > 0; --i) - { - sal_Int32 nRow = maTables[i-1].GetRow(); - maTables[i-1].SetRowsPerRow( - nRow, - maTables[i-1].GetRowsPerRow(nRow) + 1); - - maTables[i-1].SetRealRows( - nRow + 1, - maTables[i-1].GetRealRows(nRow) + maTables[i-1].GetRowsPerRow(nRow)); - } - } -} - void ScMyTables::AddRow() { - pCurrentTab->AddRow(); - pCurrentTab->SetFirstColumn(); - sal_Int32 nRow = pCurrentTab->GetRow(); - if (nRow > 0) - NewRow(); - - pCurrentTab->SetRealRows( - nRow + 1, pCurrentTab->GetRealRows(nRow) + pCurrentTab->GetRowsPerRow(nRow)); + maCellPos.SetRow(maCellPos.Row() + 1); + maCellPos.SetCol(-1); //reset columns for new row } void ScMyTables::SetRowStyle(const rtl::OUString& rCellStyleName) @@ -307,69 +191,13 @@ void ScMyTables::SetRowStyle(const rtl::OUString& rCellStyleName) rImport.GetStylesImportHelper()->SetRowStyle(rCellStyleName); } -void ScMyTables::NewColumn(bool bIsCovered) -{ - if (bIsCovered) - return; - - sal_Int32 nColCount = pCurrentTab->GetColCount(); - sal_Int32 nSpannedCols = pCurrentTab->GetSpannedCols(); - if ( (nSpannedCols > nColCount) && - (pCurrentTab->GetRow() == 0) && - (pCurrentTab->GetColumn() == 0) ) - { - if (nColCount > 0) - { - sal_Int32 FirstColsSpanned(nSpannedCols / nColCount); - sal_Int32 LastColSpanned(FirstColsSpanned - + (nSpannedCols % nColCount)); - for (sal_Int32 i = 0; i < nColCount - 1; ++i) - { - pCurrentTab->SetColsPerCol(i, FirstColsSpanned); - pCurrentTab->SetRealCols(i + 1, pCurrentTab->GetRealCols(i) + FirstColsSpanned); - } - pCurrentTab->SetColsPerCol(nColCount - 1, LastColSpanned); - pCurrentTab->SetRealCols( - nColCount, pCurrentTab->GetRealCols(nColCount - 1) + LastColSpanned); - } - } - if (pCurrentTab->GetRealCols(pCurrentTab->GetColumn()) > nSpannedCols - 1) - { - if (pCurrentTab->GetRow() == 0) - { - rImport.GetStylesImportHelper()->InsertCol(GetRealScCellPos().Col(), nCurrentSheet, rImport.GetDocument()); - size_t n = maTables.size(); - for (size_t i = n - 1; i > 0; --i) - { - sal_Int32 nColPos = - maTables[i-1].GetColumn() + maTables[i].GetSpannedCols() - 1; - - maTables[i-1].SetColsPerCol(nColPos, - maTables[i-1].GetColsPerCol(nColPos) + - pCurrentTab->GetColsPerCol(pCurrentTab->GetColumn())); - - maTables[i-1].SetRealCols( - nColPos + 1, - maTables[i-1].GetRealCols(nColPos) + maTables[i-1].GetColsPerCol(nColPos)); - - maTables[i-1].SetChangedCols(nColPos); - } - } - } -} - void ScMyTables::AddColumn(bool bIsCovered) { - pCurrentTab->AddColumn(); - if (pCurrentTab->GetSubTableSpanned() > 1) - pCurrentTab->SetSubTableSpanned(pCurrentTab->GetSubTableSpanned() - 1); - else - { - NewColumn(bIsCovered); - sal_Int32 nCol = pCurrentTab->GetColumn(); - pCurrentTab->SetRealCols( - nCol + 1, pCurrentTab->GetRealCols(nCol) + pCurrentTab->GetColsPerCol(nCol)); - } + maCellPos.SetCol( maCellPos.Col() + 1 ); + //here only need to set column style if this is the first row and + //the cell is not covered. + if(maCellPos.Row() == 0 && !bIsCovered) + rImport.GetStylesImportHelper()->InsertCol(maCellPos.Col(), maCellPos.Tab(), rImport.GetDocument()); } void ScMyTables::UpdateRowHeights() @@ -418,21 +246,8 @@ void ScMyTables::DeleteTable() { ScXMLImport::MutexGuard aGuard(rImport); - nCurrentColStylePos = 0; - if (!maTables.empty()) - { - maTables.pop_back(); - if (!maTables.empty()) - pCurrentTab = &maTables.back(); - else - pCurrentTab = NULL; - } - - if (maTables.empty()) // only set the styles if all subtables are imported and the table is finished - { - rImport.GetStylesImportHelper()->SetStylesToRanges(); - rImport.SetStylesToRangesFinished(); - } + rImport.GetStylesImportHelper()->SetStylesToRanges(); + rImport.SetStylesToRangesFinished(); //#i48793#; has to be set before protection if (!aMatrixRangeList.empty()) @@ -459,56 +274,36 @@ void ScMyTables::DeleteTable() pProtect->setPasswordHash(aHash, maProtectionData.meHash1, maProtectionData.meHash2); pProtect->setOption(ScTableProtection::SELECT_LOCKED_CELLS, maProtectionData.mbSelectProtectedCells); pProtect->setOption(ScTableProtection::SELECT_UNLOCKED_CELLS, maProtectionData.mbSelectUnprotectedCells); - rImport.GetDocument()->SetTabProtection(nCurrentSheet, pProtect.get()); + rImport.GetDocument()->SetTabProtection(maCellPos.Tab(), pProtect.get()); } } -ScAddress ScMyTables::GetRealScCellPos() const -{ - SCROW nRow = 0; - SCCOL nCol = 0; - size_t n = maTables.size(); - for (size_t i = 0; i < n; ++i) - { - const ScMyTableData& rTab = maTables[i]; - nCol += rTab.GetRealCols(rTab.GetColumn()); - nRow += rTab.GetRealRows(rTab.GetRow()); - } - return ScAddress( nCol, nRow, nCurrentSheet ); -} - -void ScMyTables::AddColCount(sal_Int32 nTempColCount) -{ - pCurrentTab->SetColCount(pCurrentTab->GetColCount() + nTempColCount); -} - void ScMyTables::AddColStyle(const sal_Int32 nRepeat, const rtl::OUString& rCellStyleName) { - OSL_ENSURE(maTables.size() == 1, "not possible to use default styles on columns in subtables"); rImport.GetStylesImportHelper()->AddColumnStyle(rCellStyleName, nCurrentColStylePos, nRepeat); nCurrentColStylePos += nRepeat; } uno::Reference< drawing::XDrawPage > ScMyTables::GetCurrentXDrawPage() { - if( (nCurrentSheet != nCurrentDrawPage) || !xDrawPage.is() ) + if( (maCellPos.Tab() != nCurrentDrawPage) || !xDrawPage.is() ) { uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier( xCurrentSheet, uno::UNO_QUERY ); if( xDrawPageSupplier.is() ) xDrawPage.set(xDrawPageSupplier->getDrawPage()); - nCurrentDrawPage = sal::static_int_cast<sal_Int16>(nCurrentSheet); + nCurrentDrawPage = sal::static_int_cast<sal_Int16>(maCellPos.Tab()); } return xDrawPage; } uno::Reference< drawing::XShapes > ScMyTables::GetCurrentXShapes() { - if( (nCurrentSheet != nCurrentXShapes) || !xShapes.is() ) + if( (maCellPos.Tab() != nCurrentXShapes) || !xShapes.is() ) { xShapes.set(GetCurrentXDrawPage(), uno::UNO_QUERY); rImport.GetShapeImport()->startPage(xShapes); rImport.GetShapeImport()->pushGroupForSorting ( xShapes ); - nCurrentXShapes = sal::static_int_cast<sal_Int16>(nCurrentSheet); + nCurrentXShapes = sal::static_int_cast<sal_Int16>(maCellPos.Tab()); return xShapes; } else @@ -517,12 +312,12 @@ uno::Reference< drawing::XShapes > ScMyTables::GetCurrentXShapes() bool ScMyTables::HasDrawPage() { - return !((nCurrentSheet != nCurrentDrawPage) || !xDrawPage.is()); + return !((maCellPos.Tab() != nCurrentDrawPage) || !xDrawPage.is()); } bool ScMyTables::HasXShapes() { - return !((nCurrentSheet != nCurrentXShapes) || !xShapes.is()); + return !((maCellPos.Tab() != nCurrentXShapes) || !xShapes.is()); } void ScMyTables::AddOLE(uno::Reference <drawing::XShape>& rShape, @@ -538,8 +333,8 @@ void ScMyTables::AddMatrixRange( OSL_ENSURE(nEndRow >= nStartRow, "wrong row order"); OSL_ENSURE(nEndColumn >= nStartColumn, "wrong column order"); ScRange aScRange( - nStartColumn, nStartRow, nCurrentSheet, - nEndColumn, nEndRow, nCurrentSheet + nStartColumn, nStartRow, maCellPos.Tab(), + nEndColumn, nEndRow, maCellPos.Tab() ); ScMatrixRange aMRange(aScRange, rFormula, rFormulaNmsp, eGrammar); aMatrixRangeList.push_back(aMRange); @@ -555,7 +350,7 @@ bool ScMyTables::IsPartOfMatrix(const SCCOL nColumn, const SCROW nRow) bool bReady(false); while(!bReady && aItr != aEndItr) { - if (nCurrentSheet > aItr->aScRange.aStart.Tab()) + if (maCellPos.Tab() > aItr->aScRange.aStart.Tab()) { OSL_FAIL("should never hapen, because the list should be cleared in DeleteTable"); aItr = aMatrixRangeList.erase(aItr); diff --git a/sc/source/filter/xml/xmlsubti.hxx b/sc/source/filter/xml/xmlsubti.hxx index 8252f4ce3b07..7b69d5ba90e4 100644 --- a/sc/source/filter/xml/xmlsubti.hxx +++ b/sc/source/filter/xml/xmlsubti.hxx @@ -47,52 +47,6 @@ class ScXMLImport; -typedef std::vector<sal_Int32> ScMysalIntVec; -typedef std::list<sal_Int32> ScMysalIntList; - -const ScMysalIntVec::size_type nDefaultRowCount = 20; -const ScMysalIntVec::size_type nDefaultColCount = 20; -const ScMysalIntVec::size_type nDefaultTabCount = 10; - -class ScMyTableData -{ -private: - ScAddress maTableCellPos; - ScMysalIntVec nColsPerCol; - ScMysalIntVec nRealCols; - ScMysalIntVec nRowsPerRow; - ScMysalIntVec nRealRows; - sal_Int32 nSpannedCols; - sal_Int32 nColCount; - sal_Int32 nSubTableSpanned; - ScMysalIntList nChangedCols; -public: - ScMyTableData(SCTAB nSheet = -1, SCCOL nCol = -1, SCROW nRow = -1); - ~ScMyTableData(); - SCROW GetRow() const { return maTableCellPos.Row(); } - SCCOL GetColumn() const { return maTableCellPos.Col(); } - void AddRow(); - void AddColumn(); - void SetFirstColumn() { maTableCellPos.SetCol(-1); } - sal_Int32 GetColsPerCol(const sal_Int32 nIndex) const { return nColsPerCol[nIndex]; } - void SetColsPerCol(const sal_Int32 nIndex, sal_Int32 nValue = 1) { nColsPerCol[nIndex] = nValue; } - sal_Int32 GetRealCols(const sal_Int32 nIndex, const bool bIsNormal = true) const; - void SetRealCols(const sal_Int32 nIndex, const sal_Int32 nValue) { nRealCols[nIndex] = nValue; } - sal_Int32 GetRowsPerRow(const sal_Int32 nIndex) const { return nRowsPerRow[nIndex]; } - void SetRowsPerRow(const sal_Int32 nIndex, const sal_Int32 nValue = 1) { nRowsPerRow[nIndex] = nValue; } - sal_Int32 GetRealRows(const sal_Int32 nIndex) const { return nIndex < 0 ? 0 : nRealRows[nIndex]; } - void SetRealRows(const sal_Int32 nIndex, const sal_Int32 nValue) { nRealRows[nIndex] = nValue; } - sal_Int32 GetSpannedCols() const { return nSpannedCols; } - void SetSpannedCols(const sal_Int32 nTempSpannedCols) { nSpannedCols = nTempSpannedCols; } - sal_Int32 GetColCount() const { return nColCount; } - void SetColCount(const sal_Int32 nTempColCount) { nColCount = nTempColCount; } - sal_Int32 GetSubTableSpanned() const { return nSubTableSpanned; } - void SetSubTableSpanned(const sal_Int32 nValue) { nSubTableSpanned = nValue; } - sal_Int32 GetChangedCols(const sal_Int32 nFromIndex, const sal_Int32 nToIndex) const; - void SetChangedCols(const sal_Int32 nValue); -}; - - struct ScMatrixRange { rtl::OUString sFormula; @@ -134,14 +88,12 @@ private: ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XDrawPage > xDrawPage; ::com::sun::star::uno::Reference < ::com::sun::star::drawing::XShapes > xShapes; rtl::OUString sCurrentSheetName; - ::boost::ptr_vector<ScMyTableData> maTables; + ScAddress maCellPos; ScXMLTabProtectionData maProtectionData; ScMyMatrixRangeList aMatrixRangeList; sal_Int32 nCurrentColStylePos; sal_Int16 nCurrentDrawPage; sal_Int16 nCurrentXShapes; - SCTAB nCurrentSheet; - ScMyTableData* pCurrentTab; void NewRow(); void NewColumn(bool bIsCovered); @@ -158,16 +110,15 @@ public: void UpdateRowHeights(); void FixupOLEs() { aFixupOLEs.FixupOLEs(); } bool IsOLE(com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& rShape) const - { return ScMyOLEFixer::IsOLE(rShape); } + { return ScMyOLEFixer::IsOLE(rShape); } void DeleteTable(); - ScAddress GetRealScCellPos() const; - void AddColCount(sal_Int32 nTempColCount); + ScAddress GetRealScCellPos() const { return maCellPos; }; void AddColStyle(const sal_Int32 nRepeat, const rtl::OUString& rCellStyleName); ScXMLTabProtectionData& GetCurrentProtectionData() { return maProtectionData; } rtl::OUString GetCurrentSheetName() const { return sCurrentSheetName; } - SCTAB GetCurrentSheet() const { return nCurrentSheet; } - sal_Int32 GetCurrentColumn() const { return maTables.back().GetColCount(); } - sal_Int32 GetCurrentRow() const { return maTables.back().GetRow(); } + SCTAB GetCurrentSheet() const { return (maCellPos.Tab() >= 0) ? maCellPos.Tab() : 0; } + SCCOL GetCurrentColumn() const { return (maCellPos.Col() >= 0) ? maCellPos.Col() : 0; } + SCROW GetCurrentRow() const { return (maCellPos.Row() >= 0) ? maCellPos.Row() : 0; } ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XSpreadsheet > GetCurrentXSheet() const { return xCurrentSheet; } ::com::sun::star::uno::Reference< ::com::sun::star::table::XCellRange > |