include/comphelper/interfacecontainer4.hxx | 13 ++++---- sc/inc/fielduno.hxx | 4 +- sc/source/ui/unoobj/fielduno.cxx | 32 +++++++------------ ucb/source/cacher/contentresultsetwrapper.cxx | 14 ++------ ucb/source/cacher/contentresultsetwrapper.hxx | 4 +- ucb/source/cacher/dynamicresultsetwrapper.cxx | 13 ++------ ucb/source/cacher/dynamicresultsetwrapper.hxx | 4 +- ucb/source/core/ucbstore.cxx | 42 +++++++------------------- ucb/source/core/ucbstore.hxx | 4 +- 9 files changed, 47 insertions(+), 83 deletions(-)
New commits: commit 0e6e0270d25c4181ed15bd04123e20672f1e3a0b Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Tue Feb 14 13:14:14 2023 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Tue Feb 14 16:57:09 2023 +0000 no need to use unique_ptr for OInterfaceContainerHelper4 it has an empty size of one pointer, so it saves no memory to use unique_ptr. Need to fix the const-ness of some methods in OInterfaceContainerHelper4 Change-Id: I0c0c28a228ccfe0e97174fbc83555059fc351b3c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/147007 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/include/comphelper/interfacecontainer4.hxx b/include/comphelper/interfacecontainer4.hxx index 7f6e72bf91f1..3a6696fda8c5 100644 --- a/include/comphelper/interfacecontainer4.hxx +++ b/include/comphelper/interfacecontainer4.hxx @@ -200,7 +200,7 @@ public: this parameter only here to make that this container is accessed while locked */ template <typename FuncT> - inline void forEach(std::unique_lock<std::mutex>& rGuard, FuncT const& func); + inline void forEach(std::unique_lock<std::mutex>& rGuard, FuncT const& func) const; /** Calls a UNO listener method for each contained listener. @@ -227,7 +227,7 @@ public: template <typename EventT> inline void notifyEach(std::unique_lock<std::mutex>& rGuard, void (SAL_CALL ListenerT::*NotificationMethod)(const EventT&), - const EventT& Event); + const EventT& Event) const; private: friend class OInterfaceIteratorHelper4<ListenerT>; @@ -279,14 +279,15 @@ inline OInterfaceContainerHelper4<T>::OInterfaceContainerHelper4() template <class T> template <typename FuncT> inline void OInterfaceContainerHelper4<T>::forEach(std::unique_lock<std::mutex>& rGuard, - FuncT const& func) + FuncT const& func) const { if (std::as_const(maData)->size() == 0) { return; } - maData.make_unique(); // so we can iterate over the data without holding the lock - OInterfaceIteratorHelper4<T> iter(rGuard, *this); + const_cast<OInterfaceContainerHelper4&>(*this) + .maData.make_unique(); // so we can iterate over the data without holding the lock + OInterfaceIteratorHelper4<T> iter(rGuard, const_cast<OInterfaceContainerHelper4&>(*this)); rGuard.unlock(); while (iter.hasMoreElements()) { @@ -312,7 +313,7 @@ template <class ListenerT> template <typename EventT> inline void OInterfaceContainerHelper4<ListenerT>::notifyEach( std::unique_lock<std::mutex>& rGuard, - void (SAL_CALL ListenerT::*NotificationMethod)(const EventT&), const EventT& Event) + void (SAL_CALL ListenerT::*NotificationMethod)(const EventT&), const EventT& Event) const { forEach<NotifySingleListener<EventT>>(rGuard, NotifySingleListener<EventT>(NotificationMethod, Event)); diff --git a/sc/inc/fielduno.hxx b/sc/inc/fielduno.hxx index 7cf455c7bcc3..82c9a04ebb87 100644 --- a/sc/inc/fielduno.hxx +++ b/sc/inc/fielduno.hxx @@ -60,7 +60,7 @@ private: ScAddress aCellPos; std::unique_ptr<ScEditSource> mpEditSource; /// List of refresh listeners. - std::unique_ptr<comphelper::OInterfaceContainerHelper4<css::util::XRefreshListener>> mpRefreshListeners; + comphelper::OInterfaceContainerHelper4<css::util::XRefreshListener> maRefreshListeners; /// mutex to lock the InterfaceContainerHelper std::mutex aMutex; @@ -114,7 +114,7 @@ private: std::unique_ptr<ScEditSource> mpEditSource; /// List of refresh listeners. - std::unique_ptr<comphelper::OInterfaceContainerHelper4<css::util::XRefreshListener>> mpRefreshListeners; + comphelper::OInterfaceContainerHelper4<css::util::XRefreshListener> maRefreshListeners; /// mutex to lock the InterfaceContainerHelper std::mutex aMutex; diff --git a/sc/source/ui/unoobj/fielduno.cxx b/sc/source/ui/unoobj/fielduno.cxx index 2a05a24fab75..aacb4e2e3815 100644 --- a/sc/source/ui/unoobj/fielduno.cxx +++ b/sc/source/ui/unoobj/fielduno.cxx @@ -289,12 +289,11 @@ ScCellFieldsObj::~ScCellFieldsObj() osl_atomic_increment( &m_refCount ); std::unique_lock g(aMutex); - if (mpRefreshListeners) + if (maRefreshListeners.getLength(g)) { lang::EventObject aEvent; aEvent.Source.set(static_cast<cppu::OWeakObject*>(this)); - mpRefreshListeners->disposeAndClear(g, aEvent); - mpRefreshListeners.reset(); + maRefreshListeners.disposeAndClear(g, aEvent); } } @@ -387,12 +386,12 @@ void SAL_CALL ScCellFieldsObj::removeContainerListener( void SAL_CALL ScCellFieldsObj::refresh( ) { std::unique_lock g(aMutex); - if (mpRefreshListeners) + if (maRefreshListeners.getLength(g)) { // Call all listeners. lang::EventObject aEvent; aEvent.Source.set(uno::Reference< util::XRefreshable >(this)); - mpRefreshListeners->notifyEach( g, &util::XRefreshListener::refreshed, aEvent ); + maRefreshListeners.notifyEach( g, &util::XRefreshListener::refreshed, aEvent ); } } @@ -401,9 +400,7 @@ void SAL_CALL ScCellFieldsObj::addRefreshListener( const uno::Reference< util::X if (xListener.is()) { std::unique_lock g(aMutex); - if (!mpRefreshListeners) - mpRefreshListeners.reset( new comphelper::OInterfaceContainerHelper4<util::XRefreshListener>() ); - mpRefreshListeners->addInterface(g, xListener); + maRefreshListeners.addInterface(g, xListener); } } @@ -412,8 +409,7 @@ void SAL_CALL ScCellFieldsObj::removeRefreshListener( const uno::Reference<util: if (xListener.is()) { std::unique_lock g(aMutex); - if (mpRefreshListeners) - mpRefreshListeners->removeInterface(g, xListener); + maRefreshListeners.removeInterface(g, xListener); } } @@ -431,12 +427,11 @@ ScHeaderFieldsObj::~ScHeaderFieldsObj() osl_atomic_increment( &m_refCount ); std::unique_lock g(aMutex); - if (mpRefreshListeners) + if (maRefreshListeners.getLength(g)) { lang::EventObject aEvent; aEvent.Source = static_cast<cppu::OWeakObject*>(this); - mpRefreshListeners->disposeAndClear(g, aEvent); - mpRefreshListeners.reset(); + maRefreshListeners.disposeAndClear(g, aEvent); } } @@ -539,12 +534,12 @@ void SAL_CALL ScHeaderFieldsObj::removeContainerListener( void SAL_CALL ScHeaderFieldsObj::refresh( ) { std::unique_lock g(aMutex); - if (mpRefreshListeners) + if (maRefreshListeners.getLength(g)) { // Call all listeners. lang::EventObject aEvent; aEvent.Source.set(uno::Reference< util::XRefreshable >(this)); - mpRefreshListeners->notifyEach( g, &util::XRefreshListener::refreshed, aEvent); + maRefreshListeners.notifyEach( g, &util::XRefreshListener::refreshed, aEvent); } } @@ -553,9 +548,7 @@ void SAL_CALL ScHeaderFieldsObj::addRefreshListener( const uno::Reference< util: if (xListener.is()) { std::unique_lock g(aMutex); - if (!mpRefreshListeners) - mpRefreshListeners.reset(new comphelper::OInterfaceContainerHelper4<util::XRefreshListener>()); - mpRefreshListeners->addInterface(g, xListener); + maRefreshListeners.addInterface(g, xListener); } } @@ -564,8 +557,7 @@ void SAL_CALL ScHeaderFieldsObj::removeRefreshListener( const uno::Reference<uti if (xListener.is()) { std::unique_lock g(aMutex); - if (mpRefreshListeners) - mpRefreshListeners->removeInterface(g, xListener); + maRefreshListeners.removeInterface(g, xListener); } } diff --git a/ucb/source/cacher/contentresultsetwrapper.cxx b/ucb/source/cacher/contentresultsetwrapper.cxx index e5917f3fdbc5..14393ff497f4 100644 --- a/ucb/source/cacher/contentresultsetwrapper.cxx +++ b/ucb/source/cacher/contentresultsetwrapper.cxx @@ -299,11 +299,11 @@ void SAL_CALL ContentResultSetWrapper::dispose() aGuard.lock(); isCleared = false; } - if( m_pDisposeEventListeners && m_pDisposeEventListeners->getLength(aGuard) ) + if( m_aDisposeEventListeners.getLength(aGuard) ) { EventObject aEvt; aEvt.Source = static_cast< XComponent * >( this ); - m_pDisposeEventListeners->disposeAndClear( aGuard, aEvt ); + m_aDisposeEventListeners.disposeAndClear( aGuard, aEvt ); } if( m_pPropertyChangeListeners ) @@ -331,11 +331,7 @@ void SAL_CALL ContentResultSetWrapper::addEventListener( const Reference< XEvent std::unique_lock aGuard( m_aMutex ); impl_EnsureNotDisposed(aGuard); - if ( !m_pDisposeEventListeners ) - m_pDisposeEventListeners.reset( - new OInterfaceContainerHelper4<XEventListener>() ); - - m_pDisposeEventListeners->addInterface( aGuard, Listener ); + m_aDisposeEventListeners.addInterface( aGuard, Listener ); } @@ -344,9 +340,7 @@ void SAL_CALL ContentResultSetWrapper::removeEventListener( const Reference< XEv { std::unique_lock aGuard( m_aMutex ); impl_EnsureNotDisposed(aGuard); - - if ( m_pDisposeEventListeners ) - m_pDisposeEventListeners->removeInterface( aGuard, Listener ); + m_aDisposeEventListeners.removeInterface( aGuard, Listener ); } diff --git a/ucb/source/cacher/contentresultsetwrapper.hxx b/ucb/source/cacher/contentresultsetwrapper.hxx index 4c67ca89ef29..4c1ae370ff20 100644 --- a/ucb/source/cacher/contentresultsetwrapper.hxx +++ b/ucb/source/cacher/contentresultsetwrapper.hxx @@ -85,8 +85,8 @@ private: //management of listeners bool m_bDisposed; ///Dispose call ready. bool m_bInDispose;///In dispose call - std::unique_ptr<comphelper::OInterfaceContainerHelper4<css::lang::XEventListener>> - m_pDisposeEventListeners; + comphelper::OInterfaceContainerHelper4<css::lang::XEventListener> + m_aDisposeEventListeners; std::unique_ptr<PropertyChangeListenerContainer_Impl> m_pPropertyChangeListeners; std::unique_ptr<VetoableChangeListenerContainer_Impl> diff --git a/ucb/source/cacher/dynamicresultsetwrapper.cxx b/ucb/source/cacher/dynamicresultsetwrapper.cxx index 8ad5b53f3055..db881dad492f 100644 --- a/ucb/source/cacher/dynamicresultsetwrapper.cxx +++ b/ucb/source/cacher/dynamicresultsetwrapper.cxx @@ -133,11 +133,11 @@ void SAL_CALL DynamicResultSetWrapper::dispose() xSourceComponent = m_xSource; - if( m_pDisposeEventListeners && m_pDisposeEventListeners->getLength(aGuard) ) + if( m_aDisposeEventListeners.getLength(aGuard) ) { EventObject aEvt; aEvt.Source = static_cast< XComponent * >( this ); - m_pDisposeEventListeners->disposeAndClear( aGuard, aEvt ); + m_aDisposeEventListeners.disposeAndClear( aGuard, aEvt ); } /* //@todo ?? ( only if java collection needs to long ) @@ -156,11 +156,7 @@ void SAL_CALL DynamicResultSetWrapper::addEventListener( const Reference< XEvent impl_EnsureNotDisposed(); std::unique_lock aGuard( m_aMutex ); - if ( !m_pDisposeEventListeners ) - m_pDisposeEventListeners.reset( - new OInterfaceContainerHelper4<XEventListener>() ); - - m_pDisposeEventListeners->addInterface( aGuard, Listener ); + m_aDisposeEventListeners.addInterface( aGuard, Listener ); } @@ -170,8 +166,7 @@ void SAL_CALL DynamicResultSetWrapper::removeEventListener( const Reference< XEv impl_EnsureNotDisposed(); std::unique_lock aGuard( m_aMutex ); - if ( m_pDisposeEventListeners ) - m_pDisposeEventListeners->removeInterface( aGuard, Listener ); + m_aDisposeEventListeners.removeInterface( aGuard, Listener ); } diff --git a/ucb/source/cacher/dynamicresultsetwrapper.hxx b/ucb/source/cacher/dynamicresultsetwrapper.hxx index 66548a64b420..a7917506d874 100644 --- a/ucb/source/cacher/dynamicresultsetwrapper.hxx +++ b/ucb/source/cacher/dynamicresultsetwrapper.hxx @@ -41,8 +41,8 @@ private: //management of listeners bool m_bDisposed; ///Dispose call ready. bool m_bInDispose;///In dispose call - std::unique_ptr<comphelper::OInterfaceContainerHelper4<css::lang::XEventListener>> - m_pDisposeEventListeners; + comphelper::OInterfaceContainerHelper4<css::lang::XEventListener> + m_aDisposeEventListeners; protected: rtl::Reference<DynamicResultSetWrapperListener> m_xMyListenerImpl; diff --git a/ucb/source/core/ucbstore.cxx b/ucb/source/core/ucbstore.cxx index 65c0e531e2e2..75ec9aa0a270 100644 --- a/ucb/source/core/ucbstore.cxx +++ b/ucb/source/core/ucbstore.cxx @@ -1053,20 +1053,18 @@ css::uno::Sequence< OUString > SAL_CALL PersistentPropertySet::getSupportedServi void SAL_CALL PersistentPropertySet::dispose() { std::unique_lock l(m_aMutex); - if ( m_pDisposeEventListeners && - m_pDisposeEventListeners->getLength(l) ) + if ( m_aDisposeEventListeners.getLength(l) ) { EventObject aEvt; aEvt.Source = static_cast< XComponent * >( this ); - m_pDisposeEventListeners->disposeAndClear( l, aEvt ); + m_aDisposeEventListeners.disposeAndClear( l, aEvt ); } - if ( m_pPropSetChangeListeners && - m_pPropSetChangeListeners->getLength(l) ) + if ( m_aPropSetChangeListeners.getLength(l) ) { EventObject aEvt; aEvt.Source = static_cast< XPropertySetInfoChangeNotifier * >( this ); - m_pPropSetChangeListeners->disposeAndClear( l, aEvt ); + m_aPropSetChangeListeners.disposeAndClear( l, aEvt ); } if ( m_pPropertyChangeListeners ) @@ -1084,11 +1082,7 @@ void SAL_CALL PersistentPropertySet::addEventListener( { std::unique_lock l(m_aMutex); - if ( !m_pDisposeEventListeners ) - m_pDisposeEventListeners.reset( - new OInterfaceContainerHelper4<css::lang::XEventListener>() ); - - m_pDisposeEventListeners->addInterface( l, Listener ); + m_aDisposeEventListeners.addInterface( l, Listener ); } @@ -1097,8 +1091,7 @@ void SAL_CALL PersistentPropertySet::removeEventListener( const Reference< XEventListener >& Listener ) { std::unique_lock l(m_aMutex); - if ( m_pDisposeEventListeners ) - m_pDisposeEventListeners->removeInterface( l, Listener ); + m_aDisposeEventListeners.removeInterface( l, Listener ); // Note: Don't want to delete empty container here -> performance. } @@ -1431,8 +1424,7 @@ void SAL_CALL PersistentPropertySet::addProperty( m_pInfo->reset(); // Notify propertyset info change listeners. - if ( m_pPropSetChangeListeners && - m_pPropSetChangeListeners->getLength(aGuard) ) + if ( m_aPropSetChangeListeners.getLength(aGuard) ) { PropertySetInfoChangeEvent evt( static_cast< OWeakObject * >( this ), @@ -1556,8 +1548,7 @@ void SAL_CALL PersistentPropertySet::removeProperty( const OUString& Name ) { sal_Int32 nHandle = -1; - if ( m_pPropSetChangeListeners && - m_pPropSetChangeListeners->getLength(aGuard) ) + if ( m_aPropSetChangeListeners.getLength(aGuard) ) { // Obtain property handle ( needed for propertysetinfo // change event )... @@ -1589,8 +1580,7 @@ void SAL_CALL PersistentPropertySet::removeProperty( const OUString& Name ) m_pInfo->reset(); // Notify propertyset info change listeners. - if ( m_pPropSetChangeListeners && - m_pPropSetChangeListeners->getLength(aGuard) ) + if ( m_aPropSetChangeListeners.getLength(aGuard) ) { PropertySetInfoChangeEvent evt( static_cast< OWeakObject * >( this ), @@ -1635,11 +1625,7 @@ void SAL_CALL PersistentPropertySet::addPropertySetInfoChangeListener( { std::unique_lock aGuard(m_aMutex); - if ( !m_pPropSetChangeListeners ) - m_pPropSetChangeListeners.reset( - new OInterfaceContainerHelper4<XPropertySetInfoChangeListener>() ); - - m_pPropSetChangeListeners->addInterface( aGuard, Listener ); + m_aPropSetChangeListeners.addInterface( aGuard, Listener ); } @@ -1648,8 +1634,7 @@ void SAL_CALL PersistentPropertySet::removePropertySetInfoChangeListener( const Reference< XPropertySetInfoChangeListener >& Listener ) { std::unique_lock aGuard(m_aMutex); - if ( m_pPropSetChangeListeners ) - m_pPropSetChangeListeners->removeInterface( aGuard, Listener ); + m_aPropSetChangeListeners.removeInterface( aGuard, Listener ); } @@ -1923,11 +1908,8 @@ void PersistentPropertySet::notifyPropertySetInfoChange( std::unique_lock<std::mutex>& rGuard, const PropertySetInfoChangeEvent& evt ) const { - if ( !m_pPropSetChangeListeners ) - return; - // Notify event listeners. - m_pPropSetChangeListeners->notifyEach( rGuard, &XPropertySetInfoChangeListener::propertySetInfoChange, evt ); + m_aPropSetChangeListeners.notifyEach( rGuard, &XPropertySetInfoChangeListener::propertySetInfoChange, evt ); } diff --git a/ucb/source/core/ucbstore.hxx b/ucb/source/core/ucbstore.hxx index 5f431fa8ac0d..31de991246ef 100644 --- a/ucb/source/core/ucbstore.hxx +++ b/ucb/source/core/ucbstore.hxx @@ -163,8 +163,8 @@ class PersistentPropertySet : public cppu::WeakImplHelper < OUString m_aKey; OUString m_aFullKey; mutable std::mutex m_aMutex; - std::unique_ptr<comphelper::OInterfaceContainerHelper4<css::lang::XEventListener>> m_pDisposeEventListeners; - std::unique_ptr<comphelper::OInterfaceContainerHelper4<css::beans::XPropertySetInfoChangeListener>> m_pPropSetChangeListeners; + comphelper::OInterfaceContainerHelper4<css::lang::XEventListener> m_aDisposeEventListeners; + comphelper::OInterfaceContainerHelper4<css::beans::XPropertySetInfoChangeListener> m_aPropSetChangeListeners; std::unique_ptr<PropertyListeners_Impl> m_pPropertyChangeListeners; private: