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

Noel Grandin noel.grandin at collabora.co.uk
Thu Mar 29 06:37:22 UTC 2018


 sw/source/core/doc/docedt.cxx |   20 ++++++++++----------
 sw/source/core/inc/mvsave.hxx |    7 +++----
 2 files changed, 13 insertions(+), 14 deletions(-)

New commits:
commit 0dde5e7d6c69fbf59a898b019ef230adfef30633
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Wed Mar 28 10:42:09 2018 +0200

    loplugin:useuniqueptr in SaveRedlEndPosForRestore
    
    Change-Id: I529ca5016ab22a8e57655da7fe5ec4f3344a05d5
    Reviewed-on: https://gerrit.libreoffice.org/52032
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/sw/source/core/doc/docedt.cxx b/sw/source/core/doc/docedt.cxx
index 3b88309bd873..f4056d1d08ff 100644
--- a/sw/source/core/doc/docedt.cxx
+++ b/sw/source/core/doc/docedt.cxx
@@ -240,7 +240,7 @@ void DelFlyInRange( const SwNodeIndex& rMkNdIdx,
 // From now on this class saves the redline positions of all redlines which ends exact at the
 // insert position (node _and_ content index)
 SaveRedlEndPosForRestore::SaveRedlEndPosForRestore( const SwNodeIndex& rInsIdx, sal_Int32 nCnt )
-    : pSavArr( nullptr ), pSavIdx( nullptr ), nSavContent( nCnt )
+    : nSavContent( nCnt )
 {
     SwNode& rNd = rInsIdx.GetNode();
     SwDoc* pDest = rNd.GetDoc();
@@ -255,24 +255,24 @@ SaveRedlEndPosForRestore::SaveRedlEndPosForRestore( const SwNodeIndex& rInsIdx,
               && *( pEnd = ( pRedl = pDest->getIDocumentRedlineAccess().GetRedlineTable()[ nFndPos ] )->End() ) == aSrcPos
               && *pRedl->Start() < aSrcPos )
         {
-            if( !pSavArr )
+            if( !pSavIdx )
             {
-                pSavArr = new std::vector<SwPosition*>;
-                pSavIdx = new SwNodeIndex( rInsIdx, -1 );
+                pSavIdx.reset(new SwNodeIndex( rInsIdx, -1 ));
             }
-            pSavArr->push_back( const_cast<SwPosition*>(pEnd) );
+            mvSavArr.push_back( const_cast<SwPosition*>(pEnd) );
         }
     }
 }
 
 SaveRedlEndPosForRestore::~SaveRedlEndPosForRestore()
 {
-    delete pSavArr;
-    delete pSavIdx;
+    pSavIdx.reset();
 }
 
-void SaveRedlEndPosForRestore::Restore_()
+void SaveRedlEndPosForRestore::Restore()
 {
+    if (mvSavArr.empty())
+        return;
     ++(*pSavIdx);
     SwContentNode* pNode = pSavIdx->GetNode().GetContentNode();
     // If there's no content node at the remembered position, we will not restore the old position
@@ -280,8 +280,8 @@ void SaveRedlEndPosForRestore::Restore_()
     if( pNode )
     {
         SwPosition aPos( *pSavIdx, SwIndex( pNode, nSavContent ));
-        for( auto n = pSavArr->size(); n; )
-            *(*pSavArr)[ --n ] = aPos;
+        for( auto n = mvSavArr.size(); n; )
+            *mvSavArr[ --n ] = aPos;
     }
 }
 
diff --git a/sw/source/core/inc/mvsave.hxx b/sw/source/core/inc/mvsave.hxx
index ec1576e83db8..1279617ef313 100644
--- a/sw/source/core/inc/mvsave.hxx
+++ b/sw/source/core/inc/mvsave.hxx
@@ -177,15 +177,14 @@ public:
 
 class SaveRedlEndPosForRestore
 {
-    std::vector<SwPosition*>* pSavArr;
-    SwNodeIndex* pSavIdx;
+    std::vector<SwPosition*> mvSavArr;
+    std::unique_ptr<SwNodeIndex> pSavIdx;
     sal_Int32 nSavContent;
 
-    void Restore_();
 public:
     SaveRedlEndPosForRestore( const SwNodeIndex& rInsIdx, sal_Int32 nContent );
     ~SaveRedlEndPosForRestore();
-    void Restore() { if( pSavArr ) Restore_(); }
+    void Restore();
 };
 
 #endif // INCLUDED_SW_SOURCE_CORE_INC_MVSAVE_HXX


More information about the Libreoffice-commits mailing list