canvas: simplify PageManager::nakedFragment loops

Convert while loops and break statements in PageManager::nakedFragment
into for loops

Change-Id: I671f4eea140f26c2f451d54911d017325084bd08
Reviewed-on: https://gerrit.libreoffice.org/18138
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Thorsten Behrens <Thorsten.Behrens@CIB.de>
This commit is contained in:
Daniel Robertson 2015-08-29 21:19:05 -04:00 committed by Thorsten Behrens
parent f8c14e81cb
commit cf9fbdb379

View File

@ -85,46 +85,32 @@ namespace canvas
// okay, one last chance is left, we try all available // okay, one last chance is left, we try all available
// pages again. maybe some other fragment was deleted // pages again. maybe some other fragment was deleted
// and we can exploit the space. // and we can exploit the space.
while(!(relocate(pFragment))) while( !( relocate( pFragment ) ) )
{ {
// no way, we need to free up some space... // no way, we need to free up some space...
// TODO(F1): this is a heuristic, could // TODO(F1): this is a heuristic, could
// be designed as a policy. // be designed as a policy.
const FragmentContainer_t::const_iterator aEnd(maFragments.end()); auto aEnd( maFragments.cend() );
FragmentContainer_t::const_iterator candidate(maFragments.begin()); auto aCurrMax( maFragments.end() );
while(candidate != aEnd) sal_uInt32 nCurrMaxArea = 0;
for( auto aCurr = maFragments.begin(); aCurr != aEnd; ++aCurr )
{ {
if(*candidate && !((*candidate)->isNaked())) if( *aCurr && !( ( *aCurr )->isNaked() ) )
break;
++candidate;
}
if (candidate != aEnd)
{
const ::basegfx::B2ISize& rSize((*candidate)->getSize());
sal_uInt32 nMaxArea(rSize.getX()*rSize.getY());
FragmentContainer_t::const_iterator it(candidate);
while(it != aEnd)
{ {
if (*it && !((*it)->isNaked())) const ::basegfx::B2ISize& rSize( ( *aCurr )->getSize() );
sal_uInt32 nArea( rSize.getX() * rSize.getY() );
if( nCurrMaxArea < nArea )
{ {
const ::basegfx::B2ISize& rCandidateSize((*it)->getSize()); aCurrMax = aCurr;
const sal_uInt32 nArea(rCandidateSize.getX()*rCandidateSize.getY()); nCurrMaxArea = nArea;
if(nArea > nMaxArea)
{
candidate=it;
nMaxArea=nArea;
}
} }
++it;
} }
// this does not erase the candidate,
// but makes it 'naked'...
(*candidate)->free(*candidate);
} }
// this does not erase the candidate,
// but makes it 'naked'...
if( aCurrMax != aEnd )
( *aCurrMax )->free( *aCurrMax );
else else
break; break;
} }