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

Noel Grandin noel.grandin at collabora.co.uk
Fri Jul 13 06:41:24 UTC 2018


 compilerplugins/clang/useuniqueptr.cxx      |    6 ++++++
 sw/source/core/inc/UndoTable.hxx            |    8 ++++----
 sw/source/core/txtnode/SwGrammarContact.cxx |   22 +++++++++-------------
 sw/source/core/undo/untbl.cxx               |   26 ++++++++++++--------------
 4 files changed, 31 insertions(+), 31 deletions(-)

New commits:
commit c79bd83818dbd49dfd77ab82457057eff6a5d3d7
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Thu Jul 12 16:57:07 2018 +0200

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

diff --git a/sw/source/core/inc/UndoTable.hxx b/sw/source/core/inc/UndoTable.hxx
index 269644245dd0..88cece131191 100644
--- a/sw/source/core/inc/UndoTable.hxx
+++ b/sw/source/core/inc/UndoTable.hxx
@@ -48,10 +48,10 @@ class SwUndoInsTable : public SwUndo
 {
     OUString sTableNm;
     SwInsertTableOptions aInsTableOpts;
-    SwDDEFieldType* pDDEFieldType;
-    std::vector<sal_uInt16> *pColWidth;
-    SwRedlineData*  pRedlData;
-    SwTableAutoFormat* pAutoFormat;
+    std::unique_ptr<SwDDEFieldType> pDDEFieldType;
+    std::unique_ptr<std::vector<sal_uInt16>> pColWidth;
+    std::unique_ptr<SwRedlineData>  pRedlData;
+    std::unique_ptr<SwTableAutoFormat> pAutoFormat;
     sal_uLong nSttNode;
     sal_uInt16 nRows, nCols;
     sal_uInt16 nAdjust;
diff --git a/sw/source/core/undo/untbl.cxx b/sw/source/core/undo/untbl.cxx
index 1f03b2e57441..927b489eba31 100644
--- a/sw/source/core/undo/untbl.cxx
+++ b/sw/source/core/undo/untbl.cxx
@@ -226,16 +226,16 @@ SwUndoInsTable::SwUndoInsTable( const SwPosition& rPos, sal_uInt16 nCl, sal_uInt
 {
     if( pColArr )
     {
-        pColWidth = new std::vector<sal_uInt16>(*pColArr);
+        pColWidth.reset( new std::vector<sal_uInt16>(*pColArr) );
     }
     if( pTAFormat )
-        pAutoFormat = new SwTableAutoFormat( *pTAFormat );
+        pAutoFormat.reset( new SwTableAutoFormat( *pTAFormat ) );
 
     // consider redline
     SwDoc& rDoc = *rPos.nNode.GetNode().GetDoc();
     if( rDoc.getIDocumentRedlineAccess().IsRedlineOn() )
     {
-        pRedlData = new SwRedlineData( nsRedlineType_t::REDLINE_INSERT, rDoc.getIDocumentRedlineAccess().GetRedlineAuthor() );
+        pRedlData.reset( new SwRedlineData( nsRedlineType_t::REDLINE_INSERT, rDoc.getIDocumentRedlineAccess().GetRedlineAuthor() ) );
         SetRedlineFlags( rDoc.getIDocumentRedlineAccess().GetRedlineFlags() );
     }
 
@@ -244,10 +244,10 @@ SwUndoInsTable::SwUndoInsTable( const SwPosition& rPos, sal_uInt16 nCl, sal_uInt
 
 SwUndoInsTable::~SwUndoInsTable()
 {
-    delete pDDEFieldType;
-    delete pColWidth;
-    delete pRedlData;
-    delete pAutoFormat;
+    pDDEFieldType.reset();
+    pColWidth.reset();
+    pRedlData.reset();
+    pAutoFormat.reset();
 }
 
 void SwUndoInsTable::UndoImpl(::sw::UndoRedoContext & rContext)
@@ -280,9 +280,8 @@ void SwUndoInsTable::UndoImpl(::sw::UndoRedoContext & rContext)
     }
 
     sTableNm = pTableNd->GetTable().GetFrameFormat()->GetName();
-    if( dynamic_cast<const SwDDETable *>(&pTableNd->GetTable()) != nullptr )
-        pDDEFieldType = static_cast<SwDDEFieldType*>(static_cast<SwDDETable&>(pTableNd->GetTable()).
-                                        GetDDEFieldType()->Copy());
+    if( auto pDDETable = dynamic_cast<const SwDDETable *>(&pTableNd->GetTable()) )
+        pDDEFieldType.reset( static_cast<SwDDEFieldType*>(pDDETable->GetDDEFieldType()->Copy()) );
 
     rDoc.GetNodes().Delete( aIdx, pTableNd->EndOfSectionIndex() -
                                 aIdx.GetIndex() + 1 );
@@ -300,7 +299,7 @@ void SwUndoInsTable::RedoImpl(::sw::UndoRedoContext & rContext)
     SwPosition const aPos(SwNodeIndex(rDoc.GetNodes(), nSttNode));
     const SwTable* pTable = rDoc.InsertTable( aInsTableOpts, aPos, nRows, nCols,
                                             nAdjust,
-                                            pAutoFormat, pColWidth );
+                                            pAutoFormat.get(), pColWidth.get() );
     static_cast<SwFrameFormat*>(pTable->GetFrameFormat())->SetName( sTableNm );
     SwTableNode* pTableNode = rDoc.GetNodes()[nSttNode]->GetTableNode();
 
@@ -310,8 +309,7 @@ void SwUndoInsTable::RedoImpl(::sw::UndoRedoContext & rContext)
                                                             *pDDEFieldType));
         std::unique_ptr<SwDDETable> pDDETable(new SwDDETable( pTableNode->GetTable(), pNewType ));
         pTableNode->SetNewTable( std::move(pDDETable) );
-        delete pDDEFieldType;
-        pDDEFieldType = nullptr;
+        pDDEFieldType.reset();
     }
 
     if( (pRedlData && IDocumentRedlineAccess::IsRedlineOn( GetRedlineFlags() )) ||
@@ -340,7 +338,7 @@ void SwUndoInsTable::RepeatImpl(::sw::RepeatContext & rContext)
 {
     rContext.GetDoc().InsertTable(
             aInsTableOpts, *rContext.GetRepeatPaM().GetPoint(),
-            nRows, nCols, nAdjust, pAutoFormat, pColWidth );
+            nRows, nCols, nAdjust, pAutoFormat.get(), pColWidth.get() );
 }
 
 SwRewriter SwUndoInsTable::GetRewriter() const
commit c75f597722608732d991619f550063e7c5d7c485
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Thu Jul 12 16:52:52 2018 +0200

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

diff --git a/compilerplugins/clang/useuniqueptr.cxx b/compilerplugins/clang/useuniqueptr.cxx
index 5d8d6c57a2fb..0af8cd295a6b 100644
--- a/compilerplugins/clang/useuniqueptr.cxx
+++ b/compilerplugins/clang/useuniqueptr.cxx
@@ -69,6 +69,12 @@ public:
         // ScTempDocSource::pTempDoc
         if (fn == SRCDIR "/sc/source/ui/unoobj/funcuno.cxx")
             return;
+        // SwAttrIter::m_pFont
+        if (fn == SRCDIR "/sw/source/core/text/itratr.cxx")
+            return;
+        // SwWrongList
+        if (fn == SRCDIR "/sw/source/core/text/wrong.cxx")
+            return;
 
         TraverseDecl(compiler.getASTContext().getTranslationUnitDecl());
     }
diff --git a/sw/source/core/txtnode/SwGrammarContact.cxx b/sw/source/core/txtnode/SwGrammarContact.cxx
index d1ae37a7571d..9fa8366f1375 100644
--- a/sw/source/core/txtnode/SwGrammarContact.cxx
+++ b/sw/source/core/txtnode/SwGrammarContact.cxx
@@ -41,14 +41,14 @@
 class SwGrammarContact : public IGrammarContact, public SwClient
 {
     Timer aTimer;
-    SwGrammarMarkUp *mpProxyList;
+    std::unique_ptr<SwGrammarMarkUp> mpProxyList;
     bool mbFinished;
     SwTextNode* getMyTextNode() { return static_cast<SwTextNode*>(GetRegisteredIn()); }
       DECL_LINK( TimerRepaint, Timer *, void );
 
 public:
     SwGrammarContact();
-    virtual ~SwGrammarContact() override { aTimer.Stop(); delete mpProxyList; }
+    virtual ~SwGrammarContact() override { aTimer.Stop(); }
 
     // (pure) virtual functions of IGrammarContact
     virtual void updateCursorPosition( const SwPosition& rNewPos ) override;
@@ -73,8 +73,7 @@ IMPL_LINK( SwGrammarContact, TimerRepaint, Timer *, pTimer, void )
         pTimer->Stop();
         if( GetRegisteredIn() )
         {   //Replace the old wrong list by the proxy list and repaint all frames
-            getMyTextNode()->SetGrammarCheck( mpProxyList );
-            mpProxyList = nullptr;
+            getMyTextNode()->SetGrammarCheck( mpProxyList.release() );
             SwTextFrame::repaintTextFrames( *getMyTextNode() );
         }
     }
@@ -91,11 +90,10 @@ void SwGrammarContact::updateCursorPosition( const SwPosition& rNewPos )
         {
             if( mpProxyList )
             {   // replace old list by the proxy list and repaint
-                getMyTextNode()->SetGrammarCheck( mpProxyList );
+                getMyTextNode()->SetGrammarCheck( mpProxyList.release() );
                 SwTextFrame::repaintTextFrames( *getMyTextNode() );
             }
             EndListeningAll();
-            mpProxyList = nullptr;
         }
         if( pTextNode )
             pTextNode->Add( this ); // welcome new paragraph
@@ -112,22 +110,21 @@ SwGrammarMarkUp* SwGrammarContact::getGrammarCheck( SwTextNode& rTextNode, bool
         {
             if( mbFinished )
             {
-                delete mpProxyList;
-                mpProxyList = nullptr;
+                mpProxyList.reset();
             }
             if( !mpProxyList )
             {
                 if( rTextNode.GetGrammarCheck() )
-                    mpProxyList = static_cast<SwGrammarMarkUp*>(rTextNode.GetGrammarCheck()->Clone());
+                    mpProxyList.reset( static_cast<SwGrammarMarkUp*>(rTextNode.GetGrammarCheck()->Clone()) );
                 else
                 {
-                    mpProxyList = new SwGrammarMarkUp();
+                    mpProxyList.reset( new SwGrammarMarkUp() );
                     mpProxyList->SetInvalid( 0, COMPLETE_STRING );
                 }
             }
            mbFinished = false;
         }
-        pRet = mpProxyList;
+        pRet = mpProxyList.get();
     }
     else
     {
@@ -153,8 +150,7 @@ void SwGrammarContact::Modify( const SfxPoolItem* pOld, const SfxPoolItem * )
     {    // if my current paragraph dies, I throw the proxy list away
         aTimer.Stop();
         EndListeningAll();
-        delete mpProxyList;
-        mpProxyList = nullptr;
+        mpProxyList.reset();
     }
 }
 


More information about the Libreoffice-commits mailing list