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

Noel Grandin noel.grandin at collabora.co.uk
Tue Apr 3 12:42:59 UTC 2018


 sw/source/core/doc/swstylemanager.cxx |   29 +++++++++--------------------
 1 file changed, 9 insertions(+), 20 deletions(-)

New commits:
commit 3a09f1a04c6e60eb299fd1ac4b91ff6a67d12daf
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Tue Apr 3 11:45:07 2018 +0200

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

diff --git a/sw/source/core/doc/swstylemanager.cxx b/sw/source/core/doc/swstylemanager.cxx
index 77cd65a17165..e6bbab2822a8 100644
--- a/sw/source/core/doc/swstylemanager.cxx
+++ b/sw/source/core/doc/swstylemanager.cxx
@@ -57,18 +57,15 @@ class SwStyleManager : public IStyleAccess
 {
     StylePool aAutoCharPool;
     StylePool aAutoParaPool;
-    SwStyleCache *mpCharCache;
-    SwStyleCache *mpParaCache;
+    std::unique_ptr<SwStyleCache> mpCharCache;
+    std::unique_ptr<SwStyleCache> mpParaCache;
 
 public:
     // accept empty item set for ignorable paragraph items.
     explicit SwStyleManager( SfxItemSet const * pIgnorableParagraphItems )
         : aAutoCharPool(),
-          aAutoParaPool( pIgnorableParagraphItems ),
-          mpCharCache(nullptr),
-          mpParaCache(nullptr)
+          aAutoParaPool( pIgnorableParagraphItems )
     {}
-    virtual ~SwStyleManager() override;
     virtual std::shared_ptr<SfxItemSet> getAutomaticStyle( const SfxItemSet& rSet,
                                                                IStyleAccess::SwAutoStyleFamily eFamily ) override;
     virtual std::shared_ptr<SfxItemSet> getByName( const OUString& rName,
@@ -85,18 +82,10 @@ IStyleAccess *createStyleManager( SfxItemSet const * pIgnorableParagraphItems )
     return new SwStyleManager( pIgnorableParagraphItems );
 }
 
-SwStyleManager::~SwStyleManager()
-{
-    delete mpCharCache;
-    delete mpParaCache;
-}
-
 void SwStyleManager::clearCaches()
 {
-    delete mpCharCache;
-    mpCharCache = nullptr;
-    delete mpParaCache;
-    mpParaCache = nullptr;
+    mpCharCache.reset();
+    mpParaCache.reset();
 }
 
 std::shared_ptr<SfxItemSet> SwStyleManager::getAutomaticStyle( const SfxItemSet& rSet,
@@ -114,13 +103,13 @@ std::shared_ptr<SfxItemSet> SwStyleManager::cacheAutomaticStyle( const SfxItemSe
     if (eFamily == IStyleAccess::AUTO_STYLE_CHAR)
     {
         if (!mpCharCache)
-            mpCharCache = new SwStyleCache();
+            mpCharCache.reset(new SwStyleCache());
         mpCharCache->addStyleName( pStyle );
     }
     else
     {
         if (!mpParaCache)
-            mpParaCache = new SwStyleCache();
+            mpParaCache.reset(new SwStyleCache());
         mpParaCache->addStyleName( pStyle );
     }
     return pStyle;
@@ -130,9 +119,9 @@ std::shared_ptr<SfxItemSet> SwStyleManager::getByName( const OUString& rName,
                                                            IStyleAccess::SwAutoStyleFamily eFamily )
 {
     StylePool& rAutoPool = eFamily == IStyleAccess::AUTO_STYLE_CHAR ? aAutoCharPool : aAutoParaPool;
-    SwStyleCache* &rpCache = eFamily == IStyleAccess::AUTO_STYLE_CHAR ? mpCharCache : mpParaCache;
+    std::unique_ptr<SwStyleCache> &rpCache = eFamily == IStyleAccess::AUTO_STYLE_CHAR ? mpCharCache : mpParaCache;
     if( !rpCache )
-        rpCache = new SwStyleCache();
+        rpCache.reset(new SwStyleCache());
     std::shared_ptr<SfxItemSet> pStyle = rpCache->getByName( rName );
     if( !pStyle.get() )
     {


More information about the Libreoffice-commits mailing list