[Libreoffice-commits] core.git: 2 commits - sfx2/source vcl/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Wed Oct 31 06:33:35 UTC 2018


 sfx2/source/dialog/splitwin.cxx |    5 ++---
 vcl/source/window/accel.cxx     |   39 ++++++++++++++++-----------------------
 2 files changed, 18 insertions(+), 26 deletions(-)

New commits:
commit 7b8e5bbfb5819ee6fec544792c14e91bc6075d29
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Tue Oct 30 11:14:42 2018 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Wed Oct 31 07:33:23 2018 +0100

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

diff --git a/sfx2/source/dialog/splitwin.cxx b/sfx2/source/dialog/splitwin.cxx
index 36302fb5957f..9dd57d90615a 100644
--- a/sfx2/source/dialog/splitwin.cxx
+++ b/sfx2/source/dialog/splitwin.cxx
@@ -243,7 +243,7 @@ SfxSplitWindow::SfxSplitWindow( vcl::Window* pParent, SfxChildAlignment eAl,
             sal_uInt16 nCount = static_cast<sal_uInt16>(aWinData.getToken(i++, ',').toInt32());
             for ( sal_uInt16 n=0; n<nCount; n++ )
             {
-                SfxDock_Impl *pDock = new SfxDock_Impl;
+                std::unique_ptr<SfxDock_Impl> pDock(new SfxDock_Impl);
                 pDock->pWin = nullptr;
                 pDock->bNewLine = false;
                 pDock->bHide = true;
@@ -255,14 +255,13 @@ SfxSplitWindow::SfxSplitWindow( vcl::Window* pParent, SfxChildAlignment eAl,
                     if ( !pDock->nType )
                     {
                         // Read error
-                        delete pDock;
                         break;
                     }
                     else
                         pDock->bNewLine = true;
                 }
 
-                maDockArr.insert(maDockArr.begin() + n, std::unique_ptr<SfxDock_Impl>(pDock));
+                maDockArr.insert(maDockArr.begin() + n, std::move(pDock));
             }
         }
     }
commit ea277ae70ee7f676ffa21fc1e7dd06ce06616d27
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Mon Oct 29 14:39:45 2018 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Wed Oct 31 07:33:07 2018 +0100

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

diff --git a/vcl/source/window/accel.cxx b/vcl/source/window/accel.cxx
index 7ba39842a2af..7222111e883d 100644
--- a/vcl/source/window/accel.cxx
+++ b/vcl/source/window/accel.cxx
@@ -26,7 +26,7 @@
 #include <vector>
 
 typedef ::std::map< sal_uLong, ImplAccelEntry* > ImplAccelMap;
-typedef ::std::vector< ImplAccelEntry* > ImplAccelList;
+typedef ::std::vector< std::unique_ptr<ImplAccelEntry> > ImplAccelList;
 
 #define ACCELENTRY_NOTFOUND     (sal_uInt16(0xFFFF))
 
@@ -84,7 +84,7 @@ static sal_uInt16 ImplAccelEntryGetIndex( ImplAccelList* pList, sal_uInt16 nId,
     return ACCELENTRY_NOTFOUND;
 }
 
-static void ImplAccelEntryInsert( ImplAccelList* pList, ImplAccelEntry* pEntry )
+static void ImplAccelEntryInsert( ImplAccelList* pList, std::unique_ptr<ImplAccelEntry> pEntry )
 {
     sal_uInt16  nInsIndex(0);
     std::vector<ImplAccelEntry *>::size_type nIndex = ImplAccelEntryGetIndex( pList, pEntry->mnId, &nInsIndex );
@@ -96,27 +96,23 @@ static void ImplAccelEntryInsert( ImplAccelList* pList, ImplAccelEntry* pEntry )
             nIndex++;
             ImplAccelEntry* pTempEntry = nullptr;
             if ( nIndex < pList->size() )
-                pTempEntry = (*pList)[ nIndex ];
+                pTempEntry = (*pList)[ nIndex ].get();
             if ( !pTempEntry || (pTempEntry->mnId != pEntry->mnId) )
                 break;
         }
         while ( nIndex < pList->size() );
 
         if ( nIndex < pList->size() ) {
-            ImplAccelList::iterator it = pList->begin();
-            ::std::advance( it, nIndex );
-            pList->insert( it, pEntry );
+            pList->insert( pList->begin() + nIndex, std::move(pEntry) );
         } else {
-            pList->push_back( pEntry );
+            pList->push_back( std::move(pEntry) );
         }
     }
     else {
         if ( nInsIndex < pList->size() ) {
-            ImplAccelList::iterator it = pList->begin();
-            ::std::advance( it, nInsIndex );
-            pList->insert( it, pEntry );
+            pList->insert( pList->begin() + nInsIndex, std::move(pEntry) );
         } else {
-            pList->push_back( pEntry );
+            pList->push_back( std::move(pEntry) );
         }
     }
 }
@@ -139,9 +135,9 @@ ImplAccelEntry* Accelerator::ImplGetAccelData( const vcl::KeyCode& rKeyCode ) co
 void Accelerator::ImplCopyData( ImplAccelData& rAccelData )
 {
     // copy table
-    for (ImplAccelEntry* i : rAccelData.maIdList)
+    for (std::unique_ptr<ImplAccelEntry>& i : rAccelData.maIdList)
     {
-        ImplAccelEntry* pEntry = new ImplAccelEntry( *i );
+        std::unique_ptr<ImplAccelEntry> pEntry(new ImplAccelEntry( *i ));
 
         // sequence accelerator, then copy also
         if ( pEntry->mpAccel )
@@ -152,17 +148,16 @@ void Accelerator::ImplCopyData( ImplAccelData& rAccelData )
         else
             pEntry->mpAutoAccel = nullptr;
 
-        mpData->maKeyMap.insert( std::make_pair( pEntry->maKeyCode.GetFullCode(), pEntry ) );
-        mpData->maIdList.push_back( pEntry );
+        mpData->maKeyMap.insert( std::make_pair( pEntry->maKeyCode.GetFullCode(), pEntry.get() ) );
+        mpData->maIdList.push_back( std::move(pEntry) );
     }
 }
 
 void Accelerator::ImplDeleteData()
 {
     // delete accelerator-entries using the id-table
-    for (ImplAccelEntry* pEntry : mpData->maIdList) {
+    for (std::unique_ptr<ImplAccelEntry>& pEntry : mpData->maIdList) {
         delete pEntry->mpAutoAccel;
-        delete pEntry;
     }
     mpData->maIdList.clear();
 }
@@ -197,7 +192,7 @@ void Accelerator::ImplInsertAccel( sal_uInt16 nItemId, const vcl::KeyCode& rKeyC
     }
 
     // fetch and fill new entries
-    ImplAccelEntry* pEntry  = new ImplAccelEntry;
+    std::unique_ptr<ImplAccelEntry> pEntry(new ImplAccelEntry);
     pEntry->mnId            = nItemId;
     pEntry->maKeyCode       = rKeyCode;
     pEntry->mpAccel         = pAutoAccel;
@@ -209,15 +204,13 @@ void Accelerator::ImplInsertAccel( sal_uInt16 nItemId, const vcl::KeyCode& rKeyC
     if ( !nCode )
     {
         OSL_FAIL( "Accelerator::InsertItem(): KeyCode with KeyCode 0 not allowed" );
-        delete pEntry;
     }
-    else if ( !mpData->maKeyMap.insert( std::make_pair( nCode, pEntry ) ).second )
+    else if ( !mpData->maKeyMap.insert( std::make_pair( nCode, pEntry.get() ) ).second )
     {
         SAL_WARN( "vcl", "Accelerator::InsertItem(): KeyCode (Key: " << nCode << ") already exists" );
-        delete pEntry;
     }
     else
-        ImplAccelEntryInsert( &(mpData->maIdList), pEntry );
+        ImplAccelEntryInsert( &(mpData->maIdList), std::move(pEntry) );
 }
 
 Accelerator::Accelerator()
@@ -268,7 +261,7 @@ sal_uInt16 Accelerator::GetItemCount() const
 sal_uInt16 Accelerator::GetItemId( sal_uInt16 nPos ) const
 {
 
-    ImplAccelEntry* pEntry = ( nPos < mpData->maIdList.size() ) ? mpData->maIdList[ nPos ] : nullptr;
+    ImplAccelEntry* pEntry = ( nPos < mpData->maIdList.size() ) ? mpData->maIdList[ nPos ].get() : nullptr;
     if ( pEntry )
         return pEntry->mnId;
     else


More information about the Libreoffice-commits mailing list