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