summaryrefslogtreecommitdiff
path: root/cppu
diff options
context:
space:
mode:
authorArkadiy Illarionov <qarkai@gmail.com>2019-03-03 13:10:45 +0300
committerAron Budea <aron.budea@collabora.com>2019-11-22 17:26:27 +0100
commit58ef4b593bba3d592e07e0f25140808c74f8aa0f (patch)
treee2c9db0f91a5092be86340e7b3b109c76406bf33 /cppu
parent2ba468bc4c29968751c77d69a7c515822222a849 (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> Reviewed-on: https://gerrit.libreoffice.org/83472 Reviewed-by: Aron Budea <aron.budea@collabora.com> Tested-by: Aron Budea <aron.budea@collabora.com>
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 ccfe85c9abe7..124065b2ef34 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>
@@ -226,14 +227,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;
}
}
}
@@ -243,11 +241,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 );
}
}
@@ -257,19 +253,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;
@@ -281,11 +272,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 ) );
@@ -295,7 +285,6 @@ TypeDescriptor_Init_Impl::~TypeDescriptor_Init_Impl()
{
SAL_INFO("cppu.typelib", "remaining null type entry!?");
}
- ++aIt;
}
#endif
}
@@ -339,18 +328,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());
}
}
@@ -1021,21 +1000,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 a336dd33eaf8..1cac15a9b347 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 f9e2a7825834..f97367bdee91 100644
--- a/cppu/source/uno/lbmap.cxx
+++ b/cppu/source/uno/lbmap.cxx
@@ -607,10 +607,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;
}