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

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Sat Oct 6 06:15:36 UTC 2018


 sd/source/ui/inc/tools/SdGlobalResourceContainer.hxx |    2 -
 sd/source/ui/tools/SdGlobalResourceContainer.cxx     |   35 ++++++-------------
 2 files changed, 13 insertions(+), 24 deletions(-)

New commits:
commit 49ea32064a28675a735fd270d07fd6ea8e7e03b6
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Fri Oct 5 10:02:08 2018 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Sat Oct 6 08:15:14 2018 +0200

    use more uniqueptr in SdGlobalResourceContainer
    
    Change-Id: I2cfd478032066c7e4cd930d098a086711b99934f
    Reviewed-on: https://gerrit.libreoffice.org/61431
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/sd/source/ui/inc/tools/SdGlobalResourceContainer.hxx b/sd/source/ui/inc/tools/SdGlobalResourceContainer.hxx
index 34f12a6dc546..6409bff17d07 100644
--- a/sd/source/ui/inc/tools/SdGlobalResourceContainer.hxx
+++ b/sd/source/ui/inc/tools/SdGlobalResourceContainer.hxx
@@ -66,7 +66,7 @@ public:
 
         When in doubt, use the shared_ptr variant of this method.
     */
-    void AddResource (::std::unique_ptr<SdGlobalResource> && pResource);
+    void AddResource (::std::unique_ptr<SdGlobalResource> pResource);
 
     /** Add a resource to the container.  By using a shared_ptr and
         releasing it only when the SgGlobalResourceContainer is destroyed
diff --git a/sd/source/ui/tools/SdGlobalResourceContainer.cxx b/sd/source/ui/tools/SdGlobalResourceContainer.cxx
index b6408cdf04be..3eab1474f43d 100644
--- a/sd/source/ui/tools/SdGlobalResourceContainer.cxx
+++ b/sd/source/ui/tools/SdGlobalResourceContainer.cxx
@@ -68,8 +68,7 @@ private:
     /** All instances of SdGlobalResource in this vector are owned by the
         container and will be destroyed when the container is destroyed.
     */
-    typedef ::std::vector<SdGlobalResource*> ResourceList;
-    ResourceList maResources;
+    std::vector<std::unique_ptr<SdGlobalResource>> maResources;
 
     typedef ::std::vector<std::shared_ptr<SdGlobalResource> > SharedResourceList;
     SharedResourceList maSharedResources;
@@ -89,27 +88,17 @@ SdGlobalResourceContainer& SdGlobalResourceContainer::Instance()
 //===== SdGlobalResourceContainer =============================================
 
 void SdGlobalResourceContainer::AddResource (
-    ::std::unique_ptr<SdGlobalResource> && pResource)
+    ::std::unique_ptr<SdGlobalResource> pResource)
 {
     ::osl::MutexGuard aGuard (mpImpl->maMutex);
 
-    Implementation::ResourceList::iterator iResource;
-    iResource = ::std::find (
-        mpImpl->maResources.begin(),
-        mpImpl->maResources.end(),
-        pResource.get());
-    if (iResource == mpImpl->maResources.end())
-        mpImpl->maResources.push_back(pResource.get());
-    else
-    {
-        // Because the given resource is a unique_ptr it is highly unlikely
-        // that we come here.  But who knows?
-        SAL_WARN ( "sd.tools",
-            "SdGlobalResourceContainer:AddResource(): Resource added twice.");
-    }
-    // We can not put the unique_ptr into the vector so we release the
-    // unique_ptr and document that we take ownership explicitly.
-    pResource.release();
+    assert( std::none_of(
+                mpImpl->maResources.begin(),
+                mpImpl->maResources.end(),
+                [&](const std::unique_ptr<SdGlobalResource>& p) { return p == pResource; })
+            && "duplicate resource?");
+
+    mpImpl->maResources.push_back(std::move(pResource));
 }
 
 void SdGlobalResourceContainer::AddResource (
@@ -162,14 +151,14 @@ SdGlobalResourceContainer::~SdGlobalResourceContainer()
     // container.  This is because a resource A added before resource B
     // may have been created due to a request of B.  Thus B depends on A and
     // should be destroyed first.
-    Implementation::ResourceList::reverse_iterator iResource;
-    for (iResource = mpImpl->maResources.rbegin();
+    for (auto iResource = mpImpl->maResources.rbegin();
          iResource != mpImpl->maResources.rend();
          ++iResource)
     {
-        delete *iResource;
+        iResource->reset();
     }
 
+
     // The SharedResourceList has not to be released manually.  We just
     // assert resources that are still held by someone other than us.
     Implementation::SharedResourceList::reverse_iterator iSharedResource;


More information about the Libreoffice-commits mailing list