[Libreoffice-commits] core.git: editeng/inc editeng/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Tue Oct 9 06:10:04 UTC 2018


 editeng/inc/editdoc.hxx             |    6 +++---
 editeng/source/editeng/editdoc.cxx  |   12 ++++++------
 editeng/source/editeng/impedit2.cxx |   23 ++++++++++-------------
 editeng/source/editeng/impedit3.cxx |    3 +--
 4 files changed, 20 insertions(+), 24 deletions(-)

New commits:
commit 33e596e03cd486ebb992327988f4bebebd23a0c9
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Mon Oct 8 10:02:43 2018 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Tue Oct 9 08:09:41 2018 +0200

    use unique_ptr in ParaPortionList
    
    Change-Id: I3d730007ba25740282091f0f3db8ffb90d5de367
    Reviewed-on: https://gerrit.libreoffice.org/61527
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/editeng/inc/editdoc.hxx b/editeng/inc/editdoc.hxx
index 92b677466761..aafeb0c81378 100644
--- a/editeng/inc/editdoc.hxx
+++ b/editeng/inc/editdoc.hxx
@@ -664,10 +664,10 @@ public:
     ParaPortion* operator[](sal_Int32 nPos);
     const ParaPortion* operator[](sal_Int32 nPos) const;
 
-    ParaPortion* Release(sal_Int32 nPos);
+    std::unique_ptr<ParaPortion> Release(sal_Int32 nPos);
     void Remove(sal_Int32 nPos);
-    void Insert(sal_Int32 nPos, ParaPortion* p);
-    void Append(ParaPortion* p);
+    void Insert(sal_Int32 nPos, std::unique_ptr<ParaPortion> p);
+    void Append(std::unique_ptr<ParaPortion> p);
     sal_Int32 Count() const;
 
 #if OSL_DEBUG_LEVEL > 0
diff --git a/editeng/source/editeng/editdoc.cxx b/editeng/source/editeng/editdoc.cxx
index 00e2698d7317..8185d7412b47 100644
--- a/editeng/source/editeng/editdoc.cxx
+++ b/editeng/source/editeng/editdoc.cxx
@@ -695,14 +695,14 @@ const ParaPortion* ParaPortionList::operator [](sal_Int32 nPos) const
     return 0 <= nPos && nPos < static_cast<sal_Int32>(maPortions.size()) ? maPortions[nPos].get() : nullptr;
 }
 
-ParaPortion* ParaPortionList::Release(sal_Int32 nPos)
+std::unique_ptr<ParaPortion> ParaPortionList::Release(sal_Int32 nPos)
 {
     if (nPos < 0 || static_cast<sal_Int32>(maPortions.size()) <= nPos)
     {
         SAL_WARN( "editeng", "ParaPortionList::Release - out of bounds pos " << nPos);
         return nullptr;
     }
-    ParaPortion* p = maPortions[nPos].release();
+    std::unique_ptr<ParaPortion> p = std::move(maPortions[nPos]);
     maPortions.erase(maPortions.begin()+nPos);
     return p;
 }
@@ -717,19 +717,19 @@ void ParaPortionList::Remove(sal_Int32 nPos)
     maPortions.erase(maPortions.begin()+nPos);
 }
 
-void ParaPortionList::Insert(sal_Int32 nPos, ParaPortion* p)
+void ParaPortionList::Insert(sal_Int32 nPos, std::unique_ptr<ParaPortion> p)
 {
     if (nPos < 0 || static_cast<sal_Int32>(maPortions.size()) < nPos)
     {
         SAL_WARN( "editeng", "ParaPortionList::Insert - out of bounds pos " << nPos);
         return;
     }
-    maPortions.insert(maPortions.begin()+nPos, std::unique_ptr<ParaPortion>(p));
+    maPortions.insert(maPortions.begin()+nPos, std::move(p));
 }
 
-void ParaPortionList::Append(ParaPortion* p)
+void ParaPortionList::Append(std::unique_ptr<ParaPortion> p)
 {
-    maPortions.push_back(std::unique_ptr<ParaPortion>(p));
+    maPortions.push_back(std::move(p));
 }
 
 sal_Int32 ParaPortionList::Count() const
diff --git a/editeng/source/editeng/impedit2.cxx b/editeng/source/editeng/impedit2.cxx
index 62b9382e2c13..e331006de1d3 100644
--- a/editeng/source/editeng/impedit2.cxx
+++ b/editeng/source/editeng/impedit2.cxx
@@ -246,8 +246,7 @@ void ImpEditEngine::InitDoc(bool bKeepParaAttribs)
 
     GetParaPortions().Reset();
 
-    ParaPortion* pIniPortion = new ParaPortion( aEditDoc[0] );
-    GetParaPortions().Insert(0, pIniPortion);
+    GetParaPortions().Insert(0, o3tl::make_unique<ParaPortion>( aEditDoc[0] ));
 
     bFormatted = false;
 
@@ -2162,17 +2161,18 @@ EditSelection ImpEditEngine::ImpMoveParagraphs( Range aOldPositions, sal_Int32 n
     for (long i = aOldPositions.Min(); i <= aOldPositions.Max(); i++  )
     {
         // always aOldPositions.Min(), since Remove().
-        ParaPortion* pTmpPortion = GetParaPortions().Release(aOldPositions.Min());
+        std::unique_ptr<ParaPortion> pTmpPortion = GetParaPortions().Release(aOldPositions.Min());
         aEditDoc.Release( aOldPositions.Min() );
-        aTmpPortionList.Append(pTmpPortion);
+        aTmpPortionList.Append(std::move(pTmpPortion));
     }
 
     sal_Int32 nRealNewPos = pDestPortion ? GetParaPortions().GetPos( pDestPortion ) : GetParaPortions().Count();
     OSL_ENSURE( nRealNewPos != EE_PARA_NOT_FOUND, "ImpMoveParagraphs: Invalid Position!" );
 
-    for (sal_Int32 i = 0; i < aTmpPortionList.Count(); ++i)
+    sal_Int32 i = 0;
+    while( aTmpPortionList.Count() > 0 )
     {
-        ParaPortion* pTmpPortion = aTmpPortionList[i];
+        std::unique_ptr<ParaPortion> pTmpPortion = aTmpPortionList.Release(0);
         if ( i == 0 )
             aSelection.Min().SetNode( pTmpPortion->GetNode() );
 
@@ -2182,7 +2182,8 @@ EditSelection ImpEditEngine::ImpMoveParagraphs( Range aOldPositions, sal_Int32 n
         ContentNode* pN = pTmpPortion->GetNode();
         aEditDoc.Insert(nRealNewPos+i, pN);
 
-        GetParaPortions().Insert(nRealNewPos+i, pTmpPortion);
+        GetParaPortions().Insert(nRealNewPos+i, std::move(pTmpPortion));
+        ++i;
     }
 
     aEndMovingParagraphsHdl.Call( aMoveParagraphsInfo );
@@ -2207,9 +2208,6 @@ EditSelection ImpEditEngine::ImpMoveParagraphs( Range aOldPositions, sal_Int32 n
     if ( pRecalc4 )
         CalcHeight( pRecalc4 );
 
-    while( aTmpPortionList.Count() > 0 )
-        aTmpPortionList.Release( aTmpPortionList.Count() - 1 );
-
 #if OSL_DEBUG_LEVEL > 0
     ParaPortionList::DbgCheck(GetParaPortions(), aEditDoc);
 #endif
@@ -2884,7 +2882,7 @@ EditPaM ImpEditEngine::ImpInsertParaBreak( EditPaM& rPaM, bool bKeepEndingAttrib
     // Here, as in undo, but also in all other methods.
     sal_Int32 nPos = GetParaPortions().GetPos( pPortion );
     ParaPortion* pNewPortion = new ParaPortion( aPaM.GetNode() );
-    GetParaPortions().Insert(nPos+1, pNewPortion);
+    GetParaPortions().Insert(nPos+1, std::unique_ptr<ParaPortion>(pNewPortion));
     ParaAttribsChanged( pNewPortion->GetNode() );
     if ( IsCallParaInsertedOrDeleted() )
         GetEditEnginePtr()->ParagraphInserted( nPos+1 );
@@ -2916,8 +2914,7 @@ EditPaM ImpEditEngine::ImpFastInsertParagraph( sal_Int32 nPara )
 
     aEditDoc.Insert(nPara, pNode);
 
-    ParaPortion* pNewPortion = new ParaPortion( pNode );
-    GetParaPortions().Insert(nPara, pNewPortion);
+    GetParaPortions().Insert(nPara, o3tl::make_unique<ParaPortion>( pNode ));
     if ( IsCallParaInsertedOrDeleted() )
         GetEditEnginePtr()->ParagraphInserted( nPara );
 
diff --git a/editeng/source/editeng/impedit3.cxx b/editeng/source/editeng/impedit3.cxx
index 93e34d40a598..afadc820687b 100644
--- a/editeng/source/editeng/impedit3.cxx
+++ b/editeng/source/editeng/impedit3.cxx
@@ -3920,8 +3920,7 @@ void ImpEditEngine::InsertContent( ContentNode* pNode, sal_Int32 nPos )
 {
     DBG_ASSERT( pNode, "NULL-Pointer in InsertContent! " );
     DBG_ASSERT( IsInUndo(), "InsertContent only for Undo()!" );
-    ParaPortion* pNew = new ParaPortion( pNode );
-    GetParaPortions().Insert(nPos, pNew);
+    GetParaPortions().Insert(nPos, o3tl::make_unique<ParaPortion>( pNode ));
     aEditDoc.Insert(nPos, pNode);
     if ( IsCallParaInsertedOrDeleted() )
         GetEditEnginePtr()->ParagraphInserted( nPos );


More information about the Libreoffice-commits mailing list