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

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Thu Jul 26 06:34:12 UTC 2018


 sw/inc/unotxdoc.hxx                |    4 ++--
 sw/source/uibase/inc/gloslst.hxx   |    2 +-
 sw/source/uibase/uno/unotxdoc.cxx  |   19 ++++++++++---------
 sw/source/uibase/utlui/gloslst.cxx |   32 ++++++++++++++------------------
 4 files changed, 27 insertions(+), 30 deletions(-)

New commits:
commit 1a0494b2dd3c2eaef8a5e83753dfc037d8fa56ae
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Wed Jul 25 12:31:55 2018 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Thu Jul 26 08:33:55 2018 +0200

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

diff --git a/sw/inc/unotxdoc.hxx b/sw/inc/unotxdoc.hxx
index f9fda4d3f216..d0ead1913fc1 100644
--- a/sw/inc/unotxdoc.hxx
+++ b/sw/inc/unotxdoc.hxx
@@ -174,8 +174,8 @@ private:
     SfxViewFrame*                                   m_pHiddenViewFrame;
     rtl::Reference<SwXDocumentPropertyHelper>       mxPropertyHelper;
 
-    SwPrintUIOptions *                              m_pPrintUIOptions;
-    SwRenderData *                                  m_pRenderData;
+    std::unique_ptr<SwPrintUIOptions>               m_pPrintUIOptions;
+    std::unique_ptr<SwRenderData>                   m_pRenderData;
 
     void                    GetNumberFormatter();
 
diff --git a/sw/source/uibase/uno/unotxdoc.cxx b/sw/source/uibase/uno/unotxdoc.cxx
index 73e69275a698..e2a33df53430 100644
--- a/sw/source/uibase/uno/unotxdoc.cxx
+++ b/sw/source/uibase/uno/unotxdoc.cxx
@@ -24,6 +24,7 @@
 #include <comphelper/string.hxx>
 #include <AnnotationWin.hxx>
 #include <o3tl/any.hxx>
+#include <o3tl/make_unique.hxx>
 #include <osl/mutex.hxx>
 #include <vcl/commandevent.hxx>
 #include <vcl/image.hxx>
@@ -192,7 +193,7 @@ using namespace ::com::sun::star::container;
 using namespace ::com::sun::star::document;
 using ::osl::FileBase;
 
-static SwPrintUIOptions * lcl_GetPrintUIOptions(
+static std::unique_ptr<SwPrintUIOptions> lcl_GetPrintUIOptions(
     SwDocShell * pDocShell,
     const SfxViewShell * pView )
 {
@@ -241,7 +242,7 @@ static SwPrintUIOptions * lcl_GetPrintUIOptions(
             pPage = static_cast<const SwPageFrame*>(pPage->GetNext());
         }
     }
-    return new SwPrintUIOptions( nCurrentPage, bWebDoc, bSwSrcView, bHasSelection, bHasPostIts, rPrintData );
+    return o3tl::make_unique<SwPrintUIOptions>( nCurrentPage, bWebDoc, bSwSrcView, bHasSelection, bHasPostIts, rPrintData );
 }
 
 static SwTextFormatColl *lcl_GetParaStyle(const OUString& rCollName, SwDoc* pDoc)
@@ -465,7 +466,7 @@ SwXTextDocument::~SwXTextDocument()
         xNumFormatAgg->setDelegator(x0);
         xNumFormatAgg = nullptr;
     }
-    delete m_pPrintUIOptions;
+    m_pPrintUIOptions.reset();
     if (m_pRenderData && m_pRenderData->IsViewOptionAdjust())
     {   // rhbz#827695: this can happen if the last page is not printed
         // the SwViewShell has been deleted already by SwView::~SwView
@@ -473,7 +474,7 @@ SwXTextDocument::~SwXTextDocument()
         // something less insane that has its own view
         m_pRenderData->ViewOptionAdjustCrashPreventionKludge();
     }
-    delete m_pRenderData;
+    m_pRenderData.reset();
 }
 
 SwXDocumentPropertyHelper * SwXTextDocument::GetPropertyHelper ()
@@ -2519,7 +2520,7 @@ sal_Int32 SAL_CALL SwXTextDocument::getRendererCount(
     SfxViewShell *pView = GetRenderView( bIsSwSrcView, rxOptions, bIsPDFExport );
 
     if (!bIsSwSrcView && !m_pRenderData)
-        m_pRenderData = new SwRenderData;
+        m_pRenderData.reset(new SwRenderData);
     if (!m_pPrintUIOptions)
         m_pPrintUIOptions = lcl_GetPrintUIOptions( pDocShell, pView );
     bool bFormat = m_pPrintUIOptions->processPropertiesAndCheckFormat( rxOptions );
@@ -2599,7 +2600,7 @@ sal_Int32 SAL_CALL SwXTextDocument::getRendererCount(
             }
 
             m_pRenderData->MakeSwPrtOptions( pRenderDocShell,
-                    m_pPrintUIOptions, bIsPDFExport );
+                    m_pPrintUIOptions.get(), bIsPDFExport );
 
             if (pSwView)
             {
@@ -2979,7 +2980,7 @@ void SAL_CALL SwXTextDocument::render(
     OSL_ENSURE( m_pRenderData, "data should have been created already in getRendererCount..." );
     OSL_ENSURE( m_pPrintUIOptions, "data should have been created already in getRendererCount..." );
     if (!bIsSwSrcView && !m_pRenderData)
-        m_pRenderData = new SwRenderData;
+        m_pRenderData.reset(new SwRenderData);
     if (!m_pPrintUIOptions)
         m_pPrintUIOptions = lcl_GetPrintUIOptions( pDocShell, pView );
     m_pPrintUIOptions->processProperties( rxOptions );
@@ -3107,8 +3108,8 @@ void SAL_CALL SwXTextDocument::render(
     }
     if( bLastPage )
     {
-        delete m_pRenderData;       m_pRenderData     = nullptr;
-        delete m_pPrintUIOptions;   m_pPrintUIOptions = nullptr;
+        m_pRenderData.reset();
+        m_pPrintUIOptions.reset();
     }
 }
 
commit a846c7106d4e4e1b8cc61e237cc2e158d037e816
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Wed Jul 25 12:26:15 2018 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Thu Jul 26 08:33:42 2018 +0200

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

diff --git a/sw/source/uibase/inc/gloslst.hxx b/sw/source/uibase/inc/gloslst.hxx
index b25e63fb2f48..bf6b8637d33b 100644
--- a/sw/source/uibase/inc/gloslst.hxx
+++ b/sw/source/uibase/inc/gloslst.hxx
@@ -45,7 +45,7 @@ struct AutoTextGroup
 
 class SwGlossaryList : public AutoTimer
 {
-    std::vector<AutoTextGroup*> aGroupArr;
+    std::vector<std::unique_ptr<AutoTextGroup>> aGroupArr;
     OUString        sPath;
     bool            bFilled;
 
diff --git a/sw/source/uibase/utlui/gloslst.cxx b/sw/source/uibase/utlui/gloslst.cxx
index ac543c9183f2..497c002933b8 100644
--- a/sw/source/uibase/utlui/gloslst.cxx
+++ b/sw/source/uibase/utlui/gloslst.cxx
@@ -111,7 +111,7 @@ bool SwGlossaryList::GetShortName(const OUString& rLongName,
     size_t nCount = aGroupArr.size();
     for(size_t i = 0; i < nCount; i++ )
     {
-        AutoTextGroup* pGroup = aGroupArr[i];
+        AutoTextGroup* pGroup = aGroupArr[i].get();
         if(!rGroupName.isEmpty() && rGroupName != pGroup->sName)
             continue;
 
@@ -176,7 +176,7 @@ OUString SwGlossaryList::GetGroupName(size_t nPos)
     OSL_ENSURE(aGroupArr.size() > nPos, "group not available");
     if(nPos < aGroupArr.size())
     {
-        AutoTextGroup* pGroup = aGroupArr[nPos];
+        AutoTextGroup* pGroup = aGroupArr[nPos].get();
         OUString sRet = pGroup->sName;
         return sRet;
     }
@@ -188,7 +188,7 @@ OUString SwGlossaryList::GetGroupTitle(size_t nPos)
     OSL_ENSURE(aGroupArr.size() > nPos, "group not available");
     if(nPos < aGroupArr.size())
     {
-        AutoTextGroup* pGroup = aGroupArr[nPos];
+        AutoTextGroup* pGroup = aGroupArr[nPos].get();
         return pGroup->sTitle;
     }
     return OUString();
@@ -199,7 +199,7 @@ sal_uInt16 SwGlossaryList::GetBlockCount(size_t nGroup)
     OSL_ENSURE(aGroupArr.size() > nGroup, "group not available");
     if(nGroup < aGroupArr.size())
     {
-        AutoTextGroup* pGroup = aGroupArr[nGroup];
+        AutoTextGroup* pGroup = aGroupArr[nGroup].get();
         return pGroup->nCount;
     }
     return 0;
@@ -210,7 +210,7 @@ OUString SwGlossaryList::GetBlockLongName(size_t nGroup, sal_uInt16 nBlock)
     OSL_ENSURE(aGroupArr.size() > nGroup, "group not available");
     if(nGroup < aGroupArr.size())
     {
-        AutoTextGroup* pGroup = aGroupArr[nGroup];
+        AutoTextGroup* pGroup = aGroupArr[nGroup].get();
         return pGroup->sLongNames.getToken(nBlock, STRING_DELIM);
     }
     return OUString();
@@ -221,7 +221,7 @@ OUString SwGlossaryList::GetBlockShortName(size_t nGroup, sal_uInt16 nBlock)
     OSL_ENSURE(aGroupArr.size() > nGroup, "group not available");
     if(nGroup < aGroupArr.size())
     {
-        AutoTextGroup* pGroup = aGroupArr[nGroup];
+        AutoTextGroup* pGroup = aGroupArr[nGroup].get();
         return pGroup->sShortNames.getToken(nBlock, STRING_DELIM);
     }
     return OUString();
@@ -253,17 +253,17 @@ void SwGlossaryList::Update()
                 sGrpName.getToken(1, GLOS_DELIM).toInt32());
             if( nPath < rPathArr.size() )
             {
-                AutoTextGroup* pGroup = new AutoTextGroup;
+                std::unique_ptr<AutoTextGroup> pGroup(new AutoTextGroup);
                 pGroup->sName = sGrpName;
 
-                FillGroup(pGroup, pGlossaries);
+                FillGroup(pGroup.get(), pGlossaries);
                 OUString sName = rPathArr[nPath] + "/" +
                     pGroup->sName.getToken(0, GLOS_DELIM) + sExt;
                 FStatHelper::GetModifiedDateTimeOfFile( sName,
                                                 &pGroup->aDateModified,
                                                 &pGroup->aDateModified );
 
-                aGroupArr.insert( aGroupArr.begin(), pGroup );
+                aGroupArr.insert( aGroupArr.begin(), std::move(pGroup) );
             }
         }
         bFilled = true;
@@ -295,7 +295,7 @@ void SwGlossaryList::Update()
                     FillGroup( pFound, pGlossaries );
                     pFound->aDateModified = *pDT;
 
-                    aGroupArr.push_back(pFound);
+                    aGroupArr.push_back(std::unique_ptr<AutoTextGroup>(pFound));
                 }
                 else if( pFound->aDateModified < *pDT )
                 {
@@ -311,7 +311,7 @@ void SwGlossaryList::Update()
             {
                 --i;
                 // maybe remove deleted groups
-                AutoTextGroup* pGroup = aGroupArr[i];
+                AutoTextGroup* pGroup = aGroupArr[i].get();
                 const size_t nGroupPath = static_cast<size_t>(
                     pGroup->sName.getToken( 1, GLOS_DELIM).toInt32());
                 // Only the groups will be checked which are registered
@@ -343,10 +343,10 @@ void SwGlossaryList::Invoke()
 
 AutoTextGroup* SwGlossaryList::FindGroup(const OUString& rGroupName)
 {
-    for(AutoTextGroup* pRet : aGroupArr)
+    for(auto & pRet : aGroupArr)
     {
         if(pRet->sName == rGroupName)
-            return pRet;
+            return pRet.get();
     }
     return nullptr;
 }
@@ -384,7 +384,7 @@ void SwGlossaryList::HasLongName(const OUString& rBegin, std::vector<OUString> *
 
     for(size_t i = 0; i < nCount; ++i)
     {
-        AutoTextGroup* pGroup = aGroupArr[i];
+        AutoTextGroup* pGroup = aGroupArr[i].get();
         for(sal_uInt16 j = 0; j < pGroup->nCount; j++)
         {
             OUString sBlock = pGroup->sLongNames.getToken(j, STRING_DELIM);
@@ -402,10 +402,6 @@ void SwGlossaryList::HasLongName(const OUString& rBegin, std::vector<OUString> *
 
 void    SwGlossaryList::ClearGroups()
 {
-    const size_t nCount = aGroupArr.size();
-    for( size_t i = 0; i < nCount; ++i )
-        delete aGroupArr[ i ];
-
     aGroupArr.clear();
     bFilled = false;
 }


More information about the Libreoffice-commits mailing list