[Libreoffice-commits] core.git: sw/source
Julien Nabet
serval2412 at yahoo.fr
Sun Sep 17 10:08:41 UTC 2017
sw/source/uibase/inc/unodispatch.hxx | 5 +--
sw/source/uibase/uno/unodispatch.cxx | 45 ++++++++++++-----------------------
2 files changed, 18 insertions(+), 32 deletions(-)
New commits:
commit d727476cff29382a34103b137542e15e1aeeb4b9
Author: Julien Nabet <serval2412 at yahoo.fr>
Date: Sun Sep 17 10:59:38 2017 +0200
Replace list by vector unodispatch (sw)
There was insert use equivalent to a push front (since we inserted at the beginning)
but anyway, there wasn't any front or remove which may have justified to keep list
+ modernize loop
Change-Id: Ic67db40ae2c71dd0eb526e6c5ca55f1ef6d202c9
Reviewed-on: https://gerrit.libreoffice.org/42368
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
diff --git a/sw/source/uibase/inc/unodispatch.hxx b/sw/source/uibase/inc/unodispatch.hxx
index 320bbf775d61..448b8e379dd9 100644
--- a/sw/source/uibase/inc/unodispatch.hxx
+++ b/sw/source/uibase/inc/unodispatch.hxx
@@ -26,7 +26,7 @@
#include <com/sun/star/frame/XDispatch.hpp>
#include <com/sun/star/frame/XInterceptorInfo.hpp>
#include <cppuhelper/implbase.hxx>
-#include <list>
+#include <vector>
#include <vcl/svapp.hxx>
#include <osl/mutex.hxx>
@@ -96,7 +96,6 @@ struct StatusStruct_Impl
css::uno::Reference< css::frame::XStatusListener> xListener;
css::util::URL aURL;
};
-typedef std::list< StatusStruct_Impl > StatusListenerList;
class SwXDispatch : public cppu::WeakImplHelper
<
css::frame::XDispatch,
@@ -104,7 +103,7 @@ class SwXDispatch : public cppu::WeakImplHelper
>
{
SwView* m_pView;
- StatusListenerList m_aListenerList;
+ std::vector< StatusStruct_Impl > m_aStatusListenerVector;
bool m_bOldEnable;
bool m_bListenerAdded;
public:
diff --git a/sw/source/uibase/uno/unodispatch.cxx b/sw/source/uibase/uno/unodispatch.cxx
index fd20b70d4961..128f5d9e8f24 100644
--- a/sw/source/uibase/uno/unodispatch.cxx
+++ b/sw/source/uibase/uno/unodispatch.cxx
@@ -257,14 +257,12 @@ void SwXDispatch::dispatch(const util::URL& aURL,
aEvent.State <<= aDescriptor.createPropertyValueSequence();
aEvent.IsEnabled = !rData.sDataSource.isEmpty();
- StatusListenerList::iterator aListIter = m_aListenerList.begin();
- for(aListIter = m_aListenerList.begin(); aListIter != m_aListenerList.end(); ++aListIter)
+ for ( auto & status : m_aStatusListenerVector )
{
- StatusStruct_Impl aStatus = *aListIter;
- if(aStatus.aURL.Complete == cURLDocumentDataSource)
+ if(status.aURL.Complete == cURLDocumentDataSource)
{
- aEvent.FeatureURL = aStatus.aURL;
- aStatus.xListener->statusChanged( aEvent );
+ aEvent.FeatureURL = status.aURL;
+ status.xListener->statusChanged( aEvent );
}
}
}
@@ -306,11 +304,10 @@ void SwXDispatch::addStatusListener(
xControl->statusChanged( aEvent );
- StatusListenerList::iterator aListIter = m_aListenerList.begin();
StatusStruct_Impl aStatus;
aStatus.xListener = xControl;
aStatus.aURL = aURL;
- m_aListenerList.insert(aListIter, aStatus);
+ m_aStatusListenerVector.emplace_back(aStatus);
if(!m_bListenerAdded)
{
@@ -324,17 +321,11 @@ void SwXDispatch::addStatusListener(
void SwXDispatch::removeStatusListener(
const uno::Reference< frame::XStatusListener >& xControl, const util::URL& )
{
- StatusListenerList::iterator aListIter = m_aListenerList.begin();
- for(aListIter = m_aListenerList.begin(); aListIter != m_aListenerList.end(); ++aListIter)
- {
- StatusStruct_Impl aStatus = *aListIter;
- if(aStatus.xListener.get() == xControl.get())
- {
- m_aListenerList.erase(aListIter);
- break;
- }
- }
- if(m_aListenerList.empty() && m_pView)
+ m_aStatusListenerVector.erase(
+ std::remove_if(m_aStatusListenerVector.begin(), m_aStatusListenerVector.end(),
+ [&](const StatusStruct_Impl& status) { return status.xListener.get() == xControl.get(); }),
+ m_aStatusListenerVector.end());
+ if(m_aStatusListenerVector.empty() && m_pView)
{
uno::Reference<view::XSelectionSupplier> xSupplier = m_pView->GetUNOObject();
uno::Reference<view::XSelectionChangeListener> xThis = this;
@@ -357,14 +348,12 @@ void SwXDispatch::selectionChanged( const lang::EventObject& )
aEvent.IsEnabled = bEnable;
aEvent.Source = *static_cast<cppu::OWeakObject*>(this);
- StatusListenerList::iterator aListIter = m_aListenerList.begin();
- for(aListIter = m_aListenerList.begin(); aListIter != m_aListenerList.end(); ++aListIter)
+ for ( auto & status : m_aStatusListenerVector )
{
- StatusStruct_Impl aStatus = *aListIter;
- aEvent.FeatureURL = aStatus.aURL;
- if (aStatus.aURL.Complete != cURLDocumentDataSource)
+ aEvent.FeatureURL = status.aURL;
+ if (status.aURL.Complete != cURLDocumentDataSource)
// the document's data source does not depend on the selection, so it's state does not change here
- aStatus.xListener->statusChanged( aEvent );
+ status.xListener->statusChanged( aEvent );
}
}
}
@@ -378,11 +367,9 @@ void SwXDispatch::disposing( const lang::EventObject& rSource )
lang::EventObject aObject;
aObject.Source = static_cast<cppu::OWeakObject*>(this);
- StatusListenerList::iterator aListIter = m_aListenerList.begin();
- for(; aListIter != m_aListenerList.end(); ++aListIter)
+ for ( auto & status : m_aStatusListenerVector )
{
- StatusStruct_Impl aStatus = *aListIter;
- aStatus.xListener->disposing(aObject);
+ status.xListener->disposing(aObject);
}
m_pView = nullptr;
}
More information about the Libreoffice-commits
mailing list