summaryrefslogtreecommitdiff
path: root/basic
diff options
context:
space:
mode:
authorArkadiy Illarionov <qarkai@gmail.com>2019-03-13 21:11:09 +0300
committerNoel Grandin <noel.grandin@collabora.co.uk>2019-03-16 20:16:46 +0100
commit10a48c737d347bcce765c8fbe009bc1dd0bb0c4d (patch)
tree6688e9ca36964bcbf589e60452a331b49a81bfde /basic
parentbb9728bbf9bb29ef2b6ca582a382f66e9adf2623 (diff)
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: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'basic')
-rw-r--r--basic/source/basmgr/basicmanagerrepository.cxx36
-rw-r--r--basic/source/classes/sb.cxx5
-rw-r--r--basic/source/classes/sbunoobj.cxx10
-rw-r--r--basic/source/classes/sbxmod.cxx30
-rw-r--r--basic/source/runtime/dllmgr-x86.cxx10
-rw-r--r--basic/source/sbx/sbxbase.cxx14
6 files changed, 38 insertions, 67 deletions
diff --git a/basic/source/basmgr/basicmanagerrepository.cxx b/basic/source/basmgr/basicmanagerrepository.cxx
index 1cc6eab188cf..c282eabacbcd 100644
--- a/basic/source/basmgr/basicmanagerrepository.cxx
+++ b/basic/source/basmgr/basicmanagerrepository.cxx
@@ -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 );
}
}
diff --git a/basic/source/classes/sb.cxx b/basic/source/classes/sb.cxx
index 4d92e3348704..8cce1979c6ec 100644
--- a/basic/source/classes/sb.cxx
+++ b/basic/source/classes/sb.cxx
@@ -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 );
}
}
diff --git a/basic/source/classes/sbunoobj.cxx b/basic/source/classes/sbunoobj.cxx
index e6c1a3e1c06b..666fe69673f3 100644
--- a/basic/source/classes/sbunoobj.cxx
+++ b/basic/source/classes/sbunoobj.cxx
@@ -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 )
diff --git a/basic/source/classes/sbxmod.cxx b/basic/source/classes/sbxmod.cxx
index 7e65e2e588a2..cdff9edfc162 100644
--- a/basic/source/classes/sbxmod.cxx
+++ b/basic/source/classes/sbxmod.cxx
@@ -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() )
{
diff --git a/basic/source/runtime/dllmgr-x86.cxx b/basic/source/runtime/dllmgr-x86.cxx
index fc5b91e3300d..347f9ad4067d 100644
--- a/basic/source/runtime/dllmgr-x86.cxx
+++ b/basic/source/runtime/dllmgr-x86.cxx
@@ -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;
}
diff --git a/basic/source/sbx/sbxbase.cxx b/basic/source/sbx/sbxbase.cxx
index 80508a155826..22dbb951c145 100644
--- a/basic/source/sbx/sbxbase.cxx
+++ b/basic/source/sbx/sbxbase.cxx
@@ -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();
}
}