Kaydet (Commit) 752cd07d authored tarafından Noel Grandin's avatar Noel Grandin Kaydeden (comit) Noel Grandin

InterfaceContainer2 with vector instead of Sequence

create an InterfaceContainer2 class to replace InterfaceContainer.
It uses a std::vector instead of a Sequence for the mutable listener
list, which provides far better performance.

Switch all our internal use-sites to the new class.

Change-Id: I6b56cfa511ded2395faa22e68fab3b2f16c3cb88
üst 0e7cd653
......@@ -26,6 +26,7 @@ $(eval $(call gb_Library_set_componentfile,animcore,animations/source/animcore/a
$(eval $(call gb_Library_use_sdk_api,animcore))
$(eval $(call gb_Library_use_libraries,animcore,\
comphelper \
cppu \
cppuhelper \
sal \
......
......@@ -47,7 +47,7 @@
#include <com/sun/star/lang/XUnoTunnel.hpp>
#include <comphelper/servicehelper.hxx>
#include <cppuhelper/queryinterface.hxx>
#include <cppuhelper/interfacecontainer.hxx>
#include <comphelper/interfacecontainer2.hxx>
#include <cppuhelper/supportsservice.hxx>
#include <cppuhelper/weakref.hxx>
......@@ -60,8 +60,8 @@
using ::osl::Mutex;
using ::osl::Guard;
using ::cppu::OInterfaceContainerHelper;
using ::cppu::OInterfaceIteratorHelper;
using ::comphelper::OInterfaceContainerHelper2;
using ::comphelper::OInterfaceIteratorHelper2;
using ::com::sun::star::uno::Any;
using ::com::sun::star::uno::UNO_QUERY;
using ::com::sun::star::uno::XInterface;
......@@ -287,7 +287,7 @@ public:
void fireChangeListener();
private:
OInterfaceContainerHelper maChangeListener;
OInterfaceContainerHelper2 maChangeListener;
static void initTypeProvider( sal_Int16 nNodeType ) throw();
......@@ -2129,7 +2129,7 @@ void AnimationNode::fireChangeListener()
{
Guard< Mutex > aGuard( maMutex );
OInterfaceIteratorHelper aIterator( maChangeListener );
OInterfaceIteratorHelper2 aIterator( maChangeListener );
if( aIterator.hasMoreElements() )
{
Reference< XInterface > xSource( static_cast<OWeakObject*>(this), UNO_QUERY );
......
......@@ -532,7 +532,7 @@ void SAL_CALL Window::removeEventListener( const uno::Reference< lang::XEventLis
void Window::fireMousePressedEvent( const css::awt::MouseEvent& rEvt )
{
::cppu::OInterfaceContainerHelper* pContainer = maListeners.getContainer( cppu::UnoType<awt::XMouseListener>::get());
::comphelper::OInterfaceContainerHelper2* pContainer = maListeners.getContainer( cppu::UnoType<awt::XMouseListener>::get());
if( pContainer )
{
......@@ -545,7 +545,7 @@ void Window::fireMousePressedEvent( const css::awt::MouseEvent& rEvt )
void Window::fireMouseReleasedEvent( const css::awt::MouseEvent& rEvt )
{
::cppu::OInterfaceContainerHelper* pContainer = maListeners.getContainer( cppu::UnoType<awt::XMouseListener>::get());
::comphelper::OInterfaceContainerHelper2* pContainer = maListeners.getContainer( cppu::UnoType<awt::XMouseListener>::get());
if( pContainer )
{
......@@ -558,7 +558,7 @@ void Window::fireMouseReleasedEvent( const css::awt::MouseEvent& rEvt )
void Window::fireMouseMovedEvent( const css::awt::MouseEvent& rEvt )
{
::cppu::OInterfaceContainerHelper* pContainer = maListeners.getContainer( cppu::UnoType<awt::XMouseMotionListener>::get());
::comphelper::OInterfaceContainerHelper2* pContainer = maListeners.getContainer( cppu::UnoType<awt::XMouseMotionListener>::get());
if( pContainer )
{
......@@ -571,7 +571,7 @@ void Window::fireMouseMovedEvent( const css::awt::MouseEvent& rEvt )
void Window::fireSetFocusEvent( const css::awt::FocusEvent& rEvt )
{
::cppu::OInterfaceContainerHelper* pContainer = maListeners.getContainer( cppu::UnoType<awt::XFocusListener>::get());
::comphelper::OInterfaceContainerHelper2* pContainer = maListeners.getContainer( cppu::UnoType<awt::XFocusListener>::get());
if( pContainer )
{
......
......@@ -25,7 +25,7 @@
#include <cppuhelper/implbase.hxx>
#include <cppuhelper/exc_hlp.hxx>
#include <cppuhelper/typeprovider.hxx>
#include <cppuhelper/interfacecontainer.hxx>
#include <comphelper/interfacecontainer2.hxx>
#include <comphelper/extract.hxx>
#include <comphelper/processfactory.hxx>
......@@ -4297,7 +4297,7 @@ class ModuleInvocationProxy : public WeakImplHelper< XInvocation, XComponent >
SbxObjectRef m_xScopeObj;
bool m_bProxyIsClassModuleObject;
::cppu::OInterfaceContainerHelper m_aListeners;
::comphelper::OInterfaceContainerHelper2 m_aListeners;
public:
ModuleInvocationProxy( const OUString& aPrefix, SbxObjectRef xScopeObj );
......
......@@ -79,8 +79,8 @@ class NameContainer : public ::cppu::BaseMutex, public NameContainer_BASE
css::uno::Type mType;
css::uno::XInterface* mpxEventSource;
::cppu::OInterfaceContainerHelper maContainerListeners;
::cppu::OInterfaceContainerHelper maChangesListeners;
::comphelper::OInterfaceContainerHelper2 maContainerListeners;
::comphelper::OInterfaceContainerHelper2 maChangesListeners;
public:
NameContainer( const css::uno::Type& rType )
......@@ -157,7 +157,7 @@ public:
class ModifiableHelper
{
private:
::cppu::OInterfaceContainerHelper m_aModifyListeners;
::comphelper::OInterfaceContainerHelper2 m_aModifyListeners;
::cppu::OWeakObject& m_rEventSource;
bool mbModified;
......
......@@ -60,7 +60,7 @@
#include <osl/mutex.hxx>
#include <rtl/ref.hxx>
#include <cppuhelper/implbase.hxx>
#include <cppuhelper/interfacecontainer.hxx>
#include <comphelper/interfacecontainer2.hxx>
#include <svtools/grfmgr.hxx>
#include <memory>
......@@ -130,7 +130,7 @@ private:
::com::sun::star::uno::Reference< ::com::sun::star::document::XDocumentProperties > m_xDocumentProperties;
::rtl::Reference< UndoManager > m_pUndoManager;
::cppu::OInterfaceContainerHelper m_aControllers;
::comphelper::OInterfaceContainerHelper2 m_aControllers;
::com::sun::star::uno::Reference< ::com::sun::star::frame::XController > m_xCurrentController;
sal_uInt16 m_nControllerLockCount;
......
......@@ -22,7 +22,7 @@
#include "WrappedPropertySet.hxx"
#include <cppuhelper/implbase.hxx>
#include <comphelper/uno3.hxx>
#include <cppuhelper/interfacecontainer.hxx>
#include <comphelper/interfacecontainer2.hxx>
#include <com/sun/star/drawing/XShape.hpp>
#include <com/sun/star/lang/XComponent.hpp>
#include <com/sun/star/lang/XServiceInfo.hpp>
......@@ -94,7 +94,7 @@ protected:
private:
std::shared_ptr< Chart2ModelContact > m_spChart2ModelContact;
::cppu::OInterfaceContainerHelper m_aEventListenerContainer;
::comphelper::OInterfaceContainerHelper2 m_aEventListenerContainer;
};
} // namespace wrapper
......
......@@ -23,7 +23,7 @@
#include "ReferenceSizePropertyProvider.hxx"
#include <cppuhelper/implbase.hxx>
#include <comphelper/uno3.hxx>
#include <cppuhelper/interfacecontainer.hxx>
#include <comphelper/interfacecontainer2.hxx>
#include <com/sun/star/chart/XAxis.hpp>
#include <com/sun/star/chart2/XAxis.hpp>
#include <com/sun/star/frame/XModel.hpp>
......@@ -131,7 +131,7 @@ private: //methods
private: //member
std::shared_ptr< Chart2ModelContact > m_spChart2ModelContact;
::cppu::OInterfaceContainerHelper m_aEventListenerContainer;
::comphelper::OInterfaceContainerHelper2 m_aEventListenerContainer;
tAxisType m_eType;
......
......@@ -607,16 +607,7 @@ void ChartDataWrapper::fireChartDataChangeEvent(
if( xSrc.is() )
aEvent.Source = xSrc;
::cppu::OInterfaceIteratorHelper aIter( m_aEventListenerContainer );
while( aIter.hasMoreElements() )
{
uno::Reference<
::com::sun::star::chart::XChartDataChangeEventListener > xListener(
aIter.next(), uno::UNO_QUERY );
if( xListener.is() )
xListener->chartDataChanged( aEvent );
}
m_aEventListenerContainer.notifyEach( &css::chart::XChartDataChangeEventListener::chartDataChanged, aEvent );
}
void ChartDataWrapper::switchToInternalDataProvider()
......
......@@ -21,7 +21,7 @@
#include "MutexContainer.hxx"
#include <cppuhelper/implbase.hxx>
#include <cppuhelper/interfacecontainer.hxx>
#include <comphelper/interfacecontainer2.hxx>
#include <com/sun/star/chart2/XAnyDescriptionAccess.hpp>
#include <com/sun/star/chart/XDateCategories.hpp>
#include <com/sun/star/lang/XComponent.hpp>
......@@ -157,7 +157,7 @@ private: //member
::com::sun::star::chart2::XAnyDescriptionAccess > m_xDataAccess;
std::shared_ptr< Chart2ModelContact > m_spChart2ModelContact;
::cppu::OInterfaceContainerHelper m_aEventListenerContainer;
::comphelper::OInterfaceContainerHelper2 m_aEventListenerContainer;
};
} // namespace wrapper
......
......@@ -23,7 +23,7 @@
#include "ReferenceSizePropertyProvider.hxx"
#include <cppuhelper/implbase.hxx>
#include <comphelper/uno3.hxx>
#include <cppuhelper/interfacecontainer.hxx>
#include <comphelper/interfacecontainer2.hxx>
#include <com/sun/star/chart2/XDataSeries.hpp>
#include <com/sun/star/frame/XModel.hpp>
#include <com/sun/star/lang/XComponent.hpp>
......@@ -126,7 +126,7 @@ protected:
private:
std::shared_ptr< Chart2ModelContact > m_spChart2ModelContact;
::cppu::OInterfaceContainerHelper m_aEventListenerContainer;
::comphelper::OInterfaceContainerHelper2 m_aEventListenerContainer;
eType m_eType;
sal_Int32 m_nSeriesIndexInNewAPI;
......
......@@ -241,7 +241,7 @@ protected:
private:
std::shared_ptr< Chart2ModelContact > m_spChart2ModelContact;
::cppu::OInterfaceContainerHelper m_aEventListenerContainer;
::comphelper::OInterfaceContainerHelper2 m_aEventListenerContainer;
::com::sun::star::uno::Reference<
::com::sun::star::chart::XAxis > m_xXAxis;
......
......@@ -22,7 +22,7 @@
#include "WrappedPropertySet.hxx"
#include <cppuhelper/implbase.hxx>
#include <comphelper/uno3.hxx>
#include <cppuhelper/interfacecontainer.hxx>
#include <comphelper/interfacecontainer2.hxx>
#include <com/sun/star/drawing/XShape.hpp>
#include <com/sun/star/lang/XComponent.hpp>
#include <com/sun/star/lang/XServiceInfo.hpp>
......@@ -89,7 +89,7 @@ protected:
private:
std::shared_ptr< Chart2ModelContact > m_spChart2ModelContact;
::cppu::OInterfaceContainerHelper m_aEventListenerContainer;
::comphelper::OInterfaceContainerHelper2 m_aEventListenerContainer;
tGridType m_eType;
};
......
......@@ -23,7 +23,7 @@
#include "ReferenceSizePropertyProvider.hxx"
#include <cppuhelper/implbase.hxx>
#include <comphelper/uno3.hxx>
#include <cppuhelper/interfacecontainer.hxx>
#include <comphelper/interfacecontainer2.hxx>
#include <com/sun/star/drawing/XShape.hpp>
#include <com/sun/star/lang/XComponent.hpp>
#include <com/sun/star/lang/XServiceInfo.hpp>
......@@ -102,7 +102,7 @@ protected:
private:
std::shared_ptr< Chart2ModelContact > m_spChart2ModelContact;
::cppu::OInterfaceContainerHelper m_aEventListenerContainer;
::comphelper::OInterfaceContainerHelper2 m_aEventListenerContainer;
};
} // namespace wrapper
......
......@@ -21,7 +21,7 @@
#include "MutexContainer.hxx"
#include "WrappedIgnoreProperty.hxx"
#include <cppuhelper/interfacecontainer.hxx>
#include <comphelper/interfacecontainer2.hxx>
#include <com/sun/star/chart2/XDiagram.hpp>
......@@ -115,7 +115,7 @@ private: //methods
private: //member
std::shared_ptr< Chart2ModelContact > m_spChart2ModelContact;
::cppu::OInterfaceContainerHelper m_aEventListenerContainer;
::comphelper::OInterfaceContainerHelper2 m_aEventListenerContainer;
WrappedIgnoreProperty m_aWrappedLineJointProperty;
};
......
......@@ -123,7 +123,7 @@ private:
private:
std::shared_ptr< Chart2ModelContact > m_spChart2ModelContact;
::cppu::OInterfaceContainerHelper m_aEventListenerContainer;
::comphelper::OInterfaceContainerHelper2 m_aEventListenerContainer;
::chart::TitleHelper::eTitleType m_eTitleType;
};
......
......@@ -20,7 +20,7 @@
#define INCLUDED_CHART2_SOURCE_CONTROLLER_CHARTAPIWRAPPER_UPDOWNBARWRAPPER_HXX
#include "MutexContainer.hxx"
#include <cppuhelper/interfacecontainer.hxx>
#include <comphelper/interfacecontainer2.hxx>
#include <com/sun/star/chart2/XDiagram.hpp>
......@@ -114,7 +114,7 @@ private: //methods
private: //member
std::shared_ptr< Chart2ModelContact > m_spChart2ModelContact;
::cppu::OInterfaceContainerHelper m_aEventListenerContainer;
::comphelper::OInterfaceContainerHelper2 m_aEventListenerContainer;
OUString m_aPropertySetName;
};
......
......@@ -22,7 +22,7 @@
#include "WrappedPropertySet.hxx"
#include <cppuhelper/implbase.hxx>
#include <comphelper/uno3.hxx>
#include <cppuhelper/interfacecontainer.hxx>
#include <comphelper/interfacecontainer2.hxx>
#include <com/sun/star/lang/XComponent.hpp>
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/uno/XComponentContext.hpp>
......@@ -76,7 +76,7 @@ protected:
private:
std::shared_ptr< Chart2ModelContact > m_spChart2ModelContact;
::cppu::OInterfaceContainerHelper m_aEventListenerContainer;
::comphelper::OInterfaceContainerHelper2 m_aEventListenerContainer;
bool m_bWall;
};
......
......@@ -86,7 +86,7 @@ void SAL_CALL CommandDispatch::addStatusListener( const Reference< frame::XStatu
{
aIt = m_aListeners.insert(
m_aListeners.begin(),
tListenerMap::value_type( URL.Complete, new ::cppu::OInterfaceContainerHelper( m_aMutex )));
tListenerMap::value_type( URL.Complete, new ::comphelper::OInterfaceContainerHelper2( m_aMutex )));
}
OSL_ASSERT( aIt != m_aListeners.end());
......@@ -155,7 +155,7 @@ void CommandDispatch::fireStatusEventForURL(
{
if( aIt->second )
{
::cppu::OInterfaceIteratorHelper aIntfIt( *((*aIt).second) );
::comphelper::OInterfaceIteratorHelper2 aIntfIt( *((*aIt).second) );
while( aIntfIt.hasMoreElements())
{
......
......@@ -21,6 +21,7 @@
#include "MutexContainer.hxx"
#include <cppuhelper/compbase.hxx>
#include <comphelper/interfacecontainer2.hxx>
#include <com/sun/star/frame/XDispatch.hpp>
#include <com/sun/star/util/XModifyListener.hpp>
#include <com/sun/star/uno/XComponentContext.hpp>
......@@ -130,7 +131,7 @@ protected:
::com::sun::star::uno::Reference< ::com::sun::star::util::XURLTransformer > m_xURLTransformer;
private:
typedef ::std::map< OUString, ::cppu::OInterfaceContainerHelper* >
typedef ::std::map< OUString, ::comphelper::OInterfaceContainerHelper2* >
tListenerMap;
tListenerMap m_aListeners;
......
......@@ -227,10 +227,10 @@ bool ChartModel::impl_isControllerConnected( const uno::Reference< frame::XContr
{
try
{
uno::Sequence< uno::Reference<uno::XInterface> > aSeq = m_aControllers.getElements();
for( sal_Int32 nN = aSeq.getLength(); nN--; )
std::vector< uno::Reference<uno::XInterface> > aSeq = m_aControllers.getElements();
for( const auto & r : aSeq )
{
if( aSeq[nN] == xController )
if( r == xController )
return true;
}
}
......
# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
#
#
# This file is part of the LibreOffice project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
$(eval $(call gb_CppunitTest_CppunitTest,comphelper_ifcontainer))
$(eval $(call gb_CppunitTest_add_exception_objects,comphelper_ifcontainer,\
comphelper/qa/container/comphelper_ifcontainer \
))
$(eval $(call gb_CppunitTest_use_api,comphelper_ifcontainer,\
udkapi \
))
$(eval $(call gb_CppunitTest_use_libraries,comphelper_ifcontainer,\
comphelper \
cppu \
cppuhelper \
sal \
$(gb_UWINAPI) \
))
# vim: set noet sw=4 ts=4:
......@@ -11,6 +11,7 @@ $(eval $(call gb_CppunitTest_CppunitTest,comphelper_test))
$(eval $(call gb_CppunitTest_add_exception_objects,comphelper_test, \
comphelper/qa/string/test_string \
comphelper/qa/container/testifcontainer \
))
$(eval $(call gb_CppunitTest_use_api,comphelper_test, \
......
......@@ -60,6 +60,7 @@ $(eval $(call gb_Library_add_exception_objects,comphelper,\
comphelper/source/container/NamedPropertyValuesContainer \
comphelper/source/container/container \
comphelper/source/container/containermultiplexer \
comphelper/source/container/interfacecontainer2 \
comphelper/source/container/embeddedobjectcontainer \
comphelper/source/container/enumerablemap \
comphelper/source/container/enumhelper \
......
......@@ -30,6 +30,7 @@ $(eval $(call gb_Module_add_subsequentcheck_targets,comphelper,\
$(eval $(call gb_Module_add_check_targets,comphelper,\
CppunitTest_comphelper_syntaxhighlight_test \
CppunitTest_comphelper_variadictemplates_test \
CppunitTest_comphelper_ifcontainer \
CppunitTest_comphelper_test \
))
......
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <sal/types.h>
#include <string.h>
#include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/plugin/TestPlugIn.h>
#include <com/sun/star/lang/XEventListener.hpp>
#include <comphelper/interfacecontainer2.hxx>
#include <cppuhelper/queryinterface.hxx>
#include <cppuhelper/implbase1.hxx>
#include <cppuhelper/propshlp.hxx>
using namespace com::sun::star;
using namespace com::sun::star::uno;
using namespace com::sun::star::lang;
class ContainerListener;
struct ContainerStats {
int m_nAlive;
int m_nDisposed;
ContainerStats() : m_nAlive(0), m_nDisposed(0) {}
};
class ContainerListener : public ::cppu::WeakImplHelper1< XEventListener >
{
ContainerStats *m_pStats;
public:
explicit ContainerListener(ContainerStats *pStats)
: m_pStats(pStats) { m_pStats->m_nAlive++; }
virtual ~ContainerListener() { m_pStats->m_nAlive--; }
virtual void SAL_CALL disposing( const EventObject& )
throw (RuntimeException, std::exception) override
{
m_pStats->m_nDisposed++;
}
};
namespace comphelper_ifcontainer
{
static const int nTests = 10;
class IfTest : public CppUnit::TestFixture
{
osl::Mutex m_aGuard;
public:
void testCreateDispose()
{
ContainerStats aStats;
comphelper::OInterfaceContainerHelper2 *pContainer;
pContainer = new comphelper::OInterfaceContainerHelper2(m_aGuard);
CPPUNIT_ASSERT_MESSAGE("Empty container not empty",
pContainer->getLength() == 0);
int i;
for (i = 0; i < nTests; i++)
{
Reference<XEventListener> xRef = new ContainerListener(&aStats);
int nNewLen = pContainer->addInterface(xRef);
CPPUNIT_ASSERT_MESSAGE("addition length mismatch",
nNewLen == i + 1);
CPPUNIT_ASSERT_MESSAGE("addition length mismatch",
pContainer->getLength() == i + 1);
}
CPPUNIT_ASSERT_MESSAGE("alive count mismatch",
aStats.m_nAlive == nTests);
EventObject aObj;
pContainer->disposeAndClear(aObj);
CPPUNIT_ASSERT_MESSAGE("dispose count mismatch",
aStats.m_nDisposed == nTests);
CPPUNIT_ASSERT_MESSAGE("leaked container left alive",
aStats.m_nAlive == 0);
delete pContainer;
}
void testEnumerate()
{
int i;
ContainerStats aStats;
comphelper::OInterfaceContainerHelper2 *pContainer;
pContainer = new comphelper::OInterfaceContainerHelper2(m_aGuard);
std::vector< Reference< XEventListener > > aListeners;
for (i = 0; i < nTests; i++)
{
Reference<XEventListener> xRef = new ContainerListener(&aStats);
pContainer->addInterface(xRef);
aListeners.push_back(xRef);
}
std::vector< Reference< XInterface > > aElements = pContainer->getElements();
CPPUNIT_ASSERT_EQUAL_MESSAGE("query contents",
(int)aElements.size(), nTests);
if ((int)aElements.size() == nTests)
{
for (i = 0; i < nTests; i++)
{
CPPUNIT_ASSERT_MESSAGE("mismatching elements",
aElements[i] == aListeners[i]);
}
}
pContainer->clear();
CPPUNIT_ASSERT_MESSAGE("non-empty container post clear",
pContainer->getLength() == 0);
delete pContainer;
}
template < typename ContainerType, typename ContainedType >
void doContainerTest(const ContainedType *pTypes)
{
ContainerStats aStats;
ContainerType *pContainer;
pContainer = new ContainerType(m_aGuard);
int i;
Reference<XEventListener> xRefs[nTests * 2];
// add these interfaces