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

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Thu Oct 4 09:31:55 UTC 2018


 sw/source/core/inc/swblocks.hxx        |    2 +-
 sw/source/core/swg/SwXMLTextBlocks.cxx |    5 ++---
 sw/source/core/swg/swblocks.cxx        |   14 +++++---------
 3 files changed, 8 insertions(+), 13 deletions(-)

New commits:
commit 56f1e2e081d29112b345df08f039a2cecbd9743d
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Wed Oct 3 14:32:08 2018 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Thu Oct 4 11:31:30 2018 +0200

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

diff --git a/sw/source/core/inc/swblocks.hxx b/sw/source/core/inc/swblocks.hxx
index cce94ffc2a22..d1a3116ec98b 100644
--- a/sw/source/core/inc/swblocks.hxx
+++ b/sw/source/core/inc/swblocks.hxx
@@ -48,7 +48,7 @@ public:
     bool operator< ( const SwBlockName& r ) const { return aShort <  r.aShort; }
 };
 
-class SwBlockNames : public o3tl::sorted_vector<SwBlockName*, o3tl::less_ptr_to<SwBlockName> > {};
+class SwBlockNames : public o3tl::sorted_vector<std::unique_ptr<SwBlockName>, o3tl::less_uniqueptr_to<SwBlockName> > {};
 
 class SwImpBlocks
 {
diff --git a/sw/source/core/swg/SwXMLTextBlocks.cxx b/sw/source/core/swg/SwXMLTextBlocks.cxx
index 34012be29642..4828ab1afcf6 100644
--- a/sw/source/core/swg/SwXMLTextBlocks.cxx
+++ b/sw/source/core/swg/SwXMLTextBlocks.cxx
@@ -148,13 +148,12 @@ void SwXMLTextBlocks::AddName( const OUString& rShort, const OUString& rLong,
     sal_uInt16 nIdx = GetIndex( rShort );
     if (nIdx != USHRT_MAX)
     {
-        delete m_aNames[nIdx];
         m_aNames.erase( m_aNames.begin() + nIdx );
     }
-    SwBlockName* pNew = new SwBlockName( rShort, rLong, rPackageName );
+    std::unique_ptr<SwBlockName> pNew(new SwBlockName( rShort, rLong, rPackageName ));
     pNew->bIsOnlyTextFlagInit = true;
     pNew->bIsOnlyText = bOnlyText;
-    m_aNames.insert( pNew );
+    m_aNames.insert( std::move(pNew) );
     m_bInfoChanged = true;
 }
 
diff --git a/sw/source/core/swg/swblocks.cxx b/sw/source/core/swg/swblocks.cxx
index 11f76c80c751..b5b3513395e7 100644
--- a/sw/source/core/swg/swblocks.cxx
+++ b/sw/source/core/swg/swblocks.cxx
@@ -102,7 +102,6 @@ SwImpBlocks::SwImpBlocks( const OUString& rFile )
 
 SwImpBlocks::~SwImpBlocks()
 {
-    m_aNames.DeleteAndDestroyAll();
 }
 
 /**
@@ -140,7 +139,7 @@ sal_uInt16 SwImpBlocks::GetIndex( const OUString& rShort ) const
     const sal_uInt16 nHash = Hash( s );
     for( size_t i = 0; i < m_aNames.size(); i++ )
     {
-        const SwBlockName* pName = m_aNames[ i ];
+        const SwBlockName* pName = m_aNames[ i ].get();
         if( pName->nHashS == nHash
          && pName->aShort == s )
             return i;
@@ -153,7 +152,7 @@ sal_uInt16 SwImpBlocks::GetLongIndex( const OUString& rLong ) const
     sal_uInt16 nHash = Hash( rLong );
     for( size_t i = 0; i < m_aNames.size(); i++ )
     {
-        const SwBlockName* pName = m_aNames[ i ];
+        const SwBlockName* pName = m_aNames[ i ].get();
         if( pName->nHashL == nHash
          && pName->aLong == rLong )
             return i;
@@ -188,13 +187,12 @@ void SwImpBlocks::AddName( const OUString& rShort, const OUString& rLong,
     sal_uInt16 nIdx = GetIndex( rShort );
     if( nIdx != USHRT_MAX )
     {
-        delete m_aNames[nIdx];
         m_aNames.erase( m_aNames.begin() + nIdx );
     }
-    SwBlockName* pNew = new SwBlockName( rShort, rLong );
+    std::unique_ptr<SwBlockName> pNew(new SwBlockName( rShort, rLong ));
     pNew->bIsOnlyTextFlagInit = true;
     pNew->bIsOnlyText = bOnlyText;
-    m_aNames.insert( pNew );
+    m_aNames.insert( std::move(pNew) );
 }
 
 bool SwImpBlocks::IsFileChanged() const
@@ -312,7 +310,6 @@ bool SwTextBlocks::Delete( sal_uInt16 n )
             nErr = pImp->Delete( n );
             if( !nErr )
             {
-                delete pImp->m_aNames[n];
                 pImp->m_aNames.erase( pImp->m_aNames.begin() + n );
             }
             if( n == pImp->m_nCurrentIndex )
@@ -356,7 +353,6 @@ void SwTextBlocks::Rename( sal_uInt16 n, const OUString* s, const OUString* l )
             if( !nErr )
             {
                 bool bOnlyText = pImp->m_aNames[ n ]->bIsOnlyText;
-                delete pImp->m_aNames[n];
                 pImp->m_aNames.erase( pImp->m_aNames.begin() + n );
                 pImp->AddName( aNew, aLong, bOnlyText );
                 nErr = pImp->MakeBlockList();
@@ -539,7 +535,7 @@ bool SwTextBlocks::IsOnlyTextBlock( sal_uInt16 nIdx ) const
     bool bRet = false;
     if( pImp && !pImp->m_bInPutMuchBlocks )
     {
-        SwBlockName* pBlkNm = pImp->m_aNames[ nIdx ];
+        SwBlockName* pBlkNm = pImp->m_aNames[ nIdx ].get();
         if( !pBlkNm->bIsOnlyTextFlagInit &&
             !pImp->IsFileChanged() && !pImp->OpenFile() )
         {


More information about the Libreoffice-commits mailing list