summaryrefslogtreecommitdiff
path: root/cppu
diff options
context:
space:
mode:
authorArkadiy Illarionov <qarkai@gmail.com>2019-03-03 13:10:45 +0300
committerNoel Grandin <noel.grandin@collabora.co.uk>2019-03-03 16:27:08 +0100
commit5af9e26ae8b463e85cb84f79a366c61d49a2d52b (patch)
treed8e001ed45e2a441e19864f8e2613317c9019ffa /cppu
parent20b1a4589ee95e34afdb3c82834fe32e1ccb25fb (diff)
Simplify containers iterations in cppcanvas, cppu, cppuhelper
Use range-based loop or replace with STL functions Change-Id: I72bf7cdb632c04e2fc8d4f7ab85cb6571222aa07 Reviewed-on: https://gerrit.libreoffice.org/68636 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'cppu')
-rw-r--r--cppu/source/threadpool/jobqueue.cxx8
-rw-r--r--cppu/source/typelib/typelib.cxx56
-rw-r--r--cppu/source/uno/lbenv.cxx23
-rw-r--r--cppu/source/uno/lbmap.cxx5
4 files changed, 30 insertions, 62 deletions
diff --git a/cppu/source/threadpool/jobqueue.cxx b/cppu/source/threadpool/jobqueue.cxx
index 2d375dcf8bbd..6c9324521f40 100644
--- a/cppu/source/threadpool/jobqueue.cxx
+++ b/cppu/source/threadpool/jobqueue.cxx
@@ -129,13 +129,11 @@ namespace cppu_threadpool {
void JobQueue::dispose( sal_Int64 nDisposeId )
{
MutexGuard guard( m_mutex );
- for( auto ii = m_lstCallstack.begin() ;
- ii != m_lstCallstack.end() ;
- ++ii )
+ for( auto& rId : m_lstCallstack )
{
- if( (*ii) == nDisposeId )
+ if( rId == nDisposeId )
{
- (*ii) = 0;
+ rId = 0;
}
}
diff --git a/cppu/source/typelib/typelib.cxx b/cppu/source/typelib/typelib.cxx
index 309543b4078d..d9fe276a6c3b 100644
--- a/cppu/source/typelib/typelib.cxx
+++ b/cppu/source/typelib/typelib.cxx
@@ -18,6 +18,7 @@
*/
+#include <algorithm>
#include <unordered_map>
#include <cassert>
#include <list>
@@ -223,14 +224,11 @@ inline void TypeDescriptor_Init_Impl::callChain(
assert(*ppRet == nullptr);
if (pCallbacks)
{
- CallbackSet_Impl::const_iterator aIt = pCallbacks->begin();
- while( aIt != pCallbacks->end() )
+ for( const CallbackEntry & rEntry : *pCallbacks )
{
- const CallbackEntry & rEntry = *aIt;
(*rEntry.second)( rEntry.first, ppRet, pName );
if( *ppRet )
return;
- ++aIt;
}
}
}
@@ -240,11 +238,9 @@ TypeDescriptor_Init_Impl::~TypeDescriptor_Init_Impl()
{
if( pCache )
{
- TypeDescriptionList_Impl::const_iterator aIt = pCache->begin();
- while( aIt != pCache->end() )
+ for( typelib_TypeDescription* pItem : *pCache )
{
- typelib_typedescription_release( *aIt );
- ++aIt;
+ typelib_typedescription_release( pItem );
}
}
@@ -254,19 +250,14 @@ TypeDescriptor_Init_Impl::~TypeDescriptor_Init_Impl()
ppTDR.reserve( pWeakMap->size() );
// save all weak references
- WeakMap_Impl::const_iterator aIt = pWeakMap->begin();
- while( aIt != pWeakMap->end() )
+ for( const auto& rEntry : *pWeakMap )
{
- ppTDR.push_back( (*aIt).second );
+ ppTDR.push_back( rEntry.second );
typelib_typedescriptionreference_acquire( ppTDR.back() );
- ++aIt;
}
- for( std::vector< typelib_TypeDescriptionReference * >::iterator i(
- ppTDR.begin() );
- i != ppTDR.end(); ++i )
+ for( typelib_TypeDescriptionReference * pTDR : ppTDR )
{
- typelib_TypeDescriptionReference * pTDR = *i;
OSL_ASSERT( pTDR->nRefCount > pTDR->nStaticRefCount );
pTDR->nRefCount -= pTDR->nStaticRefCount;
@@ -278,11 +269,10 @@ TypeDescriptor_Init_Impl::~TypeDescriptor_Init_Impl()
typelib_typedescriptionreference_release( pTDR );
}
- aIt = pWeakMap->begin();
#if defined SAL_LOG_INFO
- while( aIt != pWeakMap->end() )
+ for( const auto& rEntry : *pWeakMap )
{
- typelib_TypeDescriptionReference * pTDR = (*aIt).second;
+ typelib_TypeDescriptionReference * pTDR = rEntry.second;
if (pTDR)
{
OString aTypeName( OUStringToOString( pTDR->pTypeName, RTL_TEXTENCODING_ASCII_US ) );
@@ -292,7 +282,6 @@ TypeDescriptor_Init_Impl::~TypeDescriptor_Init_Impl()
{
SAL_INFO("cppu.typelib", "remaining null type entry!?");
}
- ++aIt;
}
#endif
}
@@ -336,18 +325,8 @@ extern "C" void SAL_CALL typelib_typedescription_revokeCallback(
// todo mt safe: guard is no solution, can not acquire while calling callback!
// OslGuard aGuard( rInit.getMutex() );
CallbackEntry aEntry( pContext, pCallback );
- CallbackSet_Impl::iterator iPos( rInit.pCallbacks->begin() );
- while (iPos != rInit.pCallbacks->end())
- {
- if (*iPos == aEntry)
- {
- iPos = rInit.pCallbacks->erase(iPos);
- }
- else
- {
- ++iPos;
- }
- }
+ rInit.pCallbacks->erase(std::remove(rInit.pCallbacks->begin(), rInit.pCallbacks->end(), aEntry),
+ rInit.pCallbacks->end());
}
}
@@ -1018,21 +997,20 @@ extern "C" void SAL_CALL typelib_typedescription_newMIInterface(
sal_Int32 n = 0;
BaseList::List const & rList = aBaseList.getList();
- for (BaseList::List::const_iterator i(rList.begin()); i != rList.end();
- ++i)
+ for (const auto& rEntry : rList)
{
- typelib_InterfaceTypeDescription const * pBase = i->base;
+ typelib_InterfaceTypeDescription const * pBase = rEntry.base;
typelib_InterfaceTypeDescription const * pDirectBase
- = pITD->ppBaseTypes[i->directBaseIndex];
+ = pITD->ppBaseTypes[rEntry.directBaseIndex];
OSL_ASSERT(pBase->ppAllMembers != nullptr);
for (sal_Int32 j = 0; j < pBase->nMembers; ++j) {
typelib_TypeDescriptionReference const * pDirectBaseMember
- = pDirectBase->ppAllMembers[i->directBaseMemberOffset + j];
+ = pDirectBase->ppAllMembers[rEntry.directBaseMemberOffset + j];
OUStringBuffer aBuf(pDirectBaseMember->pTypeName);
aBuf.append(":@");
- aBuf.append(i->directBaseIndex);
+ aBuf.append(rEntry.directBaseIndex);
aBuf.append(',');
- aBuf.append(i->memberOffset + j);
+ aBuf.append(rEntry.memberOffset + j);
aBuf.append(':');
aBuf.append(pITD->aBase.pTypeName);
OUString aName(aBuf.makeStringAndClear());
diff --git a/cppu/source/uno/lbenv.cxx b/cppu/source/uno/lbenv.cxx
index 9e9de7655041..394aa2ddf41a 100644
--- a/cppu/source/uno/lbenv.cxx
+++ b/cppu/source/uno/lbenv.cxx
@@ -495,12 +495,9 @@ static void defenv_getRegisteredInterfaces(
sal_Int32 nPos = 0;
void ** ppInterfaces = static_cast<void **>((*memAlloc)( nLen * sizeof (void *) ));
- Ptr2ObjectMap::const_iterator iPos( that->aPtr2ObjectMap.begin() );
- Ptr2ObjectMap::const_iterator const iEnd( that->aPtr2ObjectMap.end() );
- while (iPos != iEnd)
+ for (const auto& rEntry : that->aPtr2ObjectMap)
{
- (*pEnv->acquireInterface)( pEnv, ppInterfaces[nPos++] = (*iPos).first );
- ++iPos;
+ (*pEnv->acquireInterface)( pEnv, ppInterfaces[nPos++] = rEntry.first );
}
*pppInterfaces = ppInterfaces;
@@ -711,10 +708,9 @@ extern "C" void SAL_CALL uno_dumpEnvironment(
::osl::MutexGuard guard( that->mutex );
Ptr2ObjectMap ptr2obj( that->aPtr2ObjectMap );
- OId2ObjectMap::const_iterator iPos( that->aOId2ObjectMap.begin() );
- while (iPos != that->aOId2ObjectMap.end())
+ for (const auto& rEntry : that->aOId2ObjectMap)
{
- ObjectEntry * pOEntry = iPos->second;
+ ObjectEntry * pOEntry = rEntry.second;
buf.append( "+ " );
if (pOEntry->mixedObject)
@@ -757,7 +753,6 @@ extern "C" void SAL_CALL uno_dumpEnvironment(
}
writeLine( stream, buf.makeStringAndClear(), pFilter );
}
- ++iPos;
}
if (! ptr2obj.empty())
writeLine( stream, "ptr map inconsistency!!!", pFilter );
@@ -893,10 +888,9 @@ EnvironmentsData::~EnvironmentsData()
::osl::MutexGuard guard( mutex );
isDisposing = true;
- for ( OUString2EnvironmentMap::const_iterator iPos( aName2EnvMap.begin() );
- iPos != aName2EnvMap.end(); ++iPos )
+ for ( const auto& rEntry : aName2EnvMap )
{
- uno_Environment * pWeak = iPos->second;
+ uno_Environment * pWeak = rEntry.second;
uno_Environment * pHard = nullptr;
(*pWeak->harden)( &pHard, pWeak );
(*pWeak->releaseWeak)( pWeak );
@@ -982,10 +976,9 @@ void EnvironmentsData::getRegisteredEnvironments(
sal_Int32 nSize = 0;
// find matching environment
- for ( OUString2EnvironmentMap::const_iterator iPos( aName2EnvMap.begin() );
- iPos != aName2EnvMap.end(); ++iPos )
+ for ( const auto& rEntry : aName2EnvMap )
{
- uno_Environment * pWeak = iPos->second;
+ uno_Environment * pWeak = rEntry.second;
if (rEnvDcp.isEmpty() ||
rEnvDcp == pWeak->pTypeName )
{
diff --git a/cppu/source/uno/lbmap.cxx b/cppu/source/uno/lbmap.cxx
index 54852a63082f..fc093907c591 100644
--- a/cppu/source/uno/lbmap.cxx
+++ b/cppu/source/uno/lbmap.cxx
@@ -608,10 +608,9 @@ void SAL_CALL uno_getMapping(
if (! aRet.is()) // try callback chain
{
MutexGuard aGuard( rData.aCallbacksMutex );
- for ( t_CallbackSet::const_iterator iPos( rData.aCallbacks.begin() );
- iPos != rData.aCallbacks.end(); ++iPos )
+ for ( const auto& rCallback : rData.aCallbacks )
{
- (**iPos)( ppMapping, pFrom, pTo, aAddPurpose.pData );
+ (*rCallback)( ppMapping, pFrom, pTo, aAddPurpose.pData );
if (*ppMapping)
return;
}