return and use std::vector from OInterfaceContainerHelper

since most of the time we don’t need a heavyweight uno::Sequence.
Adds a new method getElementsAsVector().

Change-Id: I9e72bef0c0c723ffd0dd7d4152db5baec6784a7a
Reviewed-on: https://gerrit.libreoffice.org/15747
Reviewed-by: Noel Grandin <noelgrandin@gmail.com>
Tested-by: Noel Grandin <noelgrandin@gmail.com>
This commit is contained in:
Noel Grandin
2015-05-16 11:12:48 +02:00
parent 371200675c
commit e57314f61f
18 changed files with 148 additions and 202 deletions

View File

@@ -227,10 +227,9 @@ bool ChartModel::impl_isControllerConnected( const uno::Reference< frame::XContr
{ {
try try
{ {
uno::Sequence< uno::Reference<uno::XInterface> > aSeq = m_aControllers.getElements(); for( uno::Reference<uno::XInterface> & rInterface : m_aControllers.getElements() )
for( sal_Int32 nN = aSeq.getLength(); nN--; )
{ {
if( aSeq[nN] == xController ) if( rInterface == xController )
return true; return true;
} }
} }

View File

@@ -255,7 +255,7 @@ namespace comphelper
void AccessibleEventNotifier::addEvent( const TClientId _nClient, const AccessibleEventObject& _rEvent ) void AccessibleEventNotifier::addEvent( const TClientId _nClient, const AccessibleEventObject& _rEvent )
{ {
Sequence< Reference< XInterface > > aListeners; std::vector< Reference< XInterface > > aListeners;
// --- <mutex lock> ------------------------------- // --- <mutex lock> -------------------------------
{ {
@@ -267,25 +267,22 @@ namespace comphelper
return; return;
// since we're synchronous, again, we want to notify immediately // since we're synchronous, again, we want to notify immediately
aListeners = aClientPos->second->getElements(); aListeners = aClientPos->second->getElementsAsVector();
} }
// --- </mutex lock> ------------------------------ // --- </mutex lock> ------------------------------
// default handling: loop through all listeners, and notify them // default handling: loop through all listeners, and notify them
const Reference< XInterface >* pListeners = aListeners.getConstArray(); for ( const Reference< XInterface > & rL : aListeners )
const Reference< XInterface >* pListenersEnd = pListeners + aListeners.getLength();
while ( pListeners != pListenersEnd )
{ {
try try
{ {
static_cast< XAccessibleEventListener* >( pListeners->get() )->notifyEvent( _rEvent ); static_cast< XAccessibleEventListener* >( rL.get() )->notifyEvent( _rEvent );
} }
catch( const Exception& ) catch( const Exception& )
{ {
// no assertion, because a broken access remote bridge or something like this // no assertion, because a broken access remote bridge or something like this
// can cause this exception // can cause this exception
} }
++pListeners;
} }
} }

View File

@@ -112,12 +112,11 @@ namespace cppu_ifcontainer
pContainer->addInterface(xRef); pContainer->addInterface(xRef);
aListeners.push_back(xRef); aListeners.push_back(xRef);
} }
Sequence< Reference< XInterface > > aElements; std::vector< Reference< XInterface > > aElements = pContainer->getElementsAsVector();
aElements = pContainer->getElements();
CPPUNIT_ASSERT_MESSAGE("query contents", CPPUNIT_ASSERT_MESSAGE("query contents",
(int)aElements.getLength() == nTests); (int)aElements.size() == nTests);
if ((int)aElements.getLength() == nTests) if ((int)aElements.size() == nTests)
{ {
for (i = 0; i < nTests; i++) for (i = 0; i < nTests; i++)
{ {
@@ -157,8 +156,8 @@ namespace cppu_ifcontainer
pHelper = pContainer->getContainer(pTypes[i]); pHelper = pContainer->getContainer(pTypes[i]);
CPPUNIT_ASSERT_MESSAGE("no helper", pHelper != NULL); CPPUNIT_ASSERT_MESSAGE("no helper", pHelper != NULL);
Sequence<Reference< XInterface > > aSeq = pHelper->getElements(); std::vector<Reference< XInterface > > aSeq = pHelper->getElementsAsVector();
CPPUNIT_ASSERT_MESSAGE("wrong num elements", aSeq.getLength() == 2); CPPUNIT_ASSERT_MESSAGE("wrong num elements", aSeq.size() == 2);
CPPUNIT_ASSERT_MESSAGE("match", aSeq[0] == xRefs[i*2]); CPPUNIT_ASSERT_MESSAGE("match", aSeq[0] == xRefs[i*2]);
CPPUNIT_ASSERT_MESSAGE("match", aSeq[1] == xRefs[i*2+1]); CPPUNIT_ASSERT_MESSAGE("match", aSeq[1] == xRefs[i*2+1]);
} }
@@ -175,8 +174,8 @@ namespace cppu_ifcontainer
pHelper = pContainer->getContainer(pTypes[i]); pHelper = pContainer->getContainer(pTypes[i]);
CPPUNIT_ASSERT_MESSAGE("no helper", pHelper != NULL); CPPUNIT_ASSERT_MESSAGE("no helper", pHelper != NULL);
Sequence<Reference< XInterface > > aSeq = pHelper->getElements(); std::vector<Reference< XInterface > > aSeq = pHelper->getElementsAsVector();
CPPUNIT_ASSERT_MESSAGE("wrong num elements", aSeq.getLength() == 1); CPPUNIT_ASSERT_MESSAGE("wrong num elements", aSeq.size() == 1);
CPPUNIT_ASSERT_MESSAGE("match", aSeq[0] == xRefs[i*2]); CPPUNIT_ASSERT_MESSAGE("match", aSeq[0] == xRefs[i*2]);
} }
@@ -191,8 +190,8 @@ namespace cppu_ifcontainer
pHelper = pContainer->getContainer(pTypes[i]); pHelper = pContainer->getContainer(pTypes[i]);
CPPUNIT_ASSERT_MESSAGE("no helper", pHelper != NULL); CPPUNIT_ASSERT_MESSAGE("no helper", pHelper != NULL);
Sequence<Reference< XInterface > > aSeq = pHelper->getElements(); std::vector<Reference< XInterface > > aSeq = pHelper->getElementsAsVector();
CPPUNIT_ASSERT_MESSAGE("wrong num elements", aSeq.getLength() == 0); CPPUNIT_ASSERT_MESSAGE("wrong num elements", aSeq.size() == 0);
} }
delete pContainer; delete pContainer;

View File

@@ -430,6 +430,12 @@ global:
_ZN4cppu15supportsServiceEPN3com3sun4star4lang12XServiceInfoERKN3rtl8OUStringE; # cppu::supportsService(com::sun::star::lang::XServiceInfo*, rtl::OUString const&) _ZN4cppu15supportsServiceEPN3com3sun4star4lang12XServiceInfoERKN3rtl8OUStringE; # cppu::supportsService(com::sun::star::lang::XServiceInfo*, rtl::OUString const&)
} UDK_3.8; } UDK_3.8;
PRIVATE_cppuhelper.1 { # LibreOffice 5.1
global:
_ZNK4cppu25OInterfaceContainerHelper19getElementsAsVectorEv; # std::vector< Reference<XInterface> > OInterfaceContainerHelper::getElementsAsVector() const
};
# Unique libstdc++ symbols: # Unique libstdc++ symbols:
GLIBCXX_3.4 { GLIBCXX_3.4 {
global: global:

View File

@@ -28,6 +28,7 @@
#include <memory> #include <memory>
#include <com/sun/star/lang/XEventListener.hpp> #include <com/sun/star/lang/XEventListener.hpp>
#include <iterator>
using namespace osl; using namespace osl;
@@ -36,32 +37,6 @@ using namespace com::sun::star::lang;
namespace cppu namespace cppu
{ {
/**
* Reallocate the sequence.
*/
static void realloc( Sequence< Reference< XInterface > > & rSeq, sal_Int32 nNewLen )
{
rSeq.realloc( nNewLen );
}
/**
* Remove an element from an interface sequence.
*/
static void sequenceRemoveElementAt( Sequence< Reference< XInterface > > & rSeq, sal_Int32 index )
{
sal_Int32 nNewLen = rSeq.getLength() - 1;
Sequence< Reference< XInterface > > aDestSeq( rSeq.getLength() - 1 );
// getArray on a const sequence is faster
const Reference< XInterface > * pSource = ((const Sequence< Reference< XInterface > > &)rSeq).getConstArray();
Reference< XInterface > * pDest = aDestSeq.getArray();
sal_Int32 i = 0;
for( ; i < index; i++ )
pDest[i] = pSource[i];
for( sal_Int32 j = i ; j < nNewLen; j++ )
pDest[j] = pSource[j+1];
rSeq = aDestSeq;
}
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning( disable: 4786 ) #pragma warning( disable: 4786 )
@@ -79,7 +54,7 @@ OInterfaceIteratorHelper::OInterfaceIteratorHelper( OInterfaceContainerHelper &
if( bIsList ) if( bIsList )
{ {
rCont.bInUse = sal_True; rCont.bInUse = sal_True;
nRemain = aData.pAsSequence->getLength(); nRemain = aData.pAsVector->size();
} }
else if( aData.pAsInterface ) else if( aData.pAsInterface )
{ {
@@ -96,7 +71,7 @@ OInterfaceIteratorHelper::~OInterfaceIteratorHelper()
{ {
MutexGuard aGuard( rCont.rMutex ); MutexGuard aGuard( rCont.rMutex );
// bResetInUse protect the iterator against recursion // bResetInUse protect the iterator against recursion
bShared = aData.pAsSequence == rCont.aData.pAsSequence && rCont.bIsList; bShared = aData.pAsVector == rCont.aData.pAsVector && rCont.bIsList;
if( bShared ) if( bShared )
{ {
OSL_ENSURE( rCont.bInUse, "OInterfaceContainerHelper must be in use" ); OSL_ENSURE( rCont.bInUse, "OInterfaceContainerHelper must be in use" );
@@ -108,7 +83,7 @@ OInterfaceIteratorHelper::~OInterfaceIteratorHelper()
{ {
if( bIsList ) if( bIsList )
// Sequence owned by the iterator // Sequence owned by the iterator
delete aData.pAsSequence; delete aData.pAsVector;
else if( aData.pAsInterface ) else if( aData.pAsInterface )
// Interface is acquired by the iterator // Interface is acquired by the iterator
aData.pAsInterface->release(); aData.pAsInterface->release();
@@ -121,8 +96,7 @@ XInterface * OInterfaceIteratorHelper::next()
{ {
nRemain--; nRemain--;
if( bIsList ) if( bIsList )
// typecase to const,so the getArray method is faster return (*aData.pAsVector)[nRemain].get();
return aData.pAsSequence->getConstArray()[nRemain].get();
else if( aData.pAsInterface ) else if( aData.pAsInterface )
return aData.pAsInterface; return aData.pAsInterface;
} }
@@ -135,8 +109,8 @@ void OInterfaceIteratorHelper::remove()
if( bIsList ) if( bIsList )
{ {
OSL_ASSERT( nRemain >= 0 && OSL_ASSERT( nRemain >= 0 &&
nRemain < aData.pAsSequence->getLength() ); nRemain < static_cast<sal_Int32>(aData.pAsVector->size()) );
XInterface * p = aData.pAsSequence->getConstArray()[nRemain].get(); XInterface * p = (*aData.pAsVector)[nRemain].get();
rCont.removeInterface( * reinterpret_cast< const Reference< XInterface > * >( &p ) ); rCont.removeInterface( * reinterpret_cast< const Reference< XInterface > * >( &p ) );
} }
else else
@@ -157,7 +131,7 @@ OInterfaceContainerHelper::~OInterfaceContainerHelper()
{ {
OSL_ENSURE( !bInUse, "~OInterfaceContainerHelper but is in use" ); OSL_ENSURE( !bInUse, "~OInterfaceContainerHelper but is in use" );
if( bIsList ) if( bIsList )
delete aData.pAsSequence; delete aData.pAsVector;
else if( aData.pAsInterface ) else if( aData.pAsInterface )
aData.pAsInterface->release(); aData.pAsInterface->release();
} }
@@ -166,17 +140,30 @@ sal_Int32 OInterfaceContainerHelper::getLength() const
{ {
MutexGuard aGuard( rMutex ); MutexGuard aGuard( rMutex );
if( bIsList ) if( bIsList )
return aData.pAsSequence->getLength(); return aData.pAsVector->size();
else if( aData.pAsInterface ) else if( aData.pAsInterface )
return 1; return 1;
return 0; return 0;
} }
Sequence< Reference<XInterface> > OInterfaceContainerHelper::getElements() const std::vector< Reference<XInterface> > OInterfaceContainerHelper::getElementsAsVector() const
{ {
MutexGuard aGuard( rMutex ); MutexGuard aGuard( rMutex );
if( bIsList ) if( bIsList )
return *aData.pAsSequence; return *aData.pAsVector;
else if( aData.pAsInterface )
{
Reference<XInterface> x( aData.pAsInterface );
return { x };
}
return std::vector< Reference< XInterface > >();
}
css::uno::Sequence< Reference<XInterface> > OInterfaceContainerHelper::getElements() const
{
MutexGuard aGuard( rMutex );
if( bIsList )
return css::uno::Sequence< Reference<XInterface> >( aData.pAsVector->data(), static_cast<sal_Int32>(aData.pAsVector->size()) );
else if( aData.pAsInterface ) else if( aData.pAsInterface )
{ {
Reference<XInterface> x( aData.pAsInterface ); Reference<XInterface> x( aData.pAsInterface );
@@ -193,7 +180,7 @@ void OInterfaceContainerHelper::copyAndResetInUse()
// this should be the worst case. If a iterator is active // this should be the worst case. If a iterator is active
// and a new Listener is added. // and a new Listener is added.
if( bIsList ) if( bIsList )
aData.pAsSequence = new Sequence< Reference< XInterface > >( *aData.pAsSequence ); aData.pAsVector = new std::vector< Reference< XInterface > >( *aData.pAsVector );
else if( aData.pAsInterface ) else if( aData.pAsInterface )
aData.pAsInterface->acquire(); aData.pAsInterface->acquire();
@@ -210,19 +197,16 @@ sal_Int32 OInterfaceContainerHelper::addInterface( const Reference<XInterface> &
if( bIsList ) if( bIsList )
{ {
sal_Int32 nLen = aData.pAsSequence->getLength(); aData.pAsVector->push_back( rListener );
realloc( *aData.pAsSequence, nLen +1 ); return aData.pAsVector->size();
aData.pAsSequence->getArray()[ nLen ] = rListener;
return nLen +1;
} }
else if( aData.pAsInterface ) else if( aData.pAsInterface )
{ {
Sequence< Reference< XInterface > > * pSeq = new Sequence< Reference< XInterface > >( 2 ); std::vector< Reference< XInterface > > * pSeq = new std::vector< Reference< XInterface > >( 2 );
Reference<XInterface> * pArray = pSeq->getArray(); (*pSeq)[0] = aData.pAsInterface;
pArray[0] = aData.pAsInterface; (*pSeq)[1] = rListener;
pArray[1] = rListener;
aData.pAsInterface->release(); aData.pAsInterface->release();
aData.pAsSequence = pSeq; aData.pAsVector = pSeq;
bIsList = sal_True; bIsList = sal_True;
return 2; return 2;
} }
@@ -244,43 +228,41 @@ sal_Int32 OInterfaceContainerHelper::removeInterface( const Reference<XInterface
if( bIsList ) if( bIsList )
{ {
const Reference<XInterface> * pL = aData.pAsSequence->getConstArray(); // It is not valid to compare the pointer directly, but it's faster.
sal_Int32 nLen = aData.pAsSequence->getLength(); bool bFound = false;
sal_Int32 i; for( auto it = std::begin(*aData.pAsVector); it != std::end(*aData.pAsVector); ++it )
for( i = 0; i < nLen; i++ )
{ {
// It is not valid to compare the pointer directly, but it's faster. if( (*it).get() == rListener.get() )
if( pL[i].get() == rListener.get() )
{ {
sequenceRemoveElementAt( *aData.pAsSequence, i ); aData.pAsVector->erase(it);
bFound = true;
break; break;
} }
} }
if (!bFound)
if( i == nLen )
{ {
// interface not found, use the correct compare method // interface not found, use the correct compare method
for( i = 0; i < nLen; i++ ) for( auto it = std::begin(*aData.pAsVector); it != std::end(*aData.pAsVector); ++it )
{ {
if( pL[i] == rListener ) if( *it == rListener )
{ {
sequenceRemoveElementAt(*aData.pAsSequence, i ); aData.pAsVector->erase(it);
break; break;
} }
} }
} }
if( aData.pAsSequence->getLength() == 1 ) if( aData.pAsVector->size() == 1 )
{ {
XInterface * p = aData.pAsSequence->getConstArray()[0].get(); XInterface * p = (*aData.pAsVector)[0].get();
p->acquire(); p->acquire();
delete aData.pAsSequence; delete aData.pAsVector;
aData.pAsInterface = p; aData.pAsInterface = p;
bIsList = sal_False; bIsList = sal_False;
return 1; return 1;
} }
else else
return aData.pAsSequence->getLength(); return aData.pAsVector->size();
} }
else if( aData.pAsInterface && Reference<XInterface>( aData.pAsInterface ) == rListener ) else if( aData.pAsInterface && Reference<XInterface>( aData.pAsInterface ) == rListener )
{ {

View File

@@ -104,22 +104,15 @@ com_sun_star_comp_dba_ORowSet_get_implementation(css::uno::XComponentContext* co
} }
#define NOTIFY_LISTERNERS_CHECK(_rListeners,T,method) \ #define NOTIFY_LISTERNERS_CHECK(_rListeners,T,method) \
Sequence< Reference< XInterface > > aListenerSeq = _rListeners.getElements(); \ std::vector< Reference< XInterface > > aListenerSeq = _rListeners.getElementsAsVector(); \
\
const Reference< XInterface >* pxIntBegin = aListenerSeq.getConstArray(); \
const Reference< XInterface >* pxInt = pxIntBegin + aListenerSeq.getLength(); \
\ \
_rGuard.clear(); \ _rGuard.clear(); \
bool bCheck = true; \ bool bCheck = true; \
while( pxInt > pxIntBegin && bCheck ) \ for( auto iter = aListenerSeq.rbegin(); iter != aListenerSeq.rend() && bCheck; ++iter ) \
{ \ { \
try \ try \
{ \ { \
while( pxInt > pxIntBegin && bCheck ) \ bCheck = static_cast< T* >( (*iter).get() )->method(aEvt); \
{ \
--pxInt; \
bCheck = static_cast< T* >( pxInt->get() )->method(aEvt); \
} \
} \ } \
catch( RuntimeException& ) \ catch( RuntimeException& ) \
{ \ { \

View File

@@ -328,21 +328,14 @@ public:
return new ::cppu::OPropertyArrayHelper(aDescriptor); return new ::cppu::OPropertyArrayHelper(aDescriptor);
#define NOTIFY_LISTERNERS(_rListeners,T,method) \ #define NOTIFY_LISTERNERS(_rListeners,T,method) \
Sequence< Reference< XInterface > > aListenerSeq = _rListeners.getElements(); \ std::vector< Reference< XInterface > > aListenerSeq = _rListeners.getElementsAsVector(); \
\
const Reference< XInterface >* pxIntBegin = aListenerSeq.getConstArray(); \
const Reference< XInterface >* pxInt = pxIntBegin + aListenerSeq.getLength(); \
\ \
_rGuard.clear(); \ _rGuard.clear(); \
while( pxInt > pxIntBegin ) \ for( auto iter = aListenerSeq.rbegin(); iter != aListenerSeq.rend(); ++iter ) \
{ \ { \
try \ try \
{ \ { \
while( pxInt > pxIntBegin ) \ static_cast< T* >( (*iter).get() )->method(aEvt); \
{ \
--pxInt; \
static_cast< T* >( pxInt->get() )->method(aEvt); \
} \
} \ } \
catch( RuntimeException& ) \ catch( RuntimeException& ) \
{ \ { \

View File

@@ -596,10 +596,10 @@ void Package::fireModified()
::cppu::OInterfaceContainerHelper * container = rBHelper.getContainer( ::cppu::OInterfaceContainerHelper * container = rBHelper.getContainer(
cppu::UnoType<util::XModifyListener>::get() ); cppu::UnoType<util::XModifyListener>::get() );
if (container != 0) { if (container != 0) {
Sequence< Reference<XInterface> > elements( std::vector< Reference<XInterface> > elements(
container->getElements() ); container->getElementsAsVector() );
lang::EventObject evt( static_cast<OWeakObject *>(this) ); lang::EventObject evt( static_cast<OWeakObject *>(this) );
for ( sal_Int32 pos = 0; pos < elements.getLength(); ++pos ) for ( sal_Int32 pos = 0; pos < (sal_Int32)elements.size(); ++pos )
{ {
Reference<util::XModifyListener> xListener( Reference<util::XModifyListener> xListener(
elements[ pos ], UNO_QUERY ); elements[ pos ], UNO_QUERY );

View File

@@ -218,10 +218,10 @@ void Interceptor::generateFeatureStateEvent()
cppu::OInterfaceContainerHelper* pICH = cppu::OInterfaceContainerHelper* pICH =
m_pStatCL->getContainer(m_aInterceptedURL[i]); m_pStatCL->getContainer(m_aInterceptedURL[i]);
uno::Sequence<uno::Reference<uno::XInterface> > aSeq; std::vector<uno::Reference<uno::XInterface> > aSeq;
if(pICH) if(pICH)
aSeq = pICH->getElements(); aSeq = pICH->getElementsAsVector();
if(!aSeq.getLength()) if(aSeq.empty())
continue; continue;
frame::FeatureStateEvent aStateEvent; frame::FeatureStateEvent aStateEvent;
@@ -249,13 +249,11 @@ void Interceptor::generateFeatureStateEvent()
} }
for(sal_Int32 k = 0; k < aSeq.getLength(); ++k) for(uno::Reference<uno::XInterface> & x : aSeq)
{ {
uno::Reference<frame::XStatusListener> uno::Reference<frame::XStatusListener> Control(x,uno::UNO_QUERY);
Control(aSeq[k],uno::UNO_QUERY);
if(Control.is()) if(Control.is())
Control->statusChanged(aStateEvent); Control->statusChanged(aStateEvent);
} }
} }
} }

View File

@@ -47,7 +47,7 @@ namespace detail {
*/ */
union element_alias union element_alias
{ {
::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > > *pAsSequence; std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > > *pAsVector;
::com::sun::star::uno::XInterface * pAsInterface; ::com::sun::star::uno::XInterface * pAsInterface;
element_alias() : pAsInterface(0) {} element_alias() : pAsInterface(0) {}
}; };
@@ -155,10 +155,18 @@ public:
*/ */
sal_Int32 SAL_CALL getLength() const; sal_Int32 SAL_CALL getLength() const;
#ifdef LIBO_INTERNAL_ONLY
/**
Return all interfaces added to this container.
@since LibreOffice 5.1
Not exposed because std::vector is problematic for an ABI
**/
std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > > SAL_CALL getElementsAsVector() const;
#endif
/** /**
Return all interfaces added to this container. Return all interfaces added to this container.
**/ **/
::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > > SAL_CALL getElements() const; css::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > > SAL_CALL getElements() const;
/** Inserts an element into the container. The position is not specified, thus it is not /** Inserts an element into the container. The position is not specified, thus it is not
specified in which order events are fired. specified in which order events are fired.
@@ -236,14 +244,14 @@ public:
private: private:
friend class OInterfaceIteratorHelper; friend class OInterfaceIteratorHelper;
/** /**
bIsList == TRUE -> aData.pAsSequence of type Sequence< XInterfaceSequence >, bIsList == TRUE -> aData.pAsVector of type std::vector< XInterface >,
otherwise aData.pAsInterface == of type (XEventListener *) otherwise aData.pAsInterface == of type (XEventListener *)
*/ */
detail::element_alias aData; detail::element_alias aData;
::osl::Mutex & rMutex; ::osl::Mutex & rMutex;
/** TRUE -> used by an iterator. */ /** TRUE -> used by an iterator. */
sal_Bool bInUse; sal_Bool bInUse;
/** TRUE -> aData.pAsSequence is of type Sequence< XInterfaceSequence >. */ /** TRUE -> aData.pAsVector is of type std::vector< XInterface >. */
sal_Bool bIsList; sal_Bool bIsList;
OInterfaceContainerHelper( const OInterfaceContainerHelper & ) OInterfaceContainerHelper( const OInterfaceContainerHelper & )

View File

@@ -410,32 +410,19 @@ void SAL_CALL ScCellFieldsObj::refresh( )
if (mpRefreshListeners) if (mpRefreshListeners)
{ {
// Call all listeners. // Call all listeners.
uno::Sequence< uno::Reference< uno::XInterface > > aListeners(mpRefreshListeners->getElements()); std::vector< uno::Reference< uno::XInterface > > aListeners(mpRefreshListeners->getElementsAsVector());
sal_uInt32 nLength(aListeners.getLength()); if (!aListeners.empty())
if (nLength)
{ {
const uno::Reference< uno::XInterface >* pInterfaces = aListeners.getConstArray(); lang::EventObject aEvent;
if (pInterfaces) aEvent.Source.set(uno::Reference< util::XRefreshable >(this));
for (auto & x : aListeners)
{ {
lang::EventObject aEvent; try
aEvent.Source.set(uno::Reference< util::XRefreshable >(this)); {
sal_uInt32 i(0); static_cast< util::XRefreshListener* >(x.get())->refreshed(aEvent);
while (i < nLength) }
catch(uno::RuntimeException&)
{ {
try
{
while(i < nLength)
{
static_cast< util::XRefreshListener* >(pInterfaces->get())->refreshed(aEvent);
++pInterfaces;
++i;
}
}
catch(uno::RuntimeException&)
{
++pInterfaces;
++i;
}
} }
} }
} }
@@ -590,32 +577,19 @@ void SAL_CALL ScHeaderFieldsObj::refresh( )
if (mpRefreshListeners) if (mpRefreshListeners)
{ {
// Call all listeners. // Call all listeners.
uno::Sequence< uno::Reference< uno::XInterface > > aListeners(mpRefreshListeners->getElements()); std::vector< uno::Reference< uno::XInterface > > aListeners(mpRefreshListeners->getElementsAsVector());
sal_uInt32 nLength(aListeners.getLength()); if (!aListeners.empty())
if (nLength)
{ {
const uno::Reference< uno::XInterface >* pInterfaces = aListeners.getConstArray(); lang::EventObject aEvent;
if (pInterfaces) aEvent.Source.set(uno::Reference< util::XRefreshable >(this));
for (auto & x : aListeners)
{ {
lang::EventObject aEvent; try
aEvent.Source.set(uno::Reference< util::XRefreshable >(this)); {
sal_uInt32 i(0); static_cast< util::XRefreshListener* >(x.get())->refreshed(aEvent);
while (i < nLength) }
catch(uno::RuntimeException&)
{ {
try
{
while(i < nLength)
{
static_cast< util::XRefreshListener* >(pInterfaces->get())->refreshed(aEvent);
++pInterfaces;
++i;
}
}
catch(uno::RuntimeException&)
{
++pInterfaces;
++i;
}
} }
} }
} }

View File

@@ -345,14 +345,13 @@ bool SdStyleSheet::IsUsed() const
OInterfaceContainerHelper * pContainer = mrBHelper.getContainer( cppu::UnoType<XModifyListener>::get() ); OInterfaceContainerHelper * pContainer = mrBHelper.getContainer( cppu::UnoType<XModifyListener>::get() );
if( pContainer ) if( pContainer )
{ {
Sequence< Reference< XInterface > > aModifyListeners( pContainer->getElements() ); for( auto & x : pContainer->getElements() )
Reference< XInterface > *p = aModifyListeners.getArray();
sal_Int32 nCount = aModifyListeners.getLength();
while( nCount-- && !bResult )
{ {
Reference< XStyle > xStyle( *p++, UNO_QUERY ); Reference< XStyle > xStyle( x, UNO_QUERY );
if( xStyle.is() ) if( xStyle.is() ) {
bResult = xStyle->isInUse(); bResult = xStyle->isInUse();
break;
}
} }
} }
} }

View File

@@ -2282,11 +2282,11 @@ void SfxDocumentMetaData::createUserDefined()
m_xUserDefined, css::uno::UNO_QUERY); m_xUserDefined, css::uno::UNO_QUERY);
if (xMB.is()) if (xMB.is())
{ {
const css::uno::Sequence<css::uno::Reference<css::uno::XInterface> > const std::vector<css::uno::Reference<css::uno::XInterface> >
listeners(m_NotifyListeners.getElements()); listeners(m_NotifyListeners.getElementsAsVector());
for (css::uno::Reference< css::uno::XInterface > const * iter = listeners.begin(); iter != listeners.end(); ++iter) { for (css::uno::Reference< css::uno::XInterface > const & iter : listeners) {
xMB->addModifyListener( xMB->addModifyListener(
css::uno::Reference< css::util::XModifyListener >(*iter, css::uno::Reference< css::util::XModifyListener >(iter,
css::uno::UNO_QUERY)); css::uno::UNO_QUERY));
} }
} }

View File

@@ -235,10 +235,10 @@ sal_Bool SAL_CALL TableDesignStyle::isInUse() throw (RuntimeException, std::exce
OInterfaceContainerHelper * pContainer = rBHelper.getContainer( cppu::UnoType<XModifyListener>::get() ); OInterfaceContainerHelper * pContainer = rBHelper.getContainer( cppu::UnoType<XModifyListener>::get() );
if( pContainer ) if( pContainer )
{ {
Sequence< Reference< XInterface > > aListener( pContainer->getElements() ); std::vector< Reference< XInterface > > aListener( pContainer->getElementsAsVector() );
aGuard.clear(); aGuard.clear();
sal_Int32 nIndex = aListener.getLength(); sal_Int32 nIndex = aListener.size();
while( --nIndex >= 0 ) while( --nIndex >= 0 )
{ {
TableDesignUser* pUser = dynamic_cast< TableDesignUser* >( aListener[nIndex].get() ); TableDesignUser* pUser = dynamic_cast< TableDesignUser* >( aListener[nIndex].get() );

View File

@@ -229,10 +229,10 @@ uno::Any SAL_CALL SvxShapeCollection::getByIndex( sal_Int32 Index )
if( Index < 0 || Index >= getCount() ) if( Index < 0 || Index >= getCount() )
throw lang::IndexOutOfBoundsException(); throw lang::IndexOutOfBoundsException();
uno::Sequence< Reference< uno::XInterface> > xElements( maShapeContainer.getElements() ); std::vector< Reference< uno::XInterface> > xElements( maShapeContainer.getElementsAsVector() );
return uno::makeAny( Reference< drawing::XShape>(static_cast< drawing::XShape* >( xElements.getArray()[Index].get())) ); return uno::makeAny( Reference< drawing::XShape>(static_cast< drawing::XShape* >( xElements[Index].get())) );
} }
// XElementAccess // XElementAccess

View File

@@ -1757,13 +1757,13 @@ void VCLXToolkit::callTopWindowListeners(
= static_cast< ::VclWindowEvent const * >(pEvent)->GetWindow(); = static_cast< ::VclWindowEvent const * >(pEvent)->GetWindow();
if (pWindow->IsTopWindow()) if (pWindow->IsTopWindow())
{ {
css::uno::Sequence< css::uno::Reference< css::uno::XInterface > > std::vector< css::uno::Reference< css::uno::XInterface > >
aListeners(m_aTopWindowListeners.getElements()); aListeners(m_aTopWindowListeners.getElementsAsVector());
if (aListeners.hasElements()) if (!aListeners.empty())
{ {
css::lang::EventObject aAwtEvent( css::lang::EventObject aAwtEvent(
static_cast< css::awt::XWindow * >(pWindow->GetWindowPeer())); static_cast< css::awt::XWindow * >(pWindow->GetWindowPeer()));
for (::sal_Int32 i = 0; i < aListeners.getLength(); ++i) for (::sal_Int32 i = 0; i < (sal_Int32)aListeners.size(); ++i)
{ {
css::uno::Reference< css::awt::XTopWindowListener > css::uno::Reference< css::awt::XTopWindowListener >
xListener(aListeners[i], css::uno::UNO_QUERY); xListener(aListeners[i], css::uno::UNO_QUERY);
@@ -1786,10 +1786,10 @@ void VCLXToolkit::callTopWindowListeners(
long VCLXToolkit::callKeyHandlers(::VclSimpleEvent const * pEvent, long VCLXToolkit::callKeyHandlers(::VclSimpleEvent const * pEvent,
bool bPressed) bool bPressed)
{ {
css::uno::Sequence< css::uno::Reference< css::uno::XInterface > > std::vector< css::uno::Reference< css::uno::XInterface > >
aHandlers(m_aKeyHandlers.getElements()); aHandlers(m_aKeyHandlers.getElementsAsVector());
if (aHandlers.hasElements()) if (!aHandlers.empty())
{ {
vcl::Window * pWindow = static_cast< ::VclWindowEvent const * >(pEvent)->GetWindow(); vcl::Window * pWindow = static_cast< ::VclWindowEvent const * >(pEvent)->GetWindow();
@@ -1809,7 +1809,7 @@ long VCLXToolkit::callKeyHandlers(::VclSimpleEvent const * pEvent,
pKeyEvent->GetKeyCode().GetCode(), pKeyEvent->GetCharCode(), pKeyEvent->GetKeyCode().GetCode(), pKeyEvent->GetCharCode(),
sal::static_int_cast< sal_Int16 >( sal::static_int_cast< sal_Int16 >(
pKeyEvent->GetKeyCode().GetFunction())); pKeyEvent->GetKeyCode().GetFunction()));
for (::sal_Int32 i = 0; i < aHandlers.getLength(); ++i) for (::sal_Int32 i = 0; i < (sal_Int32)aHandlers.size(); ++i)
{ {
css::uno::Reference< css::awt::XKeyHandler > xHandler( css::uno::Reference< css::awt::XKeyHandler > xHandler(
aHandlers[i], css::uno::UNO_QUERY); aHandlers[i], css::uno::UNO_QUERY);
@@ -1838,9 +1838,9 @@ void VCLXToolkit::callFocusListeners(::VclSimpleEvent const * pEvent,
= static_cast< ::VclWindowEvent const * >(pEvent)->GetWindow(); = static_cast< ::VclWindowEvent const * >(pEvent)->GetWindow();
if (pWindow->IsTopWindow()) if (pWindow->IsTopWindow())
{ {
css::uno::Sequence< css::uno::Reference< css::uno::XInterface > > std::vector< css::uno::Reference< css::uno::XInterface > >
aListeners(m_aFocusListeners.getElements()); aListeners(m_aFocusListeners.getElementsAsVector());
if (aListeners.hasElements()) if (!aListeners.empty())
{ {
// Ignore the interior of compound controls when determining the // Ignore the interior of compound controls when determining the
// window that gets the focus next (see implementation in // window that gets the focus next (see implementation in
@@ -1859,7 +1859,7 @@ void VCLXToolkit::callFocusListeners(::VclSimpleEvent const * pEvent,
static_cast< css::awt::XWindow * >(pWindow->GetWindowPeer()), static_cast< css::awt::XWindow * >(pWindow->GetWindowPeer()),
static_cast<sal_Int16>(pWindow->GetGetFocusFlags()), static_cast<sal_Int16>(pWindow->GetGetFocusFlags()),
xNext, false); xNext, false);
for (::sal_Int32 i = 0; i < aListeners.getLength(); ++i) for (size_t i = 0; i < aListeners.size(); ++i)
{ {
css::uno::Reference< css::awt::XFocusListener > xListener( css::uno::Reference< css::awt::XFocusListener > xListener(
aListeners[i], css::uno::UNO_QUERY); aListeners[i], css::uno::UNO_QUERY);

View File

@@ -916,13 +916,11 @@ void ControlModelContainerBase::implNotifyTabModelChange( const OUString& _rAcce
aEvent.Changes[ 0 ].Accessor <<= _rAccessor; aEvent.Changes[ 0 ].Accessor <<= _rAccessor;
Sequence< Reference< XInterface > > aChangeListeners( maChangeListeners.getElements() ); std::vector< Reference< XInterface > > aChangeListeners( maChangeListeners.getElementsAsVector() );
const Reference< XInterface >* pListener = aChangeListeners.getConstArray(); for ( Reference< XInterface > & rListener : aChangeListeners )
const Reference< XInterface >* pListenerEnd = aChangeListeners.getConstArray() + aChangeListeners.getLength();
for ( ; pListener != pListenerEnd; ++pListener )
{ {
if ( pListener->is() ) if ( rListener.is() )
static_cast< XChangesListener* >( pListener->get() )->changesOccurred( aEvent ); static_cast< XChangesListener* >( rListener.get() )->changesOccurred( aEvent );
} }
} }

View File

@@ -162,11 +162,11 @@ XResultSet_impl::dispose()
void XResultSet_impl::rowCountChanged() void XResultSet_impl::rowCountChanged()
{ {
sal_Int32 aOldValue,aNewValue; sal_Int32 aOldValue,aNewValue;
uno::Sequence< uno::Reference< uno::XInterface > > seq; std::vector< uno::Reference< uno::XInterface > > seq;
{ {
osl::MutexGuard aGuard( m_aMutex ); osl::MutexGuard aGuard( m_aMutex );
if( m_pRowCountListeners ) if( m_pRowCountListeners )
seq = m_pRowCountListeners->getElements(); seq = m_pRowCountListeners->getElementsAsVector();
aNewValue = m_aItems.size(); aNewValue = m_aItems.size();
aOldValue = aNewValue-1; aOldValue = aNewValue-1;
} }
@@ -176,7 +176,7 @@ void XResultSet_impl::rowCountChanged()
aEv.PropertyHandle = -1; aEv.PropertyHandle = -1;
aEv.OldValue <<= aOldValue; aEv.OldValue <<= aOldValue;
aEv.NewValue <<= aNewValue; aEv.NewValue <<= aNewValue;
for( sal_Int32 i = 0; i < seq.getLength(); ++i ) for( sal_Int32 i = 0; i < (sal_Int32)seq.size(); ++i )
{ {
uno::Reference< beans::XPropertyChangeListener > listener( uno::Reference< beans::XPropertyChangeListener > listener(
seq[i], uno::UNO_QUERY ); seq[i], uno::UNO_QUERY );
@@ -188,11 +188,11 @@ void XResultSet_impl::rowCountChanged()
void XResultSet_impl::isFinalChanged() void XResultSet_impl::isFinalChanged()
{ {
uno::Sequence< uno::Reference< XInterface > > seq; std::vector< uno::Reference< XInterface > > seq;
{ {
osl::MutexGuard aGuard( m_aMutex ); osl::MutexGuard aGuard( m_aMutex );
if( m_pIsFinalListeners ) if( m_pIsFinalListeners )
seq = m_pIsFinalListeners->getElements(); seq = m_pIsFinalListeners->getElementsAsVector();
m_bRowCountFinal = true; m_bRowCountFinal = true;
} }
beans::PropertyChangeEvent aEv; beans::PropertyChangeEvent aEv;
@@ -203,7 +203,7 @@ void XResultSet_impl::isFinalChanged()
bool tval = true; bool tval = true;
aEv.OldValue <<= fval; aEv.OldValue <<= fval;
aEv.NewValue <<= tval; aEv.NewValue <<= tval;
for( sal_Int32 i = 0; i < seq.getLength(); ++i ) for( sal_Int32 i = 0; i < (sal_Int32)seq.size(); ++i )
{ {
uno::Reference< beans::XPropertyChangeListener > listener( uno::Reference< beans::XPropertyChangeListener > listener(
seq[i], uno::UNO_QUERY ); seq[i], uno::UNO_QUERY );