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

Noel Grandin noel.grandin at collabora.co.uk
Thu Mar 22 06:35:11 UTC 2018


 sw/source/core/doc/doctxm.cxx |   11 +++++------
 sw/source/core/inc/doctxm.hxx |   40 ++++++++++------------------------------
 2 files changed, 15 insertions(+), 36 deletions(-)

New commits:
commit 2074a7a42d5865ce2915a0e3c16535d5105c6e71
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Tue Mar 20 09:26:34 2018 +0200

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

diff --git a/sw/source/core/doc/doctxm.cxx b/sw/source/core/doc/doctxm.cxx
index 621f540c0e00..64310da59d4c 100644
--- a/sw/source/core/doc/doctxm.cxx
+++ b/sw/source/core/doc/doctxm.cxx
@@ -449,7 +449,7 @@ const SwAttrSet& SwDoc::GetTOXBaseAttrSet(const SwTOXBase& rTOXBase)
 
 const SwTOXBase* SwDoc::GetDefaultTOXBase( TOXTypes eTyp, bool bCreate )
 {
-    SwTOXBase** prBase = nullptr;
+    std::unique_ptr<SwTOXBase>* prBase = nullptr;
     switch(eTyp)
     {
     case  TOX_CONTENT:          prBase = &mpDefTOXBases->pContBase; break;
@@ -468,14 +468,14 @@ const SwTOXBase* SwDoc::GetDefaultTOXBase( TOXTypes eTyp, bool bCreate )
     {
         SwForm aForm(eTyp);
         const SwTOXType* pType = GetTOXType(eTyp, 0);
-        (*prBase) = new SwTOXBase(pType, aForm, SwTOXElement::NONE, pType->GetTypeName());
+        prBase->reset(new SwTOXBase(pType, aForm, SwTOXElement::NONE, pType->GetTypeName()));
     }
-    return (*prBase);
+    return prBase->get();
 }
 
 void    SwDoc::SetDefaultTOXBase(const SwTOXBase& rBase)
 {
-    SwTOXBase** prBase = nullptr;
+    std::unique_ptr<SwTOXBase>* prBase = nullptr;
     switch(rBase.GetType())
     {
     case  TOX_CONTENT:          prBase = &mpDefTOXBases->pContBase; break;
@@ -490,8 +490,7 @@ void    SwDoc::SetDefaultTOXBase(const SwTOXBase& rBase)
     }
     if (!prBase)
         return;
-    delete *prBase;
-    (*prBase) = new SwTOXBase(rBase);
+    prBase->reset(new SwTOXBase(rBase));
 }
 
 /// Delete table of contents
diff --git a/sw/source/core/inc/doctxm.hxx b/sw/source/core/inc/doctxm.hxx
index 1e7fc131fbae..39826f2eb8ec 100644
--- a/sw/source/core/inc/doctxm.hxx
+++ b/sw/source/core/inc/doctxm.hxx
@@ -85,38 +85,18 @@ public:
 
 struct SwDefTOXBase_Impl
 {
-    SwTOXBase* pContBase;
-    SwTOXBase* pIdxBase;
-    SwTOXBase* pUserBase;
-    SwTOXBase* pTableBase;
-    SwTOXBase* pObjBase;
-    SwTOXBase* pIllBase;
-    SwTOXBase* pAuthBase;
-    SwTOXBase* pBiblioBase;
-
-    SwDefTOXBase_Impl() :
-    pContBase(nullptr),
-    pIdxBase(nullptr),
-    pUserBase(nullptr),
-    pTableBase(nullptr),
-    pObjBase(nullptr),
-    pIllBase(nullptr),
-    pAuthBase(nullptr),
-    pBiblioBase(nullptr)
+    std::unique_ptr<SwTOXBase> pContBase;
+    std::unique_ptr<SwTOXBase> pIdxBase;
+    std::unique_ptr<SwTOXBase> pUserBase;
+    std::unique_ptr<SwTOXBase> pTableBase;
+    std::unique_ptr<SwTOXBase> pObjBase;
+    std::unique_ptr<SwTOXBase> pIllBase;
+    std::unique_ptr<SwTOXBase> pAuthBase;
+    std::unique_ptr<SwTOXBase> pBiblioBase;
+
+    SwDefTOXBase_Impl()
     {
     }
-    ~SwDefTOXBase_Impl()
-    {
-        delete pContBase;
-        delete pIdxBase;
-        delete pUserBase;
-        delete pTableBase;
-        delete pObjBase;
-        delete pIllBase;
-        delete pAuthBase;
-        delete pBiblioBase;
-    }
-
 };
 
 #endif


More information about the Libreoffice-commits mailing list