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

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Mon Jan 14 06:02:57 UTC 2019


 sw/source/uibase/app/mainwn.cxx |   54 ++++++++++++++++++++--------------------
 1 file changed, 27 insertions(+), 27 deletions(-)

New commits:
commit 101cd1b9cfb2b080a838f3253e6d7f37f483a372
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Fri Jan 11 15:38:54 2019 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Mon Jan 14 07:02:36 2019 +0100

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

diff --git a/sw/source/uibase/app/mainwn.cxx b/sw/source/uibase/app/mainwn.cxx
index 36a34038f856..8adb6212e4ad 100644
--- a/sw/source/uibase/app/mainwn.cxx
+++ b/sw/source/uibase/app/mainwn.cxx
@@ -30,17 +30,17 @@ struct SwProgress
     long nStartValue,
          nStartCount;
     SwDocShell  *pDocShell;
-    SfxProgress *pProgress;
+    std::unique_ptr<SfxProgress> pProgress;
 };
 
-static std::vector<SwProgress*> *pProgressContainer = nullptr;
+static std::vector<std::unique_ptr<SwProgress>> *pProgressContainer = nullptr;
 
 static SwProgress *lcl_SwFindProgress( SwDocShell const *pDocShell )
 {
-    for (SwProgress* pTmp : *pProgressContainer)
+    for (auto& pTmp : *pProgressContainer)
     {
         if ( pTmp->pDocShell == pDocShell )
-            return pTmp;
+            return pTmp.get();
     }
     return nullptr;
 }
@@ -48,29 +48,31 @@ static SwProgress *lcl_SwFindProgress( SwDocShell const *pDocShell )
 void StartProgress( const char* pMessResId, long nStartValue, long nEndValue,
                     SwDocShell *pDocShell )
 {
-    if( !SW_MOD()->IsEmbeddedLoadSave() )
+    if( SW_MOD()->IsEmbeddedLoadSave() )
+        return;
+
+    SwProgress *pProgress = nullptr;
+
+    if ( !pProgressContainer )
+        pProgressContainer = new std::vector<std::unique_ptr<SwProgress>>;
+    else
     {
-        SwProgress *pProgress = nullptr;
+        pProgress = lcl_SwFindProgress( pDocShell );
+        if ( pProgress )
+            ++pProgress->nStartCount;
+    }
 
-        if ( !pProgressContainer )
-            pProgressContainer = new std::vector<SwProgress*>;
-        else
-        {
-            if ( nullptr != (pProgress = lcl_SwFindProgress( pDocShell )) )
-                ++pProgress->nStartCount;
-        }
-        if ( !pProgress )
-        {
-            pProgress = new SwProgress;
-            pProgress->pProgress = new SfxProgress( pDocShell,
-                                                    SwResId(pMessResId),
-                                                    nEndValue - nStartValue );
-            pProgress->nStartCount = 1;
-            pProgress->pDocShell = pDocShell;
-            pProgressContainer->insert( pProgressContainer->begin(), pProgress );
-        }
-        pProgress->nStartValue = nStartValue;
+    if ( !pProgress )
+    {
+        pProgress = new SwProgress;
+        pProgress->pProgress.reset( new SfxProgress( pDocShell,
+                                                SwResId(pMessResId),
+                                                nEndValue - nStartValue ) );
+        pProgress->nStartCount = 1;
+        pProgress->pDocShell = pDocShell;
+        pProgressContainer->insert( pProgressContainer->begin(), std::unique_ptr<SwProgress>(pProgress) );
     }
+    pProgress->nStartValue = nStartValue;
 }
 
 void SetProgressState( long nPosition, SwDocShell const *pDocShell )
@@ -91,7 +93,7 @@ void EndProgress( SwDocShell const *pDocShell )
         std::vector<SwProgress *>::size_type i;
         for ( i = 0; i < pProgressContainer->size(); ++i )
         {
-            SwProgress *pTmp = (*pProgressContainer)[i];
+            SwProgress *pTmp = (*pProgressContainer)[i].get();
             if ( pTmp->pDocShell == pDocShell )
             {
                 pProgress = pTmp;
@@ -103,8 +105,6 @@ void EndProgress( SwDocShell const *pDocShell )
         {
             pProgress->pProgress->Stop();
             pProgressContainer->erase( pProgressContainer->begin() + i );
-            delete pProgress->pProgress;
-            delete pProgress;
             //#112337# it may happen that the container has been removed
             //while rescheduling
             if ( pProgressContainer && pProgressContainer->empty() )


More information about the Libreoffice-commits mailing list