[Libreoffice-commits] core.git: sc/source

Mike Kaganski (via logerrit) logerrit at kemper.freedesktop.org
Fri Jul 23 17:23:35 UTC 2021


 sc/source/core/data/drwlayer.cxx |   32 ++++++++++++++++----------------
 1 file changed, 16 insertions(+), 16 deletions(-)

New commits:
commit 51371d7e652366b3967d1b5ab6b6217d1ade78d2
Author:     Mike Kaganski <mike.kaganski at collabora.com>
AuthorDate: Fri Jul 23 16:55:04 2021 +0200
Commit:     Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Fri Jul 23 19:22:58 2021 +0200

    Use vector instead of unique_ptr
    
    Change-Id: Iea1fb26d9e176283a96d6f0d18dae5b58e55602e
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/119432
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>

diff --git a/sc/source/core/data/drwlayer.cxx b/sc/source/core/data/drwlayer.cxx
index 8d4593992e06..7d31106ee7d7 100644
--- a/sc/source/core/data/drwlayer.cxx
+++ b/sc/source/core/data/drwlayer.cxx
@@ -1543,7 +1543,6 @@ void ScDrawLayer::DeleteObjectsInArea( SCTAB nTab, SCCOL nCol1,SCROW nRow1,
     if (!nObjCount)
         return;
 
-    size_t nDelCount = 0;
     tools::Rectangle aDelRect = pDoc->GetMMRect( nCol1, nRow1, nCol2, nRow2, nTab );
     tools::Rectangle aDelCircle = aDelRect;
     aDelCircle.AdjustLeft(-250);
@@ -1551,7 +1550,8 @@ void ScDrawLayer::DeleteObjectsInArea( SCTAB nTab, SCCOL nCol1,SCROW nRow1,
     aDelCircle.AdjustTop(-70);
     aDelCircle.AdjustBottom(70);
 
-    std::unique_ptr<SdrObject*[]> ppObj(new SdrObject*[nObjCount]);
+    std::vector<SdrObject*> ppObj;
+    ppObj.reserve(nObjCount);
 
     SdrObjListIter aIter( pPage, SdrIterMode::Flat );
     SdrObject* pObject = aIter.Next();
@@ -1567,7 +1567,7 @@ void ScDrawLayer::DeleteObjectsInArea( SCTAB nTab, SCCOL nCol1,SCROW nRow1,
             {
                 aObjRect = pObject->GetLogicRect();
                 if(aDelCircle.IsInside(aObjRect))
-                   ppObj[nDelCount++] = pObject;
+                   ppObj.push_back(pObject);
             }
             else
             {
@@ -1578,10 +1578,10 @@ void ScDrawLayer::DeleteObjectsInArea( SCTAB nTab, SCCOL nCol1,SCROW nRow1,
                     {
                         ScAnchorType aAnchorType = ScDrawLayer::GetAnchorType(*pObject);
                         if (aAnchorType == SCA_CELL || aAnchorType == SCA_CELL_RESIZE)
-                            ppObj[nDelCount++] = pObject;
+                            ppObj.push_back(pObject);
                     }
                     else
-                        ppObj[nDelCount++] = pObject;
+                        ppObj.push_back(pObject);
                 }
             }
         }
@@ -1590,11 +1590,11 @@ void ScDrawLayer::DeleteObjectsInArea( SCTAB nTab, SCCOL nCol1,SCROW nRow1,
     }
 
     if (bRecording)
-        for (size_t i=1; i<=nDelCount; ++i)
-            AddCalcUndo( std::make_unique<SdrUndoRemoveObj>( *ppObj[nDelCount-i] ) );
+        for (auto p : ppObj)
+            AddCalcUndo(std::make_unique<SdrUndoRemoveObj>(*p));
 
-    for (size_t i=1; i<=nDelCount; ++i)
-        pPage->RemoveObject( ppObj[nDelCount-i]->GetOrdNum() );
+    for (auto p : ppObj)
+        pPage->RemoveObject(p->GetOrdNum());
 }
 
 void ScDrawLayer::DeleteObjectsInSelection( const ScMarkData& rMark )
@@ -1622,13 +1622,13 @@ void ScDrawLayer::DeleteObjectsInSelection( const ScMarkData& rMark )
             const size_t nObjCount = pPage->GetObjCount();
             if (nObjCount)
             {
-                size_t nDelCount = 0;
                 //  Rectangle around the whole selection
                 tools::Rectangle aMarkBound = pDoc->GetMMRect(
                             aMarkRange.aStart.Col(), aMarkRange.aStart.Row(),
                             aMarkRange.aEnd.Col(), aMarkRange.aEnd.Row(), nTab );
 
-                std::unique_ptr<SdrObject*[]> ppObj(new SdrObject*[nObjCount]);
+                std::vector<SdrObject*> ppObj;
+                ppObj.reserve(nObjCount);
 
                 SdrObjListIter aIter( pPage, SdrIterMode::Flat );
                 SdrObject* pObject = aIter.Next();
@@ -1650,7 +1650,7 @@ void ScDrawLayer::DeleteObjectsInSelection( const ScMarkData& rMark )
                                                                  pObjData->maStart.Row()));
                         if (bObjectInMarkArea || bObjectAnchoredToMarkedCell)
                         {
-                            ppObj[nDelCount++] = pObject;
+                            ppObj.push_back(pObject);
                         }
                     }
 
@@ -1660,11 +1660,11 @@ void ScDrawLayer::DeleteObjectsInSelection( const ScMarkData& rMark )
                 //  Delete objects (backwards)
 
                 if (bRecording)
-                    for (size_t i=1; i<=nDelCount; ++i)
-                        AddCalcUndo( std::make_unique<SdrUndoRemoveObj>( *ppObj[nDelCount-i] ) );
+                    for (auto p : ppObj)
+                        AddCalcUndo(std::make_unique<SdrUndoRemoveObj>(*p));
 
-                for (size_t i=1; i<=nDelCount; ++i)
-                    pPage->RemoveObject( ppObj[nDelCount-i]->GetOrdNum() );
+                for (auto p : ppObj)
+                    pPage->RemoveObject(p->GetOrdNum());
             }
         }
         else


More information about the Libreoffice-commits mailing list