[Libreoffice-commits] core.git: include/svx svx/source

Noel Grandin noel.grandin at collabora.co.uk
Tue Oct 17 07:01:21 UTC 2017


 include/svx/xmleohlp.hxx    |    9 ++++-----
 svx/source/xml/xmleohlp.cxx |   37 ++++++++++---------------------------
 2 files changed, 14 insertions(+), 32 deletions(-)

New commits:
commit 7fac547c442aa699d94c48e40fcf8b58f9457161
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Mon Oct 16 13:51:35 2017 +0200

    use rtl::Reference in SvXMLEmbeddedObjectHelper
    
    instead of manual ref counting
    
    Change-Id: I6b88b72dd28183feca46fc04841a2e8f19e5c47a
    Reviewed-on: https://gerrit.libreoffice.org/43421
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
    Tested-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/include/svx/xmleohlp.hxx b/include/svx/xmleohlp.hxx
index 8d93889e3723..b2aafdac31f3 100644
--- a/include/svx/xmleohlp.hxx
+++ b/include/svx/xmleohlp.hxx
@@ -22,12 +22,13 @@
 
 #include <cppuhelper/compbase.hxx>
 #include <osl/mutex.hxx>
-#include <map>
 #include <com/sun/star/container/XNameContainer.hpp>
 #include <com/sun/star/document/XEmbeddedObjectResolver.hpp>
 #include <com/sun/star/container/XNameAccess.hpp>
 #include <com/sun/star/embed/XEmbeddedObject.hpp>
 #include <svx/svxdllapi.h>
+#include <map>
+#include <memory>
 
 enum class SvXMLEmbeddedObjectHelperMode
 {
@@ -43,9 +44,6 @@ class OutputStorageWrapper_Impl;
 class SVX_DLLPUBLIC SvXMLEmbeddedObjectHelper :
     public cppu::WeakComponentImplHelper< css::document::XEmbeddedObjectResolver, css::container::XNameAccess >
 {
-    typedef ::std::map< OUString, OutputStorageWrapper_Impl* > SvXMLEmbeddedObjectHelper_Impl;
-private:
-
     ::osl::Mutex                maMutex;
 
     const OUString       maReplacementGraphicsContainerStorageName;
@@ -59,7 +57,8 @@ private:
     css::uno::Reference < css::embed::XStorage > mxTempStorage;  // package
                                                 // objects
     SvXMLEmbeddedObjectHelperMode       meCreateMode;
-    SvXMLEmbeddedObjectHelper_Impl      *mpStreamMap;
+    std::unique_ptr<std::map< OUString, rtl::Reference<OutputStorageWrapper_Impl> >>
+                                                 mpStreamMap;
 
     SVX_DLLPRIVATE bool                 ImplGetStorageNames(
                                        const OUString& rURLStr,
diff --git a/svx/source/xml/xmleohlp.cxx b/svx/source/xml/xmleohlp.cxx
index c349ef624bdb..ed3babc126a7 100644
--- a/svx/source/xml/xmleohlp.cxx
+++ b/svx/source/xml/xmleohlp.cxx
@@ -141,20 +141,6 @@ SvXMLEmbeddedObjectHelper::SvXMLEmbeddedObjectHelper( ::comphelper::IEmbeddedHel
 
 SvXMLEmbeddedObjectHelper::~SvXMLEmbeddedObjectHelper()
 {
-    if( mpStreamMap )
-    {
-        SvXMLEmbeddedObjectHelper_Impl::iterator aIter = mpStreamMap->begin();
-        SvXMLEmbeddedObjectHelper_Impl::iterator aEnd = mpStreamMap->end();
-        for( ; aIter != aEnd; ++aIter )
-        {
-            if( aIter->second )
-            {
-                aIter->second->release();
-                aIter->second = nullptr;
-            }
-        }
-        delete mpStreamMap;
-    }
 }
 
 void SAL_CALL SvXMLEmbeddedObjectHelper::disposing()
@@ -447,13 +433,13 @@ OUString SvXMLEmbeddedObjectHelper::ImplInsertEmbeddedObjectURL(
     if( SvXMLEmbeddedObjectHelperMode::Read == meCreateMode )
     {
         OutputStorageWrapper_Impl *pOut = nullptr;
-        SvXMLEmbeddedObjectHelper_Impl::iterator aIter;
+        std::map< OUString, rtl::Reference<OutputStorageWrapper_Impl> >::iterator aIter;
 
         if( mpStreamMap )
         {
             aIter = mpStreamMap->find( rURLStr );
-            if( aIter != mpStreamMap->end() && aIter->second )
-                pOut = aIter->second;
+            if( aIter != mpStreamMap->end() && aIter->second.is() )
+                pOut = aIter->second.get();
         }
 
         SvGlobalName aClassId, *pClassId = nullptr;
@@ -471,7 +457,6 @@ OUString SvXMLEmbeddedObjectHelper::ImplInsertEmbeddedObjectURL(
         if( pOut )
         {
             mpStreamMap->erase( aIter );
-            pOut->release();
         }
     }
     else
@@ -600,19 +585,17 @@ Any SAL_CALL SvXMLEmbeddedObjectHelper::getByName(
         Reference < XOutputStream > xStrm;
         if( mpStreamMap )
         {
-            SvXMLEmbeddedObjectHelper_Impl::iterator aIter =
-                mpStreamMap->find( rURLStr );
-            if( aIter != mpStreamMap->end() && aIter->second )
-                xStrm = aIter->second;
+            auto aIter = mpStreamMap->find( rURLStr );
+            if( aIter != mpStreamMap->end() && aIter->second.is() )
+                xStrm = aIter->second.get();
         }
         if( !xStrm.is() )
         {
-            OutputStorageWrapper_Impl *pOut = new OutputStorageWrapper_Impl;
-            pOut->acquire();
+            rtl::Reference<OutputStorageWrapper_Impl> xOut = new OutputStorageWrapper_Impl;
             if( !mpStreamMap )
-                mpStreamMap = new SvXMLEmbeddedObjectHelper_Impl;
-            (*mpStreamMap)[rURLStr] = pOut;
-            xStrm = pOut;
+                mpStreamMap.reset( new std::map< OUString, rtl::Reference<OutputStorageWrapper_Impl> > );
+            (*mpStreamMap)[rURLStr] = xOut;
+            xStrm = xOut.get();
         }
 
         aRet <<= xStrm;


More information about the Libreoffice-commits mailing list