diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-08-22 15:12:17 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-08-23 15:20:19 +0200 |
commit | d4f692db44748def01152425f2ef9df8abf8c5ca (patch) | |
tree | 7abf297145c75cd34a97566f1c6c8f61f3c1ae16 /sc | |
parent | 4a58fd0e81b0375c71f6182233f0ec9390942cd1 (diff) |
simplify ScMyGeneratedList
no need to use std::list and no need to allocate entries on the heap.
But to make this work properly, we need move constructors on ScBigRange
and therefore ScBigAddress
Change-Id: Ic3cb1fd85051ff30fe5c5b8d8fd6cab81a7b38eb
Reviewed-on: https://gerrit.libreoffice.org/59451
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sc')
-rw-r--r-- | sc/inc/bigrange.hxx | 4 | ||||
-rw-r--r-- | sc/source/filter/xml/XMLChangeTrackingImportHelper.cxx | 55 | ||||
-rw-r--r-- | sc/source/filter/xml/XMLChangeTrackingImportHelper.hxx | 14 |
3 files changed, 28 insertions, 45 deletions
diff --git a/sc/inc/bigrange.hxx b/sc/inc/bigrange.hxx index 995b03d1a36a..ab9d91659d1d 100644 --- a/sc/inc/bigrange.hxx +++ b/sc/inc/bigrange.hxx @@ -40,6 +40,7 @@ public: : nRow( nRowP ), nCol( nColP ), nTab( nTabP ) {} ScBigAddress( const ScBigAddress& r ) : nRow( r.nRow ), nCol( r.nCol ), nTab( r.nTab ) {} + ScBigAddress( ScBigAddress&& ) = default; ScBigAddress( const ScAddress& r ) : nRow( r.Row() ), nCol( r.Col() ), nTab( r.Tab() ) {} @@ -64,6 +65,7 @@ public: ScBigAddress& operator=( const ScBigAddress& r ) { nCol = r.nCol; nRow = r.nRow; nTab = r.nTab; return *this; } + ScBigAddress& operator=( ScBigAddress&& ) = default; ScBigAddress& operator=( const ScAddress& r ) { nCol = r.Col(); nRow = r.Row(); nTab = r.Tab(); return *this; } bool operator==( const ScBigAddress& r ) const @@ -112,6 +114,7 @@ public: ScBigRange() : aStart(), aEnd() {} ScBigRange( const ScBigRange& r ) : aStart( r.aStart ), aEnd( r.aEnd ) {} + ScBigRange( ScBigRange&& ) = default; ScBigRange( const ScRange& r ) : aStart( r.aStart ), aEnd( r.aEnd ) {} ScBigRange( sal_Int32 nCol1, sal_Int32 nRow1, sal_Int32 nTab1, @@ -141,6 +144,7 @@ public: ScBigRange& operator=( const ScBigRange& r ) { aStart = r.aStart; aEnd = r.aEnd; return *this; } + ScBigRange& operator=( ScBigRange&& ) = default; bool operator==( const ScBigRange& r ) const { return (aStart == r.aStart) && (aEnd == r.aEnd); } bool operator!=( const ScBigRange& r ) const diff --git a/sc/source/filter/xml/XMLChangeTrackingImportHelper.cxx b/sc/source/filter/xml/XMLChangeTrackingImportHelper.cxx index 5f1862ae023e..ca86e272820e 100644 --- a/sc/source/filter/xml/XMLChangeTrackingImportHelper.cxx +++ b/sc/source/filter/xml/XMLChangeTrackingImportHelper.cxx @@ -78,17 +78,6 @@ const ScCellValue& ScMyCellInfo::CreateCell( ScDocument* pDoc ) return maCell; } -ScMyGenerated::ScMyGenerated(std::unique_ptr<ScMyCellInfo> pTempCellInfo, const ScBigRange& aTempBigRange) - : aBigRange(aTempBigRange) - , nID(0) - , pCellInfo(std::move(pTempCellInfo)) -{ -} - -ScMyGenerated::~ScMyGenerated() -{ -} - ScMyBaseAction::ScMyBaseAction(const ScChangeActionType nTempActionType) : aDependencies(), aDeletedList(), @@ -366,19 +355,18 @@ void ScXMLChangeTrackingImportHelper::GetMultiSpannedRange() void ScXMLChangeTrackingImportHelper::AddGenerated(std::unique_ptr<ScMyCellInfo> pCellInfo, const ScBigRange& aBigRange) { - ScMyGenerated* pGenerated = new ScMyGenerated(std::move(pCellInfo), aBigRange); + ScMyGenerated aGenerated { aBigRange, 0, std::move(pCellInfo) }; if (pCurrentAction->nActionType == SC_CAT_MOVE) { - static_cast<ScMyMoveAction*>(pCurrentAction)->aGeneratedList.push_back(pGenerated); + static_cast<ScMyMoveAction*>(pCurrentAction)->aGeneratedList.push_back(std::move(aGenerated)); } else if ((pCurrentAction->nActionType == SC_CAT_DELETE_COLS) || (pCurrentAction->nActionType == SC_CAT_DELETE_ROWS)) { - static_cast<ScMyDelAction*>(pCurrentAction)->aGeneratedList.push_back(pGenerated); + static_cast<ScMyDelAction*>(pCurrentAction)->aGeneratedList.push_back(std::move(aGenerated)); } else { - delete pGenerated; OSL_FAIL("try to insert a generated action to a wrong action"); } } @@ -502,27 +490,24 @@ ScChangeAction* ScXMLChangeTrackingImportHelper::CreateContentAction(const ScMyC return pNewAction; } -void ScXMLChangeTrackingImportHelper::CreateGeneratedActions(ScMyGeneratedList& rList) +void ScXMLChangeTrackingImportHelper::CreateGeneratedActions(std::deque<ScMyGenerated>& rList) { if (!rList.empty()) { - ScMyGeneratedList::iterator aItr(rList.begin()); - ScMyGeneratedList::iterator aEndItr(rList.end()); - while (aItr != aEndItr) + for (ScMyGenerated & rGenerated : rList) { - if ((*aItr)->nID == 0) + if (rGenerated.nID == 0) { ScCellValue aCell; - if ((*aItr)->pCellInfo) - aCell = (*aItr)->pCellInfo->CreateCell(pDoc); + if (rGenerated.pCellInfo) + aCell = rGenerated.pCellInfo->CreateCell(pDoc); if (!aCell.isEmpty()) { - (*aItr)->nID = pTrack->AddLoadedGenerated(aCell, (*aItr)->aBigRange, (*aItr)->pCellInfo->sInputString); - OSL_ENSURE((*aItr)->nID, "could not insert generated action"); + rGenerated.nID = pTrack->AddLoadedGenerated(aCell, rGenerated.aBigRange, rGenerated.pCellInfo->sInputString); + OSL_ENSURE(rGenerated.nID, "could not insert generated action"); } } - ++aItr; } } } @@ -536,14 +521,12 @@ void ScXMLChangeTrackingImportHelper::SetDeletionDependencies(ScMyDelAction* pAc (pAction->nActionType == SC_CAT_DELETE_TABS)), "wrong action type"); if (pDelAct) { - ScMyGeneratedList::iterator aItr(pAction->aGeneratedList.begin()); - ScMyGeneratedList::iterator aEndItr(pAction->aGeneratedList.end()); + auto aItr(pAction->aGeneratedList.begin()); + auto aEndItr(pAction->aGeneratedList.end()); while (aItr != aEndItr) { - OSL_ENSURE((*aItr)->nID, "a not inserted generated action"); - pDelAct->SetDeletedInThis((*aItr)->nID, pTrack); - if (*aItr) - delete *aItr; + OSL_ENSURE(aItr->nID, "a not inserted generated action"); + pDelAct->SetDeletedInThis(aItr->nID, pTrack); aItr = pAction->aGeneratedList.erase(aItr); } } @@ -599,14 +582,12 @@ void ScXMLChangeTrackingImportHelper::SetMovementDependencies(ScMyMoveAction* pA { if (pMoveAct) { - ScMyGeneratedList::iterator aItr(pAction->aGeneratedList.begin()); - ScMyGeneratedList::iterator aEndItr(pAction->aGeneratedList.end()); + auto aItr(pAction->aGeneratedList.begin()); + auto aEndItr(pAction->aGeneratedList.end()); while (aItr != aEndItr) { - OSL_ENSURE((*aItr)->nID, "a not inserted generated action"); - pMoveAct->SetDeletedInThis((*aItr)->nID, pTrack); - if (*aItr) - delete *aItr; + OSL_ENSURE(aItr->nID, "a not inserted generated action"); + pMoveAct->SetDeletedInThis(aItr->nID, pTrack); aItr = pAction->aGeneratedList.erase(aItr); } } diff --git a/sc/source/filter/xml/XMLChangeTrackingImportHelper.hxx b/sc/source/filter/xml/XMLChangeTrackingImportHelper.hxx index 036a9333613d..558eee4289fa 100644 --- a/sc/source/filter/xml/XMLChangeTrackingImportHelper.hxx +++ b/sc/source/filter/xml/XMLChangeTrackingImportHelper.hxx @@ -70,15 +70,13 @@ struct ScMyDeleted struct ScMyGenerated { ScBigRange aBigRange; - sal_uInt32 nID; + sal_uInt32 nID = 0; std::unique_ptr<ScMyCellInfo> pCellInfo; - ScMyGenerated(std::unique_ptr<ScMyCellInfo> pCellInfo, const ScBigRange& aBigRange); - ~ScMyGenerated(); + ScMyGenerated(ScBigRange range, sal_uInt32 id, std::unique_ptr<ScMyCellInfo> p) + : aBigRange(range), nID(id), pCellInfo(std::move(p)) {} }; -typedef std::list<ScMyGenerated*> ScMyGeneratedList; - struct ScMyInsertionCutOff { sal_uInt32 nID; @@ -135,7 +133,7 @@ struct ScMyInsAction : public ScMyBaseAction struct ScMyDelAction : public ScMyBaseAction { - ScMyGeneratedList aGeneratedList; + std::deque<ScMyGenerated> aGeneratedList; std::unique_ptr<ScMyInsertionCutOff> pInsCutOff; ScMyMoveCutOffs aMoveCutOffs; sal_Int32 nD; @@ -146,7 +144,7 @@ struct ScMyDelAction : public ScMyBaseAction struct ScMyMoveAction : public ScMyBaseAction { - ScMyGeneratedList aGeneratedList; + std::deque<ScMyGenerated> aGeneratedList; std::unique_ptr<ScMyMoveRanges> pMoveRanges; ScMyMoveAction(); @@ -188,7 +186,7 @@ private: ScChangeAction* CreateRejectionAction(const ScMyRejAction* pAction); ScChangeAction* CreateContentAction(const ScMyContentAction* pAction); - void CreateGeneratedActions(ScMyGeneratedList& rList); + void CreateGeneratedActions(std::deque<ScMyGenerated>& rList); public: ScXMLChangeTrackingImportHelper(); |