basctl/source/basicide/baside2b.cxx                |   29 +-----------
 basctl/source/basicide/bastypes.cxx                |    6 --
 basctl/source/basicide/breakpoint.cxx              |   25 ++++------
 basegfx/source/polygon/b3dpolygon.cxx              |   48 ++++++---------------
 basegfx/test/boxclipper.cxx                        |    4 -
 basic/source/basmgr/basicmanagerrepository.cxx     |   36 ++++++---------
 basic/source/classes/sb.cxx                        |    5 --
 basic/source/classes/sbunoobj.cxx                  |   10 ----
 basic/source/classes/sbxmod.cxx                    |   30 ++++---------
 basic/source/runtime/dllmgr-x86.cxx                |   10 +---
 basic/source/sbx/sbxbase.cxx                       |   14 ++----
 bridges/source/cpp_uno/msvc_win32_intel/except.cxx |   10 +---
 bridges/source/cpp_uno/shared/vtablefactory.cxx    |    8 +--
 13 files changed, 78 insertions(+), 157 deletions(-)

New commits:
commit 10a48c737d347bcce765c8fbe009bc1dd0bb0c4d
Author:     Arkadiy Illarionov <qar...@gmail.com>
AuthorDate: Wed Mar 13 21:11:09 2019 +0300
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Sat Mar 16 20:16:46 2019 +0100

    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.gran...@collabora.co.uk>

diff --git a/basctl/source/basicide/baside2b.cxx 
b/basctl/source/basicide/baside2b.cxx
index e1d526df52cf..728ac019d167 100644
--- a/basctl/source/basicide/baside2b.cxx
+++ b/basctl/source/basicide/baside2b.cxx
@@ -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
diff --git a/basctl/source/basicide/bastypes.cxx 
b/basctl/source/basicide/bastypes.cxx
index 5ffbfbfd302d..169ee1818bdf 100644
--- a/basctl/source/basicide/bastypes.cxx
+++ b/basctl/source/basicide/bastypes.cxx
@@ -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);
 }
diff --git a/basctl/source/basicide/breakpoint.cxx 
b/basctl/source/basicide/breakpoint.cxx
index 15d5139f6610..b70be0594579 100644
--- a/basctl/source/basicide/breakpoint.cxx
+++ b/basctl/source/basicide/breakpoint.cxx
@@ -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;
 }
 
diff --git a/basegfx/source/polygon/b3dpolygon.cxx 
b/basegfx/source/polygon/b3dpolygon.cxx
index 9817fb43f6fb..5d23be90562c 100644
--- a/basegfx/source/polygon/b3dpolygon.cxx
+++ b/basegfx/source/polygon/b3dpolygon.cxx
@@ -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);
diff --git a/basegfx/test/boxclipper.cxx b/basegfx/test/boxclipper.cxx
index 0987daf9d929..d7c7c094b962 100644
--- a/basegfx/test/boxclipper.cxx
+++ b/basegfx/test/boxclipper.cxx
@@ -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);
         }
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();
     }
 }
 
diff --git a/bridges/source/cpp_uno/msvc_win32_intel/except.cxx 
b/bridges/source/cpp_uno/msvc_win32_intel/except.cxx
index b706c1b343fc..4f761ef3ed20 100644
--- a/bridges/source/cpp_uno/msvc_win32_intel/except.cxx
+++ b/bridges/source/cpp_uno/msvc_win32_intel/except.cxx
@@ -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);
     }
 }
 
diff --git a/bridges/source/cpp_uno/shared/vtablefactory.cxx 
b/bridges/source/cpp_uno/shared/vtablefactory.cxx
index 4789b0341ebd..a40e9e08b53d 100644
--- a/bridges/source/cpp_uno/shared/vtablefactory.cxx
+++ b/bridges/source/cpp_uno/shared/vtablefactory.cxx
@@ -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);
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to