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

Noel Grandin noel.grandin at collabora.co.uk
Mon Mar 5 06:27:40 UTC 2018


 sfx2/source/appl/linksrc.cxx    |   54 ++++++++++++++++++----------------------
 sfx2/source/control/objface.cxx |   19 ++++----------
 sfx2/source/dialog/templdlg.cxx |   32 ++++++++---------------
 3 files changed, 43 insertions(+), 62 deletions(-)

New commits:
commit c9f01cc7855a20b1e0bff662cfbb75fe3665cd8a
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Wed Feb 28 14:37:10 2018 +0200

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

diff --git a/sfx2/source/control/objface.cxx b/sfx2/source/control/objface.cxx
index 244c8781fee5..78f561e3cedf 100644
--- a/sfx2/source/control/objface.cxx
+++ b/sfx2/source/control/objface.cxx
@@ -73,8 +73,10 @@ typedef std::vector<SfxObjectUI_Impl*> SfxObjectUIArr_Impl;
 
 struct SfxInterface_Impl
 {
-    SfxObjectUIArr_Impl     aObjectBars;    // registered ObjectBars
-    SfxObjectUIArr_Impl     aChildWindows;  // registered ChildWindows
+    std::vector<std::unique_ptr<SfxObjectUI_Impl>>
+                            aObjectBars;    // registered ObjectBars
+    std::vector<std::unique_ptr<SfxObjectUI_Impl>>
+                            aChildWindows;  // registered ChildWindows
     OUString                aPopupName;     // registered PopupMenu
     StatusBarId             eStatBarResId;  // registered StatusBar
     SfxModule*              pModule;
@@ -86,15 +88,6 @@ struct SfxInterface_Impl
         , bRegistered(false)
     {
     }
-
-    ~SfxInterface_Impl()
-    {
-        for (auto const& objectBar : aObjectBars)
-            delete objectBar;
-
-        for (auto const& childWindow : aChildWindows)
-            delete childWindow;
-    }
 };
 
 static SfxObjectUI_Impl* CreateObjectBarUI_Impl(sal_uInt16 nPos, SfxVisibilityFlags nFlags, ToolbarId eId, SfxShellFeature nFeature);
@@ -280,7 +273,7 @@ void SfxInterface::RegisterObjectBar(sal_uInt16 nPos, SfxVisibilityFlags nFlags,
 {
     SfxObjectUI_Impl* pUI = CreateObjectBarUI_Impl(nPos, nFlags, eId, nFeature);
     if ( pUI )
-        pImplData->aObjectBars.push_back(pUI);
+        pImplData->aObjectBars.emplace_back(pUI);
 }
 
 SfxObjectUI_Impl* CreateObjectBarUI_Impl(sal_uInt16 nPos, SfxVisibilityFlags nFlags, ToolbarId eId, SfxShellFeature nFeature)
@@ -365,7 +358,7 @@ void SfxInterface::RegisterChildWindow(sal_uInt16 nId, bool bContext, SfxShellFe
 {
     SfxObjectUI_Impl* pUI = new SfxObjectUI_Impl(0, SfxVisibilityFlags::Invisible, nId, nFeature);
     pUI->bContext = bContext;
-    pImplData->aChildWindows.push_back(pUI);
+    pImplData->aChildWindows.emplace_back(pUI);
 }
 
 void SfxInterface::RegisterStatusBar(StatusBarId eId)
diff --git a/sfx2/source/dialog/templdlg.cxx b/sfx2/source/dialog/templdlg.cxx
index 412b02f35110..7f1a9a77038b 100644
--- a/sfx2/source/dialog/templdlg.cxx
+++ b/sfx2/source/dialog/templdlg.cxx
@@ -499,7 +499,7 @@ void StyleTreeListBox_Impl::Recalc()
 
 /** Internal structure for the establishment of the hierarchical view */
 class StyleTree_Impl;
-typedef std::vector<StyleTree_Impl*> StyleTreeArr_Impl;
+typedef std::vector<std::unique_ptr<StyleTree_Impl>> StyleTreeArr_Impl;
 
 class StyleTree_Impl
 {
@@ -513,20 +513,14 @@ public:
 
     StyleTree_Impl(const OUString &rName, const OUString &rParent):
         aName(rName), aParent(rParent), pChildren(0) {}
-    ~StyleTree_Impl();
 
     const OUString& getName() { return aName; }
     const OUString& getParent() { return aParent; }
     StyleTreeArr_Impl& getChildren() { return pChildren; }
 };
 
-StyleTree_Impl::~StyleTree_Impl()
-{
-    for (auto const& child : pChildren)
-        delete child;
-}
 
-StyleTreeArr_Impl& MakeTree_Impl(StyleTreeArr_Impl& rArr)
+void MakeTree_Impl(StyleTreeArr_Impl& rArr)
 {
     const comphelper::string::NaturalStringSorter aSorter(
         ::comphelper::getProcessComponentContext(),
@@ -536,11 +530,11 @@ StyleTreeArr_Impl& MakeTree_Impl(StyleTreeArr_Impl& rArr)
     styleFinder.reserve(rArr.size());
     for (const auto& pEntry : rArr)
     {
-        styleFinder.emplace(pEntry->getName(), pEntry);
+        styleFinder.emplace(pEntry->getName(), pEntry.get());
     }
 
     // Arrange all under their Parents
-    for (const auto& pEntry : rArr)
+    for (auto& pEntry : rArr)
     {
         if (!pEntry->HasParent())
             continue;
@@ -550,21 +544,19 @@ StyleTreeArr_Impl& MakeTree_Impl(StyleTreeArr_Impl& rArr)
             StyleTree_Impl* pCmp = it->second;
             // Insert child entries sorted
             auto iPos = std::lower_bound(pCmp->getChildren().begin(), pCmp->getChildren().end(), pEntry,
-                [&aSorter](StyleTree_Impl* pEntry1, StyleTree_Impl* pEntry2) { return aSorter.compare(pEntry1->getName(), pEntry2->getName()) < 0; });
-            pCmp->getChildren().insert(iPos, pEntry);
+                [&aSorter](std::unique_ptr<StyleTree_Impl> const & pEntry1, std::unique_ptr<StyleTree_Impl> const & pEntry2) { return aSorter.compare(pEntry1->getName(), pEntry2->getName()) < 0; });
+            pCmp->getChildren().insert(iPos, std::move(pEntry));
         }
     }
 
     // Only keep tree roots in rArr, child elements can be accessed through the hierarchy
-    rArr.erase(std::remove_if(rArr.begin(), rArr.end(), [](StyleTree_Impl* pEntry) { return pEntry->HasParent(); }), rArr.end());
+    rArr.erase(std::remove_if(rArr.begin(), rArr.end(), [](std::unique_ptr<StyleTree_Impl> const & pEntry) { return !pEntry; }), rArr.end());
 
     // tdf#91106 sort top level styles
     std::sort(rArr.begin(), rArr.end(),
-        [&aSorter](StyleTree_Impl* pEntry1, StyleTree_Impl* pEntry2) {
+        [&aSorter](std::unique_ptr<StyleTree_Impl> const & pEntry1, std::unique_ptr<StyleTree_Impl> const & pEntry2) {
             return aSorter.compare(pEntry1->getName(), pEntry2->getName()) < 0;
         });
-
-    return rArr;
 }
 
 inline bool IsExpanded_Impl( const ExpandedEntries_t& rEntries,
@@ -595,7 +587,7 @@ SvTreeListEntry* FillBox_Impl(SvTreeListBox* pBox,
 
     for(size_t i = 0; i < pEntry->getChildren().size(); ++i)
     {
-        FillBox_Impl(pBox, pEntry->getChildren()[i], rEntries, eStyleFamily, pTreeListEntry);
+        FillBox_Impl(pBox, pEntry->getChildren()[i].get(), rEntries, eStyleFamily, pTreeListEntry);
     }
     return pTreeListEntry;
 }
@@ -1033,7 +1025,7 @@ void SfxCommonTemplateDialog_Impl::FillTreeBox()
         while (pStyle)
         {
             StyleTree_Impl* pNew = new StyleTree_Impl(pStyle->GetName(), pStyle->GetParent());
-            aArr.push_back(pNew);
+            aArr.emplace_back(pNew);
             pStyle = pStyleSheetPool->Next();
         }
 
@@ -1046,8 +1038,8 @@ void SfxCommonTemplateDialog_Impl::FillTreeBox()
 
         for (sal_uInt16 i = 0; i < nCount; ++i)
         {
-            FillBox_Impl(pTreeBox, aArr[i], aEntries, pItem->GetFamily(), nullptr);
-            delete aArr[i];
+            FillBox_Impl(pTreeBox, aArr[i].get(), aEntries, pItem->GetFamily(), nullptr);
+            aArr[i].reset();
         }
         pTreeBox->Recalc();
 
commit 260a443be052ba2c0c57584130a638341a2d3014
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Wed Feb 28 11:59:14 2018 +0200

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

diff --git a/sfx2/source/appl/linksrc.cxx b/sfx2/source/appl/linksrc.cxx
index f55bb31bab9d..ca97b745a814 100644
--- a/sfx2/source/appl/linksrc.cxx
+++ b/sfx2/source/appl/linksrc.cxx
@@ -86,44 +86,35 @@ struct SvLinkSource_Entry_Impl
 
 class SvLinkSource_Array_Impl
 {
+friend class SvLinkSource_EntryIter_Impl;
 private:
-    std::vector<SvLinkSource_Entry_Impl*> mvData;
+    std::vector<std::unique_ptr<SvLinkSource_Entry_Impl>> mvData;
 
 public:
     SvLinkSource_Array_Impl() : mvData() {}
 
     size_t size() const { return mvData.size(); }
-    SvLinkSource_Entry_Impl *operator[](size_t idx) const { return mvData[idx]; }
-    std::vector<SvLinkSource_Entry_Impl*>::const_iterator cbegin() const { return mvData.cbegin(); }
-    std::vector<SvLinkSource_Entry_Impl*>::const_iterator cend() const { return mvData.cend(); }
-    void clear() { mvData.clear(); }
-    void push_back(SvLinkSource_Entry_Impl* rData) { mvData.push_back(rData); }
+    SvLinkSource_Entry_Impl *operator[](size_t idx) const { return mvData[idx].get(); }
+    void push_back(SvLinkSource_Entry_Impl* rData) { mvData.emplace_back(rData); }
 
     void DeleteAndDestroy(SvLinkSource_Entry_Impl* p)
     {
-        std::vector<SvLinkSource_Entry_Impl*>::iterator it = std::find(mvData.begin(), mvData.end(), p);
-        if (it != mvData.end())
-        {
-            mvData.erase(it);
-            delete p;
-        }
-    }
-
-    ~SvLinkSource_Array_Impl()
-    {
-        for (auto const& elem : mvData)
-            delete elem;
+        for (auto it = mvData.begin(); it != mvData.end(); ++it)
+            if (it->get() == p)
+            {
+                mvData.erase(it);
+                break;
+            }
     }
 };
 
 class SvLinkSource_EntryIter_Impl
 {
-    SvLinkSource_Array_Impl aArr;
+    std::vector<SvLinkSource_Entry_Impl*> aArr;
     const SvLinkSource_Array_Impl& rOrigArr;
     sal_uInt16 nPos;
 public:
     explicit SvLinkSource_EntryIter_Impl( const SvLinkSource_Array_Impl& rArr );
-    ~SvLinkSource_EntryIter_Impl();
     SvLinkSource_Entry_Impl* Curr()
                             { return nPos < aArr.size() ? aArr[ nPos ] : nullptr; }
     SvLinkSource_Entry_Impl* Next();
@@ -132,18 +123,22 @@ public:
 
 SvLinkSource_EntryIter_Impl::SvLinkSource_EntryIter_Impl(
         const SvLinkSource_Array_Impl& rArr )
-    : aArr( rArr ), rOrigArr( rArr ), nPos( 0 )
+    : rOrigArr( rArr ), nPos( 0 )
 {
-}
-SvLinkSource_EntryIter_Impl::~SvLinkSource_EntryIter_Impl()
-{
-    aArr.clear();
+    for (auto const & i : rArr.mvData)
+        aArr.push_back(i.get());
 }
 
 bool SvLinkSource_EntryIter_Impl::IsValidCurrValue( SvLinkSource_Entry_Impl* pEntry )
 {
-    return ( nPos < aArr.size() && aArr[nPos] == pEntry
-       && std::find( rOrigArr.cbegin(), rOrigArr.cend(), pEntry ) != rOrigArr.cend() );
+    if ( nPos >= aArr.size() )
+        return false;
+    if (aArr[nPos] != pEntry)
+        return false;
+    for (auto const & i : rOrigArr.mvData)
+        if (i.get() == pEntry)
+            return true;
+    return false;
 }
 
 SvLinkSource_Entry_Impl* SvLinkSource_EntryIter_Impl::Next()
@@ -160,8 +155,9 @@ SvLinkSource_Entry_Impl* SvLinkSource_EntryIter_Impl::Next()
             // then we must search the current (or the next) in the orig
             do {
                 pRet = aArr[ nPos ];
-                if( std::find(rOrigArr.cbegin(), rOrigArr.cend(), pRet ) != rOrigArr.cend() )
-                    break;
+                for (auto const & i : rOrigArr.mvData)
+                    if (i.get() == pRet)
+                        return pRet;
                 pRet = nullptr;
                 ++nPos;
             } while( nPos < aArr.size() );


More information about the Libreoffice-commits mailing list