summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorArkadiy Illarionov <qarkai@gmail.com>2018-08-15 21:32:27 +0300
committerNoel Grandin <noel.grandin@collabora.co.uk>2018-08-20 17:12:11 +0200
commit0787ce8814e37972a0c968f60008d4e8722b6e27 (patch)
tree9d2803ebda8813e6b3f2bc2e6f8a74953b2931c1 /sc
parentd2c9c60fefb9687adbde4be61ed66a5123a2587f (diff)
Simplify containers iterations, tdf#96099 follow-up
Use range-based loop or replace with std::any_of, std::find and std::find_if where applicable. Change-Id: I2f80788c49d56094c29b102eb96a7a7c079567c6 Reviewed-on: https://gerrit.libreoffice.org/59143 Tested-by: Jenkins Reviewed-by: Michael Meeks <michael.meeks@collabora.com> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sc')
-rw-r--r--sc/source/core/data/documen2.cxx4
-rw-r--r--sc/source/core/tool/rangelst.cxx49
-rw-r--r--sc/source/filter/ftools/fapihelper.cxx8
-rw-r--r--sc/source/filter/oox/formulaparser.cxx7
-rw-r--r--sc/source/filter/oox/pivotcachebuffer.cxx8
-rw-r--r--sc/source/ui/miscdlgs/conflictsdlg.cxx107
6 files changed, 69 insertions, 114 deletions
diff --git a/sc/source/core/data/documen2.cxx b/sc/source/core/data/documen2.cxx
index 6cba2a5eda6b..4dde125e4dba 100644
--- a/sc/source/core/data/documen2.cxx
+++ b/sc/source/core/data/documen2.cxx
@@ -128,8 +128,8 @@ struct ScLookupCacheMapImpl
private:
void freeCaches()
{
- for (auto it( aCacheMap.begin()); it != aCacheMap.end(); ++it)
- delete (*it).second;
+ for (auto& aCacheItem : aCacheMap)
+ delete aCacheItem.second;
}
};
diff --git a/sc/source/core/tool/rangelst.cxx b/sc/source/core/tool/rangelst.cxx
index 394d5d5f09f9..b20efcf1952b 100644
--- a/sc/source/core/tool/rangelst.cxx
+++ b/sc/source/core/tool/rangelst.cxx
@@ -390,10 +390,8 @@ bool ScRangeList::UpdateReference(
if(maRanges.empty())
return true;
- auto itr = maRanges.begin(), itrEnd = maRanges.end();
- for (; itr != itrEnd; ++itr)
+ for (auto& rR : maRanges)
{
- ScRange& rR = *itr;
SCCOL theCol1;
SCROW theRow1;
SCTAB theTab1;
@@ -430,10 +428,8 @@ bool ScRangeList::UpdateReference(
void ScRangeList::InsertRow( SCTAB nTab, SCCOL nColStart, SCCOL nColEnd, SCROW nRowPos, SCSIZE nSize )
{
std::vector<ScRange> aNewRanges;
- for(auto it = maRanges.begin(), itEnd = maRanges.end(); it != itEnd;
- ++it)
+ for(auto & rRange : maRanges)
{
- ScRange & rRange = *it;
if(rRange.aStart.Tab() <= nTab && rRange.aEnd.Tab() >= nTab)
{
if(rRange.aEnd.Row() == nRowPos - 1 && (nColStart <= rRange.aEnd.Col() || nColEnd >= rRange.aStart.Col()))
@@ -450,23 +446,20 @@ void ScRangeList::InsertRow( SCTAB nTab, SCCOL nColStart, SCCOL nColEnd, SCROW n
}
}
- for(auto it = aNewRanges.cbegin(), itEnd = aNewRanges.cend();
- it != itEnd; ++it)
+ for(auto & rRange : aNewRanges)
{
- if(!it->IsValid())
+ if(!rRange.IsValid())
continue;
- Join(*it);
+ Join(rRange);
}
}
void ScRangeList::InsertCol( SCTAB nTab, SCROW nRowStart, SCROW nRowEnd, SCCOL nColPos, SCSIZE nSize )
{
std::vector<ScRange> aNewRanges;
- for(auto it = maRanges.begin(), itEnd = maRanges.end(); it != itEnd;
- ++it)
+ for(auto & rRange : maRanges)
{
- ScRange & rRange = *it;
if(rRange.aStart.Tab() <= nTab && rRange.aEnd.Tab() >= nTab)
{
if(rRange.aEnd.Col() == nColPos - 1 && (nRowStart <= rRange.aEnd.Row() || nRowEnd >= rRange.aStart.Row()))
@@ -481,13 +474,12 @@ void ScRangeList::InsertCol( SCTAB nTab, SCROW nRowStart, SCROW nRowEnd, SCCOL n
}
}
- for(std::vector<ScRange>::const_iterator it = aNewRanges.begin(), itEnd = aNewRanges.end();
- it != itEnd; ++it)
+ for(auto & rRange : aNewRanges)
{
- if(!it->IsValid())
+ if(!rRange.IsValid())
continue;
- Join(*it);
+ Join(rRange);
}
}
@@ -934,13 +926,13 @@ bool ScRangeList::DeleteArea( SCCOL nCol1, SCROW nRow1, SCTAB nTab1,
std::vector<ScRange> aNewRanges;
- for(auto itr = maRanges.begin(); itr != maRanges.end(); ++itr)
+ for(auto & rRange : maRanges)
{
// we have two basic cases here:
// 1. Delete area and pRange intersect
// 2. Delete area and pRange are not intersecting
// checking for 2 and if true skip this range
- if(!itr->Intersects(aRange))
+ if(!rRange.Intersects(aRange))
continue;
// We get between 1 and 4 ranges from the difference of the first with the second
@@ -951,7 +943,7 @@ bool ScRangeList::DeleteArea( SCCOL nCol1, SCROW nRow1, SCTAB nTab1,
// getting exactly one range is the simple case
// r.aStart.X() <= p.aStart.X() && r.aEnd.X() >= p.aEnd.X()
// && ( r.aStart.Y() <= p.aStart.Y() || r.aEnd.Y() >= r.aEnd.Y() )
- if(handleOneRange( aRange, *itr ))
+ if(handleOneRange( aRange, rRange ))
{
bChanged = true;
continue;
@@ -959,7 +951,7 @@ bool ScRangeList::DeleteArea( SCCOL nCol1, SCROW nRow1, SCTAB nTab1,
// getting two ranges
// r.aStart.X()
- else if(handleTwoRanges( aRange, *itr, aNewRanges ))
+ else if(handleTwoRanges( aRange, rRange, aNewRanges ))
{
bChanged = true;
continue;
@@ -971,7 +963,7 @@ bool ScRangeList::DeleteArea( SCCOL nCol1, SCROW nRow1, SCTAB nTab1,
// or
// r.aStart.X() <= p.aStart.X() && r.aEnd.X() < p.aEnd.X()
// && r.aStart.Y() > p.aStart.Y() && r.aEnd.Y() < p.aEnd.Y()
- else if(handleThreeRanges( aRange, *itr, aNewRanges ))
+ else if(handleThreeRanges( aRange, rRange, aNewRanges ))
{
bChanged = true;
continue;
@@ -980,14 +972,14 @@ bool ScRangeList::DeleteArea( SCCOL nCol1, SCROW nRow1, SCTAB nTab1,
// getting 4 ranges
// r.aStart.X() > p.aStart.X() && r.aEnd().X() < p.aEnd.X()
// && r.aStart.Y() > p.aStart.Y() && r.aEnd().Y() < p.aEnd.Y()
- else if(handleFourRanges( aRange, *itr, aNewRanges ))
+ else if(handleFourRanges( aRange, rRange, aNewRanges ))
{
bChanged = true;
continue;
}
}
- for(vector<ScRange>::iterator itr = aNewRanges.begin(); itr != aNewRanges.end(); ++itr)
- Join( *itr);
+ for(auto & rRange : aNewRanges)
+ Join(rRange);
return bChanged;
}
@@ -1134,15 +1126,14 @@ ScAddress ScRangeList::GetTopLeftCorner() const
ScRangeList ScRangeList::GetIntersectedRange(const ScRange& rRange) const
{
ScRangeList aReturn;
- for(auto itr = maRanges.cbegin(), itrEnd = maRanges.cend();
- itr != itrEnd; ++itr)
+ for(auto& rR : maRanges)
{
- if(itr->Intersects(rRange))
+ if(rR.Intersects(rRange))
{
SCCOL nColStart1, nColEnd1, nColStart2, nColEnd2;
SCROW nRowStart1, nRowEnd1, nRowStart2, nRowEnd2;
SCTAB nTabStart1, nTabEnd1, nTabStart2, nTabEnd2;
- itr->GetVars(nColStart1, nRowStart1, nTabStart1,
+ rR.GetVars(nColStart1, nRowStart1, nTabStart1,
nColEnd1, nRowEnd1, nTabEnd1);
rRange.GetVars(nColStart2, nRowStart2, nTabStart2,
nColEnd2, nRowEnd2, nTabEnd2);
diff --git a/sc/source/filter/ftools/fapihelper.cxx b/sc/source/filter/ftools/fapihelper.cxx
index dab3b5e112f3..146af75aaca5 100644
--- a/sc/source/filter/ftools/fapihelper.cxx
+++ b/sc/source/filter/ftools/fapihelper.cxx
@@ -296,11 +296,11 @@ ScfPropSetHelper::ScfPropSetHelper( const sal_Char* const* ppcPropNames ) :
// fill the property name sequence and store original sort order
sal_Int32 nSeqIdx = 0;
- for( auto aIt = aPropNameVec.cbegin(), aEnd = aPropNameVec.cend();
- aIt != aEnd; ++aIt, ++nSeqIdx )
+ for( auto& aPropName : aPropNameVec )
{
- maNameSeq[ nSeqIdx ] = aIt->first;
- maNameOrder[ aIt->second ] = nSeqIdx;
+ maNameSeq[ nSeqIdx ] = aPropName.first;
+ maNameOrder[ aPropName.second ] = nSeqIdx;
+ ++nSeqIdx;
}
}
diff --git a/sc/source/filter/oox/formulaparser.cxx b/sc/source/filter/oox/formulaparser.cxx
index a6d3c0f7a18d..083c1b594aa8 100644
--- a/sc/source/filter/oox/formulaparser.cxx
+++ b/sc/source/filter/oox/formulaparser.cxx
@@ -620,8 +620,11 @@ ApiTokenSequence FormulaParserImpl::finalizeImport()
if( aTokens.hasElements() )
{
ApiToken* pToken = aTokens.getArray();
- for( auto aIt = maTokenIndexes.cbegin(), aEnd = maTokenIndexes.cend(); aIt != aEnd; ++aIt, ++pToken )
- *pToken = maTokenStorage[ *aIt ];
+ for( auto& tokenIndex : maTokenIndexes )
+ {
+ *pToken = maTokenStorage[ tokenIndex ];
+ ++pToken;
+ }
}
return finalizeTokenArray( aTokens );
}
diff --git a/sc/source/filter/oox/pivotcachebuffer.cxx b/sc/source/filter/oox/pivotcachebuffer.cxx
index 2a46606e0111..95f4addfa10c 100644
--- a/sc/source/filter/oox/pivotcachebuffer.cxx
+++ b/sc/source/filter/oox/pivotcachebuffer.cxx
@@ -688,8 +688,8 @@ OUString PivotCacheField::createParentGroupField( const Reference< XDataPilotFie
names as they are already grouped is used here to resolve the
item names. */
::std::vector< OUString > aMembers;
- for( auto aBeg2 = aIt->begin(), aIt2 = aBeg2, aEnd2 = aIt->end(); aIt2 != aEnd2; ++aIt2 )
- if( const PivotCacheGroupItem* pName = ContainerHelper::getVectorElement( orItemNames, *aIt2 ) )
+ for( auto i : *aIt )
+ if( const PivotCacheGroupItem* pName = ContainerHelper::getVectorElement( orItemNames, i ) )
if( ::std::find( aMembers.begin(), aMembers.end(), pName->maGroupName ) == aMembers.end() )
aMembers.push_back( pName->maGroupName );
@@ -756,8 +756,8 @@ OUString PivotCacheField::createParentGroupField( const Reference< XDataPilotFie
aPropSet.setProperty( PROP_GroupInfo, aGroupInfo );
}
// replace original item names in passed vector with group name
- for( auto aIt2 = aIt->begin(), aEnd2 = aIt->end(); aIt2 != aEnd2; ++aIt2 )
- if( PivotCacheGroupItem* pName = ContainerHelper::getVectorElementAccess( orItemNames, *aIt2 ) )
+ for( auto i : *aIt )
+ if( PivotCacheGroupItem* pName = ContainerHelper::getVectorElementAccess( orItemNames, i ) )
pName->maGroupName = aGroupName;
}
}
diff --git a/sc/source/ui/miscdlgs/conflictsdlg.cxx b/sc/source/ui/miscdlgs/conflictsdlg.cxx
index 0664058641bb..28ba0dfdf368 100644
--- a/sc/source/ui/miscdlgs/conflictsdlg.cxx
+++ b/sc/source/ui/miscdlgs/conflictsdlg.cxx
@@ -30,71 +30,47 @@
bool ScConflictsListEntry::HasSharedAction( sal_uLong nSharedAction ) const
{
auto aEnd = maSharedActions.cend();
- for ( auto aItr = maSharedActions.cbegin(); aItr != aEnd; ++aItr )
- {
- if ( *aItr == nSharedAction )
- {
- return true;
- }
- }
+ auto aItr = std::find(maSharedActions.cbegin(), aEnd, nSharedAction);
- return false;
+ return aItr != aEnd;
}
bool ScConflictsListEntry::HasOwnAction( sal_uLong nOwnAction ) const
{
auto aEnd = maOwnActions.cend();
- for ( auto aItr = maOwnActions.cbegin(); aItr != aEnd; ++aItr )
- {
- if ( *aItr == nOwnAction )
- {
- return true;
- }
- }
+ auto aItr = std::find(maOwnActions.cbegin(), aEnd, nOwnAction);
- return false;
+ return aItr != aEnd;
}
// class ScConflictsListHelper
bool ScConflictsListHelper::HasOwnAction( ScConflictsList& rConflictsList, sal_uLong nOwnAction )
{
- ScConflictsList::const_iterator aEnd = rConflictsList.end();
- for ( ScConflictsList::const_iterator aItr = rConflictsList.begin(); aItr != aEnd; ++aItr )
- {
- if ( aItr->HasOwnAction( nOwnAction ) )
- {
- return true;
- }
- }
-
- return false;
+ return std::any_of(rConflictsList.begin(), rConflictsList.end(),
+ [nOwnAction](ScConflictsListEntry& rConflict) { return rConflict.HasOwnAction( nOwnAction ); });
}
ScConflictsListEntry* ScConflictsListHelper::GetSharedActionEntry( ScConflictsList& rConflictsList, sal_uLong nSharedAction )
{
- ScConflictsList::iterator aEnd = rConflictsList.end();
- for ( ScConflictsList::iterator aItr = rConflictsList.begin(); aItr != aEnd; ++aItr )
- {
- if ( aItr->HasSharedAction( nSharedAction ) )
- {
- return &(*aItr);
- }
- }
+ auto aEnd = rConflictsList.end();
+ auto aItr = std::find_if(rConflictsList.begin(), aEnd,
+ [nSharedAction](ScConflictsListEntry& rConflict) { return rConflict.HasSharedAction( nSharedAction ); });
+
+ if (aItr != aEnd)
+ return &(*aItr);
return nullptr;
}
ScConflictsListEntry* ScConflictsListHelper::GetOwnActionEntry( ScConflictsList& rConflictsList, sal_uLong nOwnAction )
{
- ScConflictsList::iterator aEnd = rConflictsList.end();
- for ( ScConflictsList::iterator aItr = rConflictsList.begin(); aItr != aEnd; ++aItr )
- {
- if ( aItr->HasOwnAction( nOwnAction ) )
- {
- return &(*aItr);
- }
- }
+ auto aEnd = rConflictsList.end();
+ auto aItr = std::find_if(rConflictsList.begin(), aEnd,
+ [nOwnAction](ScConflictsListEntry& rConflict) { return rConflict.HasOwnAction( nOwnAction ); });
+
+ if (aItr != aEnd)
+ return &(*aItr);
return nullptr;
}
@@ -164,26 +140,15 @@ bool ScConflictsFinder::DoActionsIntersect( const ScChangeAction* pAction1, cons
ScConflictsListEntry* ScConflictsFinder::GetIntersectingEntry( const ScChangeAction* pAction ) const
{
- ScConflictsList::iterator aEnd = mrConflictsList.end();
- for ( ScConflictsList::iterator aItr = mrConflictsList.begin(); aItr != aEnd; ++aItr )
+ auto doActionsIntersect = [this, pAction](const sal_uLong& aAction) { return DoActionsIntersect( mpTrack->GetAction( aAction ), pAction ); };
+
+ for ( auto& rConflict : mrConflictsList )
{
- auto aEndShared = aItr->maSharedActions.cend();
- for ( auto aItrShared = aItr->maSharedActions.cbegin(); aItrShared != aEndShared; ++aItrShared )
- {
- if ( DoActionsIntersect( mpTrack->GetAction( *aItrShared ), pAction ) )
- {
- return &(*aItr);
- }
- }
+ if (std::any_of( rConflict.maSharedActions.cbegin(), rConflict.maSharedActions.cend(), doActionsIntersect ))
+ return &rConflict;
- auto aEndOwn = aItr->maOwnActions.cend();
- for ( auto aItrOwn = aItr->maOwnActions.cbegin(); aItrOwn != aEndOwn; ++aItrOwn )
- {
- if ( DoActionsIntersect( mpTrack->GetAction( *aItrOwn ), pAction ) )
- {
- return &(*aItr);
- }
- }
+ if (std::any_of( rConflict.maOwnActions.cbegin(), rConflict.maOwnActions.cend(), doActionsIntersect ))
+ return &rConflict;
}
return nullptr;
@@ -209,10 +174,9 @@ ScConflictsListEntry* ScConflictsFinder::GetEntry( sal_uLong nSharedAction, cons
// try to get a list entry for which any of the own actions intersects with
// any other action of this entry
- auto aEnd = rOwnActions.cend();
- for ( auto aItr = rOwnActions.cbegin(); aItr != aEnd; ++aItr )
+ for ( auto& rOwnAction : rOwnActions )
{
- pEntry = GetIntersectingEntry( mpTrack->GetAction( *aItr ) );
+ pEntry = GetIntersectingEntry( mpTrack->GetAction( rOwnAction ) );
if ( pEntry )
{
pEntry->maSharedActions.push_back( nSharedAction );
@@ -253,12 +217,11 @@ bool ScConflictsFinder::Find()
if ( aOwnActions.size() )
{
ScConflictsListEntry* pEntry = GetEntry( pSharedAction->GetActionNumber(), aOwnActions );
- auto aEnd = aOwnActions.end();
- for ( auto aItr = aOwnActions.begin(); aItr != aEnd; ++aItr )
+ for ( auto& aOwnAction : aOwnActions )
{
- if ( pEntry && !ScConflictsListHelper::HasOwnAction( mrConflictsList, *aItr ) )
+ if ( pEntry && !ScConflictsListHelper::HasOwnAction( mrConflictsList, aOwnAction ) )
{
- pEntry->maOwnActions.push_back( *aItr );
+ pEntry->maOwnActions.push_back( aOwnAction );
}
}
bReturn = true;
@@ -674,10 +637,9 @@ void ScConflictsDlg::UpdateView()
pRootUserData->pData = static_cast< void* >( pConflictEntry );
SvTreeListEntry* pRootEntry = m_pLbConflicts->InsertEntry( GetConflictString( *aItr ), pRootUserData );
- auto aEndShared = aItr->maSharedActions.cend();
- for ( auto aItrShared = aItr->maSharedActions.cbegin(); aItrShared != aEndShared; ++aItrShared )
+ for ( auto& aSharedAction : aItr->maSharedActions )
{
- ScChangeAction* pAction = mpSharedTrack ? mpSharedTrack->GetAction(*aItrShared) : nullptr;
+ ScChangeAction* pAction = mpSharedTrack ? mpSharedTrack->GetAction(aSharedAction) : nullptr;
if ( pAction )
{
// only display shared top content entries
@@ -695,10 +657,9 @@ void ScConflictsDlg::UpdateView()
}
}
- auto aEndOwn = aItr->maOwnActions.cend();
- for ( auto aItrOwn = aItr->maOwnActions.cbegin(); aItrOwn != aEndOwn; ++aItrOwn )
+ for ( auto& aOwnAction : aItr->maOwnActions )
{
- ScChangeAction* pAction = mpOwnTrack ? mpOwnTrack->GetAction(*aItrOwn) : nullptr;
+ ScChangeAction* pAction = mpOwnTrack ? mpOwnTrack->GetAction(aOwnAction) : nullptr;
if ( pAction )
{
// only display own top content entries