[Libreoffice-commits] core.git: canvas/source

Daniel Robertson danlrobertson89 at gmail.com
Fri Sep 4 16:16:52 PDT 2015


 canvas/source/tools/pagemanager.cxx |   46 ++++++++++++------------------------
 1 file changed, 16 insertions(+), 30 deletions(-)

New commits:
commit cf9fbdb379e2935677a73ced513d7faf855c299c
Author: Daniel Robertson <danlrobertson89 at gmail.com>
Date:   Sat Aug 29 21:19:05 2015 -0400

    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 at libreoffice.org>
    Reviewed-by: Thorsten Behrens <Thorsten.Behrens at CIB.de>

diff --git a/canvas/source/tools/pagemanager.cxx b/canvas/source/tools/pagemanager.cxx
index f7faee0..46c5716 100644
--- a/canvas/source/tools/pagemanager.cxx
+++ b/canvas/source/tools/pagemanager.cxx
@@ -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 (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( *aCurr && !( ( *aCurr )->isNaked() ) )
                 {
-                    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());
-                        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);
             }
+            // this does not erase the candidate,
+            // but makes it 'naked'...
+            if( aCurrMax != aEnd )
+                ( *aCurrMax )->free( *aCurrMax );
             else
                 break;
         }


More information about the Libreoffice-commits mailing list