Kaydet (Commit) 10a48c73 authored tarafından Arkadiy Illarionov's avatar Arkadiy Illarionov Kaydeden (comit) Noel Grandin

Simplify containers iterations in basctl, basegfx, basic, bridges

Use range-based loop or replace with STL functions

Change-Id: I8594740103bdc2091c2d03d4b92bbe8393f5378c
Reviewed-on: https://gerrit.libreoffice.org/69223
Tested-by: Jenkins
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst bb9728bb
......@@ -2877,32 +2877,9 @@ UnoTypeCodeCompletetor::UnoTypeCodeCompletetor( const std::vector< OUString >& a
return;
}
auto j = aVect.begin() + 1;//start from aVect[1]: aVect[0] is the variable name
OUString sMethName;
while( j != aVect.end() )
{
sMethName = *j;
if( CodeCompleteOptions::IsExtendedTypeDeclaration() )
{
if( !CheckMethod(sMethName) && !CheckField(sMethName) )
{
bCanComplete = false;
break;
}
}
else
{
if( !CheckField(sMethName) )
{
bCanComplete = false;
break;
}
}
++j;
}
//start from aVect[1]: aVect[0] is the variable name
bCanComplete = std::none_of(aVect.begin() + 1, aVect.end(), [this](const OUString& rMethName) {
return (!CodeCompleteOptions::IsExtendedTypeDeclaration() || !CheckMethod(rMethName)) && !CheckField(rMethName); });
}
std::vector< OUString > UnoTypeCodeCompletetor::GetXIdlClassMethods() const
......
......@@ -664,10 +664,8 @@ void LibInfo::InsertInfo (
void LibInfo::RemoveInfoFor (ScriptDocument const& rDocument)
{
Map::iterator it;
for (it = m_aMap.begin(); it != m_aMap.end(); ++it)
if (it->first.GetDocument() == rDocument)
break;
Map::iterator it = std::find_if(m_aMap.begin(), m_aMap.end(),
[&rDocument](Map::reference rEntry) { return rEntry.first.GetDocument() == rDocument; });
if (it != m_aMap.end())
m_aMap.erase(it);
}
......
......@@ -51,14 +51,13 @@ void BreakPointList::transfer(BreakPointList & rList)
void BreakPointList::InsertSorted(BreakPoint aNewBrk)
{
for ( auto it = maBreakPoints.begin(); it != maBreakPoints.end(); ++it )
auto it = std::find_if(maBreakPoints.begin(), maBreakPoints.end(),
[&aNewBrk](const BreakPoint& rBreakPoint) { return aNewBrk.nLine <= rBreakPoint.nLine; });
if (it != maBreakPoints.end())
{
if ( aNewBrk.nLine <= it->nLine )
{
DBG_ASSERT( it->nLine != aNewBrk.nLine, "BreakPoint exists already!" );
maBreakPoints.insert( it, aNewBrk );
return;
}
DBG_ASSERT( it->nLine != aNewBrk.nLine, "BreakPoint exists already!" );
maBreakPoints.insert( it, aNewBrk );
return;
}
// no insert position found => LIST_APPEND
maBreakPoints.push_back( aNewBrk );
......@@ -127,14 +126,10 @@ void BreakPointList::ResetHitCount()
void BreakPointList::remove(const BreakPoint* ptr)
{
for ( auto i = maBreakPoints.begin(); i != maBreakPoints.end(); ++i )
{
if ( ptr == &(*i) )
{
maBreakPoints.erase( i );
return;
}
}
auto i = std::find_if(maBreakPoints.begin(), maBreakPoints.end(),
[&ptr](const BreakPoint& rBreakPoint) { return ptr == &rBreakPoint; });
if (i != maBreakPoints.end())
maBreakPoints.erase( i );
return;
}
......
......@@ -335,11 +335,8 @@ public:
BColorDataVector::const_iterator aEnd(rSource.maVector.end());
maVector.insert(aIndex, aStart, aEnd);
for(; aStart != aEnd; ++aStart)
{
if(!aStart->equalZero())
mnUsedEntries++;
}
mnUsedEntries += std::count_if(aStart, aEnd,
[](BColorDataVector::const_reference rData) { return !rData.equalZero(); });
}
}
......@@ -349,13 +346,10 @@ public:
{
const BColorDataVector::iterator aDeleteStart(maVector.begin() + nIndex);
const BColorDataVector::iterator aDeleteEnd(aDeleteStart + nCount);
BColorDataVector::const_iterator aStart(aDeleteStart);
for(; mnUsedEntries && aStart != aDeleteEnd; ++aStart)
{
if(!aStart->equalZero())
mnUsedEntries--;
}
auto nDeleteUsed = std::count_if(aDeleteStart, aDeleteEnd,
[](BColorDataVector::const_reference rData) { return !rData.equalZero(); });
mnUsedEntries -= std::min(mnUsedEntries, static_cast<sal_uInt32>(nDeleteUsed));
// remove point data
maVector.erase(aDeleteStart, aDeleteEnd);
......@@ -482,11 +476,8 @@ public:
NormalsData3DVector::const_iterator aEnd(rSource.maVector.end());
maVector.insert(aIndex, aStart, aEnd);
for(; aStart != aEnd; ++aStart)
{
if(!aStart->equalZero())
mnUsedEntries++;
}
mnUsedEntries += std::count_if(aStart, aEnd,
[](NormalsData3DVector::const_reference rData) { return !rData.equalZero(); });
}
}
......@@ -496,13 +487,10 @@ public:
{
const NormalsData3DVector::iterator aDeleteStart(maVector.begin() + nIndex);
const NormalsData3DVector::iterator aDeleteEnd(aDeleteStart + nCount);
NormalsData3DVector::const_iterator aStart(aDeleteStart);
for(; mnUsedEntries && aStart != aDeleteEnd; ++aStart)
{
if(!aStart->equalZero())
mnUsedEntries--;
}
auto nDeleteUsed = std::count_if(aDeleteStart, aDeleteEnd,
[](NormalsData3DVector::const_reference rData) { return !rData.equalZero(); });
mnUsedEntries -= std::min(mnUsedEntries, static_cast<sal_uInt32>(nDeleteUsed));
// remove point data
maVector.erase(aDeleteStart, aDeleteEnd);
......@@ -637,11 +625,8 @@ public:
TextureData2DVector::const_iterator aEnd(rSource.maVector.end());
maVector.insert(aIndex, aStart, aEnd);
for(; aStart != aEnd; ++aStart)
{
if(!aStart->equalZero())
mnUsedEntries++;
}
mnUsedEntries += std::count_if(aStart, aEnd,
[](TextureData2DVector::const_reference rData) { return !rData.equalZero(); });
}
}
......@@ -651,13 +636,10 @@ public:
{
const TextureData2DVector::iterator aDeleteStart(maVector.begin() + nIndex);
const TextureData2DVector::iterator aDeleteEnd(aDeleteStart + nCount);
TextureData2DVector::const_iterator aStart(aDeleteStart);
for(; mnUsedEntries && aStart != aDeleteEnd; ++aStart)
{
if(!aStart->equalZero())
mnUsedEntries--;
}
auto nDeleteUsed = std::count_if(aDeleteStart, aDeleteEnd,
[](TextureData2DVector::const_reference rData) { return !rData.equalZero(); });
mnUsedEntries -= std::min(mnUsedEntries, static_cast<sal_uInt32>(nDeleteUsed));
// remove point data
maVector.erase(aDeleteStart, aDeleteEnd);
......
......@@ -189,8 +189,8 @@ public:
std::rotate(aTmp2.begin(),pSmallest,aTmp2.end());
aTmp.clear();
for(std::vector<B2DPoint>::iterator pCurr=aTmp2.begin(); pCurr!=aTmp2.end(); ++pCurr)
aTmp.append(*pCurr);
for(const auto& rCurr : aTmp2)
aTmp.append(rCurr);
aRes.append(aTmp);
}
......
......@@ -555,16 +555,13 @@ namespace basic
Reference< XInterface > xNormalizedSource( _rSource.Source, UNO_QUERY );
for ( BasicManagerStore::iterator loop = m_aStore.begin();
loop != m_aStore.end();
++loop
)
BasicManagerStore::iterator it = std::find_if(m_aStore.begin(), m_aStore.end(),
[&xNormalizedSource](BasicManagerStore::reference rEntry) {
return rEntry.first.get() == xNormalizedSource.get(); });
if (it != m_aStore.end())
{
if ( loop->first.get() == xNormalizedSource.get() )
{
impl_removeFromRepository( loop );
return;
}
impl_removeFromRepository( it );
return;
}
OSL_FAIL( "ImplRepository::_disposing: where does this come from?" );
......@@ -580,20 +577,15 @@ namespace basic
BasicManager* pManager = dynamic_cast< BasicManager* >( &_rBC );
OSL_ENSURE( pManager, "ImplRepository::Notify: where does this come from?" );
for ( BasicManagerStore::iterator loop = m_aStore.begin();
loop != m_aStore.end();
++loop
)
BasicManagerStore::iterator it = std::find_if(m_aStore.begin(), m_aStore.end(),
[&pManager](BasicManagerStore::reference rEntry) { return rEntry.second.get() == pManager; });
if (it != m_aStore.end())
{
if ( loop->second.get() == pManager )
{
// a BasicManager which is still in our repository is being deleted.
// That's bad, since by definition, we *own* all instances in our
// repository.
OSL_FAIL( "ImplRepository::Notify: nobody should tamper with the managers, except ourself!" );
m_aStore.erase( loop );
break;
}
// a BasicManager which is still in our repository is being deleted.
// That's bad, since by definition, we *own* all instances in our
// repository.
OSL_FAIL( "ImplRepository::Notify: nobody should tamper with the managers, except ourself!" );
m_aStore.erase( it );
}
}
......
......@@ -200,10 +200,9 @@ void lclRemoveDocBasicItem( StarBASIC& rDocBasic )
it->second->stopListening();
GaDocBasicItems::get().erase( it );
}
auto it_end = GaDocBasicItems::get().end();
for( it = GaDocBasicItems::get().begin(); it != it_end; ++it )
for( auto& rEntry : GaDocBasicItems::get() )
{
it->second->clearDependingVarsOnDelete( rDocBasic );
rEntry.second->clearDependingVarsOnDelete( rDocBasic );
}
}
......
......@@ -4405,14 +4405,8 @@ static DisposeItemVector GaDisposeItemVector;
static DisposeItemVector::iterator lcl_findItemForBasic( StarBASIC const * pBasic )
{
DisposeItemVector::iterator it;
for( it = GaDisposeItemVector.begin() ; it != GaDisposeItemVector.end() ; ++it )
{
StarBasicDisposeItem* pItem = *it;
if( pItem->m_pBasic == pBasic )
return it;
}
return GaDisposeItemVector.end();
return std::find_if(GaDisposeItemVector.begin(), GaDisposeItemVector.end(),
[&pBasic](StarBasicDisposeItem* pItem) { return pItem->m_pBasic == pBasic; });
}
static StarBasicDisposeItem* lcl_getOrCreateItemForBasic( StarBASIC* pBasic )
......
......@@ -1495,16 +1495,11 @@ bool SbModule::SetBP( sal_uInt16 nLine )
return false;
if( !pBreaks )
pBreaks.reset( new SbiBreakpoints );
size_t i;
for( i = 0; i < pBreaks->size(); i++ )
{
sal_uInt16 b = pBreaks->operator[]( i );
if( b == nLine )
return true;
if( b < nLine )
break;
}
pBreaks->insert( pBreaks->begin() + i, nLine );
auto it = std::find_if(pBreaks->begin(), pBreaks->end(),
[&nLine](const sal_uInt16 b) { return b <= nLine; });
if (it != pBreaks->end() && *it == nLine)
return true;
pBreaks->insert( it, nLine );
// #38568: Set during runtime as well here BasicDebugFlags::Break
if( GetSbData()->pInst && GetSbData()->pInst->pRun )
......@@ -1518,17 +1513,12 @@ bool SbModule::ClearBP( sal_uInt16 nLine )
bool bRes = false;
if( pBreaks )
{
for( size_t i = 0; i < pBreaks->size(); i++ )
auto it = std::find_if(pBreaks->begin(), pBreaks->end(),
[&nLine](const sal_uInt16 b) { return b <= nLine; });
bRes = (it != pBreaks->end()) && (*it == nLine);
if (bRes)
{
sal_uInt16 b = pBreaks->operator[]( i );
if( b == nLine )
{
pBreaks->erase( pBreaks->begin() + i );
bRes = true;
break;
}
if( b < nLine )
break;
pBreaks->erase(it);
}
if( pBreaks->empty() )
{
......
......@@ -557,15 +557,13 @@ ErrCode call(
arguments->Get(i)->ResetFlag(SbxFlagBits::Reference);
//TODO: skipped for errors?!?
}
for (std::vector< UnmarshalData >::iterator i(data.unmarshal.begin());
i != data.unmarshal.end(); ++i)
for (auto& rUnmarshalData : data.unmarshal)
{
unmarshal(i->variable, i->buffer);
unmarshal(rUnmarshalData.variable, rUnmarshalData.buffer);
}
for (std::vector< StringData >::iterator i(data.unmarshalStrings.begin());
i != data.unmarshalStrings.end(); ++i)
for (const auto& rStringData : data.unmarshalStrings)
{
ErrCode e = unmarshalString(*i, result);
ErrCode e = unmarshalString(rStringData, result);
if (e != ERRCODE_NONE) {
return e;
}
......
......@@ -123,15 +123,13 @@ void SbxBase::AddFactory( SbxFactory* pFac )
void SbxBase::RemoveFactory( SbxFactory const * pFac )
{
SbxAppData& r = GetSbxData_Impl();
for (auto it = r.m_Factories.begin(); it != r.m_Factories.end(); ++it)
auto it = std::find_if(r.m_Factories.begin(), r.m_Factories.end(),
[&pFac](const std::unique_ptr<SbxFactory>& rxFactory) { return rxFactory.get() == pFac; });
if (it != r.m_Factories.end())
{
if ((*it).get() == pFac)
{
std::unique_ptr<SbxFactory> tmp(std::move(*it));
r.m_Factories.erase( it );
(void)tmp.release();
break;
}
std::unique_ptr<SbxFactory> tmp(std::move(*it));
r.m_Factories.erase( it );
(void)tmp.release();
}
}
......
......@@ -157,10 +157,9 @@ RTTInfos::~RTTInfos() throw ()
SAL_INFO("bridges", "> freeing generated RTTI infos... <");
MutexGuard aGuard( _aMutex );
for ( t_string2PtrMap::const_iterator iPos( _allRTTI.begin() );
iPos != _allRTTI.end(); ++iPos )
for ( auto& rEntry : _allRTTI )
{
__type_info * pType = reinterpret_cast<__type_info*>(iPos->second);
__type_info * pType = reinterpret_cast<__type_info*>(rEntry.second);
pType->~__type_info(); // obsolete, but good style...
std::free( pType );
}
......@@ -375,10 +374,9 @@ ExceptionInfos::~ExceptionInfos() throw ()
SAL_INFO("bridges", "> freeing exception infos... <");
MutexGuard aGuard( _aMutex );
for ( t_string2PtrMap::const_iterator iPos( _allRaiseInfos.begin() );
iPos != _allRaiseInfos.end(); ++iPos )
for ( auto& rEntry : _allRaiseInfos )
{
delete reinterpret_cast<RaiseInfo*>(iPos->second);
delete reinterpret_cast<RaiseInfo*>(rEntry.second);
}
}
......
......@@ -181,11 +181,11 @@ VtableFactory::VtableFactory(): m_arena(
VtableFactory::~VtableFactory() {
{
osl::MutexGuard guard(m_mutex);
for (Map::iterator i(m_map.begin()); i != m_map.end(); ++i) {
for (sal_Int32 j = 0; j < i->second.count; ++j) {
freeBlock(i->second.blocks[j]);
for (auto& rEntry : m_map) {
for (sal_Int32 j = 0; j < rEntry.second.count; ++j) {
freeBlock(rEntry.second.blocks[j]);
}
delete[] i->second.blocks;
delete[] rEntry.second.blocks;
}
}
rtl_arena_destroy(m_arena);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment