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

Noel Grandin noel.grandin at collabora.co.uk
Mon Jan 29 06:19:40 UTC 2018


 ucb/source/ucp/file/bc.cxx                |   46 +++++++-----------------
 ucb/source/ucp/file/bc.hxx                |    8 ++--
 ucb/source/ucp/tdoc/tdoc_datasupplier.cxx |   57 ++++++++----------------------
 3 files changed, 35 insertions(+), 76 deletions(-)

New commits:
commit 1168956b91987beb6065498fa6fba05477ebf480
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Tue Jan 23 15:09:42 2018 +0200

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

diff --git a/ucb/source/ucp/file/bc.cxx b/ucb/source/ucp/file/bc.cxx
index 4f076002ac8c..cb669916e8c8 100644
--- a/ucb/source/ucp/file/bc.cxx
+++ b/ucb/source/ucp/file/bc.cxx
@@ -128,11 +128,6 @@ BaseContent::~BaseContent( )
         m_pMyShell->deregisterNotifier( m_aUncPath,this );
     }
     m_pMyShell->m_pProvider->release();
-
-    delete m_pDisposeEventListeners;
-    delete m_pContentEventListeners;
-    delete m_pPropertyListener;
-    delete m_pPropertySetInfoChangeListeners;
 }
 
 
@@ -182,8 +177,8 @@ BaseContent::addEventListener( const Reference< lang::XEventListener >& Listener
     osl::MutexGuard aGuard( m_aMutex );
 
     if ( ! m_pDisposeEventListeners )
-        m_pDisposeEventListeners =
-            new comphelper::OInterfaceContainerHelper2( m_aEventListenerMutex );
+        m_pDisposeEventListeners.reset(
+            new comphelper::OInterfaceContainerHelper2( m_aEventListenerMutex ) );
 
     m_pDisposeEventListeners->addInterface( Listener );
 }
@@ -203,27 +198,19 @@ void SAL_CALL
 BaseContent::dispose()
 {
     lang::EventObject aEvt;
-    comphelper::OInterfaceContainerHelper2* pDisposeEventListeners;
-    comphelper::OInterfaceContainerHelper2* pContentEventListeners;
-    comphelper::OInterfaceContainerHelper2* pPropertySetInfoChangeListeners;
-    PropertyListeners* pPropertyListener;
+    std::unique_ptr<comphelper::OInterfaceContainerHelper2> pDisposeEventListeners;
+    std::unique_ptr<comphelper::OInterfaceContainerHelper2> pContentEventListeners;
+    std::unique_ptr<comphelper::OInterfaceContainerHelper2> pPropertySetInfoChangeListeners;
+    std::unique_ptr<PropertyListeners> pPropertyListener;
 
     {
         osl::MutexGuard aGuard( m_aMutex );
         aEvt.Source = static_cast< XContent* >( this );
 
-
-        pDisposeEventListeners = m_pDisposeEventListeners;
-        m_pDisposeEventListeners = nullptr;
-
-        pContentEventListeners = m_pContentEventListeners;
-        m_pContentEventListeners = nullptr;
-
-        pPropertySetInfoChangeListeners = m_pPropertySetInfoChangeListeners;
-        m_pPropertySetInfoChangeListeners = nullptr;
-
-        pPropertyListener = m_pPropertyListener;
-        m_pPropertyListener = nullptr;
+        pDisposeEventListeners = std::move(m_pDisposeEventListeners);
+        pContentEventListeners = std::move(m_pContentEventListeners);
+        pPropertySetInfoChangeListeners = std::move(m_pPropertySetInfoChangeListeners);
+        pPropertyListener = std::move(m_pPropertyListener);
     }
 
     if ( pDisposeEventListeners && pDisposeEventListeners->getLength() )
@@ -237,11 +224,6 @@ BaseContent::dispose()
 
     if( pPropertySetInfoChangeListeners )
         pPropertySetInfoChangeListeners->disposeAndClear( aEvt );
-
-    delete pDisposeEventListeners;
-    delete pContentEventListeners;
-    delete pPropertyListener;
-    delete pPropertySetInfoChangeListeners;
 }
 
 //  XServiceInfo
@@ -422,7 +404,7 @@ BaseContent::addPropertiesChangeListener(
     osl::MutexGuard aGuard( m_aMutex );
 
     if( ! m_pPropertyListener )
-        m_pPropertyListener = new PropertyListeners( m_aEventListenerMutex );
+        m_pPropertyListener.reset( new PropertyListeners( m_aEventListenerMutex ) );
 
 
     if( PropertyNames.getLength() == 0 )
@@ -521,8 +503,8 @@ BaseContent::addContentEventListener(
     osl::MutexGuard aGuard( m_aMutex );
 
     if ( ! m_pContentEventListeners )
-        m_pContentEventListeners =
-            new comphelper::OInterfaceContainerHelper2( m_aEventListenerMutex );
+        m_pContentEventListeners.reset(
+            new comphelper::OInterfaceContainerHelper2( m_aEventListenerMutex ) );
 
 
     m_pContentEventListeners->addInterface( Listener );
@@ -646,7 +628,7 @@ BaseContent::addPropertySetInfoChangeListener(
 {
     osl::MutexGuard aGuard( m_aMutex );
     if( ! m_pPropertySetInfoChangeListeners )
-        m_pPropertySetInfoChangeListeners = new comphelper::OInterfaceContainerHelper2( m_aEventListenerMutex );
+        m_pPropertySetInfoChangeListeners.reset( new comphelper::OInterfaceContainerHelper2( m_aEventListenerMutex ) );
 
     m_pPropertySetInfoChangeListeners->addInterface( Listener );
 }
diff --git a/ucb/source/ucp/file/bc.hxx b/ucb/source/ucp/file/bc.hxx
index 09ed60c34e37..34db251539ab 100644
--- a/ucb/source/ucp/file/bc.hxx
+++ b/ucb/source/ucp/file/bc.hxx
@@ -232,10 +232,10 @@ namespace fileaccess {
         osl::Mutex                         m_aMutex;
 
         osl::Mutex                          m_aEventListenerMutex;
-        comphelper::OInterfaceContainerHelper2*   m_pDisposeEventListeners;
-        comphelper::OInterfaceContainerHelper2*   m_pContentEventListeners;
-        comphelper::OInterfaceContainerHelper2*   m_pPropertySetInfoChangeListeners;
-        PropertyListeners*                  m_pPropertyListener;
+        std::unique_ptr<comphelper::OInterfaceContainerHelper2>   m_pDisposeEventListeners;
+        std::unique_ptr<comphelper::OInterfaceContainerHelper2>   m_pContentEventListeners;
+        std::unique_ptr<comphelper::OInterfaceContainerHelper2>   m_pPropertySetInfoChangeListeners;
+        std::unique_ptr<PropertyListeners>                  m_pPropertyListener;
 
 
         // Private Methods
commit 53d6326bfa033692b801cba66a0af174f0666087
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Tue Jan 23 15:06:31 2018 +0200

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

diff --git a/ucb/source/ucp/tdoc/tdoc_datasupplier.cxx b/ucb/source/ucp/tdoc/tdoc_datasupplier.cxx
index 5a36dded1271..e446092b4ac2 100644
--- a/ucb/source/ucp/tdoc/tdoc_datasupplier.cxx
+++ b/ucb/source/ucp/tdoc/tdoc_datasupplier.cxx
@@ -45,7 +45,7 @@ namespace tdoc_ucp
 
 struct ResultListEntry
 {
-    OUString                             aURL;
+    OUString                                  aURL;
     uno::Reference< ucb::XContentIdentifier > xId;
     uno::Reference< ucb::XContent >           xContent;
     uno::Reference< sdbc::XRow >              xRow;
@@ -54,22 +54,16 @@ struct ResultListEntry
 };
 
 
-// ResultList.
-
-
-typedef std::vector< ResultListEntry* > ResultList;
-
-
 // struct DataSupplier_Impl.
 
 
 struct DataSupplier_Impl
 {
     osl::Mutex                                   m_aMutex;
-    ResultList                                   m_aResults;
+    std::vector< ResultListEntry >               m_aResults;
     rtl::Reference< Content >                    m_xContent;
     uno::Reference< uno::XComponentContext >     m_xContext;
-    uno::Sequence< OUString > *                  m_pNamesOfChildren;
+    std::unique_ptr<uno::Sequence< OUString > >  m_pNamesOfChildren;
     bool                                         m_bCountFinal;
     bool                                         m_bThrowException;
 
@@ -77,27 +71,11 @@ struct DataSupplier_Impl
             const uno::Reference< uno::XComponentContext >& rxContext,
             const rtl::Reference< Content >& rContent )
     : m_xContent( rContent ), m_xContext( rxContext ),
-      m_pNamesOfChildren( nullptr ),
       m_bCountFinal( false ), m_bThrowException( false )
     {}
-    ~DataSupplier_Impl();
 };
 
 
-DataSupplier_Impl::~DataSupplier_Impl()
-{
-    ResultList::const_iterator it  = m_aResults.begin();
-    ResultList::const_iterator end = m_aResults.end();
-
-    while ( it != end )
-    {
-        delete *it;
-        ++it;
-    }
-
-    delete m_pNamesOfChildren;
-}
-
 }
 
 // DataSupplier Implementation.
@@ -121,7 +99,7 @@ ResultSetDataSupplier::queryContentIdentifierString( sal_uInt32 nIndex )
 
     if ( nIndex < m_pImpl->m_aResults.size() )
     {
-        OUString aId = m_pImpl->m_aResults[ nIndex ]->aURL;
+        OUString aId = m_pImpl->m_aResults[ nIndex ].aURL;
         if ( !aId.isEmpty() )
         {
             // Already cached.
@@ -132,7 +110,7 @@ ResultSetDataSupplier::queryContentIdentifierString( sal_uInt32 nIndex )
     if ( getResult( nIndex ) )
     {
         // Note: getResult fills m_pImpl->m_aResults[ nIndex ]->aURL.
-        return m_pImpl->m_aResults[ nIndex ]->aURL;
+        return m_pImpl->m_aResults[ nIndex ].aURL;
     }
     return OUString();
 }
@@ -146,7 +124,7 @@ ResultSetDataSupplier::queryContentIdentifier( sal_uInt32 nIndex )
     if ( nIndex < m_pImpl->m_aResults.size() )
     {
         uno::Reference< ucb::XContentIdentifier > xId
-                                = m_pImpl->m_aResults[ nIndex ]->xId;
+                                = m_pImpl->m_aResults[ nIndex ].xId;
         if ( xId.is() )
         {
             // Already cached.
@@ -159,7 +137,7 @@ ResultSetDataSupplier::queryContentIdentifier( sal_uInt32 nIndex )
     {
         uno::Reference< ucb::XContentIdentifier > xId
             = new ::ucbhelper::ContentIdentifier( aId );
-        m_pImpl->m_aResults[ nIndex ]->xId = xId;
+        m_pImpl->m_aResults[ nIndex ].xId = xId;
         return xId;
     }
     return uno::Reference< ucb::XContentIdentifier >();
@@ -174,7 +152,7 @@ ResultSetDataSupplier::queryContent( sal_uInt32 nIndex )
     if ( nIndex < m_pImpl->m_aResults.size() )
     {
         uno::Reference< ucb::XContent > xContent
-                                = m_pImpl->m_aResults[ nIndex ]->xContent;
+                                = m_pImpl->m_aResults[ nIndex ].xContent;
         if ( xContent.is() )
         {
             // Already cached.
@@ -190,7 +168,7 @@ ResultSetDataSupplier::queryContent( sal_uInt32 nIndex )
         {
             uno::Reference< ucb::XContent > xContent
                 = m_pImpl->m_xContent->getProvider()->queryContent( xId );
-            m_pImpl->m_aResults[ nIndex ]->xContent = xContent;
+            m_pImpl->m_aResults[ nIndex ].xContent = xContent;
             return xContent;
 
         }
@@ -241,7 +219,7 @@ bool ResultSetDataSupplier::getResult( sal_uInt32 nIndex )
             // Assemble URL for child.
             OUString aURL = assembleChildURL( rName );
 
-            m_pImpl->m_aResults.push_back( new ResultListEntry( aURL ) );
+            m_pImpl->m_aResults.emplace_back( aURL );
 
             if ( n == nIndex )
             {
@@ -300,7 +278,7 @@ sal_uInt32 ResultSetDataSupplier::totalCount()
             // Assemble URL for child.
             OUString aURL = assembleChildURL( rName );
 
-            m_pImpl->m_aResults.push_back( new ResultListEntry( aURL ) );
+            m_pImpl->m_aResults.emplace_back( aURL );
         }
     }
 
@@ -341,7 +319,7 @@ ResultSetDataSupplier::queryPropertyValues( sal_uInt32 nIndex  )
 
     if ( nIndex < m_pImpl->m_aResults.size() )
     {
-        uno::Reference< sdbc::XRow > xRow = m_pImpl->m_aResults[ nIndex ]->xRow;
+        uno::Reference< sdbc::XRow > xRow = m_pImpl->m_aResults[ nIndex ].xRow;
         if ( xRow.is() )
         {
             // Already cached.
@@ -356,7 +334,7 @@ ResultSetDataSupplier::queryPropertyValues( sal_uInt32 nIndex  )
                         getResultSet()->getProperties(),
                         m_pImpl->m_xContent->getContentProvider().get(),
                         queryContentIdentifierString( nIndex ) );
-        m_pImpl->m_aResults[ nIndex ]->xRow = xRow;
+        m_pImpl->m_aResults[ nIndex ].xRow = xRow;
         return xRow;
     }
 
@@ -369,7 +347,7 @@ void ResultSetDataSupplier::releasePropertyValues( sal_uInt32 nIndex )
     osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
 
     if ( nIndex < m_pImpl->m_aResults.size() )
-        m_pImpl->m_aResults[ nIndex ]->xRow.clear();
+        m_pImpl->m_aResults[ nIndex ].xRow.clear();
 }
 
 // virtual
@@ -390,21 +368,20 @@ bool ResultSetDataSupplier::queryNamesOfChildren()
 
     if ( m_pImpl->m_pNamesOfChildren == nullptr )
     {
-        uno::Sequence< OUString > * pNamesOfChildren
-            = new uno::Sequence< OUString >();
+        std::unique_ptr<uno::Sequence< OUString >> pNamesOfChildren(
+            new uno::Sequence< OUString >() );
 
         if ( !m_pImpl->m_xContent->getContentProvider()->queryNamesOfChildren(
                 m_pImpl->m_xContent->getIdentifier()->getContentIdentifier(),
                 *pNamesOfChildren ) )
         {
             OSL_FAIL( "Got no list of children!" );
-            delete pNamesOfChildren;
             m_pImpl->m_bThrowException = true;
             return false;
         }
         else
         {
-            m_pImpl->m_pNamesOfChildren = pNamesOfChildren;
+            m_pImpl->m_pNamesOfChildren = std::move( pNamesOfChildren );
         }
     }
     return true;


More information about the Libreoffice-commits mailing list