[Libreoffice-commits] .: svtools/source

Joseph Powers jpowers at kemper.freedesktop.org
Sun Aug 21 21:29:47 PDT 2011


 svtools/source/graphic/grfcache.cxx |  100 +++++++++++++++++++++---------------
 svtools/source/graphic/grfcache.hxx |    4 +
 2 files changed, 64 insertions(+), 40 deletions(-)

New commits:
commit b737e34d1c86938fc2e2704531b89da45fd91fee
Author: Joseph Powers <jpowers27 at cox.net>
Date:   Sun Aug 21 20:56:56 2011 -0700

    Replace List with std::list< GraphicCacheEntry* >

diff --git a/svtools/source/graphic/grfcache.cxx b/svtools/source/graphic/grfcache.cxx
index e4e996e..55d4063 100644
--- a/svtools/source/graphic/grfcache.cxx
+++ b/svtools/source/graphic/grfcache.cxx
@@ -577,41 +577,54 @@ GraphicCache::GraphicCache( GraphicManager& rMgr, sal_uLong nDisplayCacheSize, s
 
 GraphicCache::~GraphicCache()
 {
-    DBG_ASSERT( !maGraphicCache.Count(), "GraphicCache::~GraphicCache(): there are some GraphicObjects in cache" );
+    DBG_ASSERT( !maGraphicCache.size(), "GraphicCache::~GraphicCache(): there are some GraphicObjects in cache" );
     DBG_ASSERT( !maDisplayCache.Count(), "GraphicCache::~GraphicCache(): there are some GraphicObjects in display cache" );
 }
 
 // -----------------------------------------------------------------------------
 
-void GraphicCache::AddGraphicObject( const GraphicObject& rObj, Graphic& rSubstitute,
-                                     const ByteString* pID, const GraphicObject* pCopyObj )
+void GraphicCache::AddGraphicObject(
+    const GraphicObject& rObj,
+    Graphic& rSubstitute,
+    const ByteString* pID,
+    const GraphicObject* pCopyObj
+)
 {
     sal_Bool bInserted = sal_False;
 
-    if( !rObj.IsSwappedOut() &&
-        ( pID || ( pCopyObj && ( pCopyObj->GetType() != GRAPHIC_NONE ) ) || ( rObj.GetType() != GRAPHIC_NONE ) ) )
+    if(  !rObj.IsSwappedOut()
+      && (  pID
+         || (    pCopyObj
+            && ( pCopyObj->GetType() != GRAPHIC_NONE )
+            )
+         || ( rObj.GetType() != GRAPHIC_NONE )
+         )
+      )
     {
-        if( pCopyObj )
+        if( pCopyObj
+          && !maGraphicCache.empty()
+        )
         {
-            GraphicCacheEntry* pEntry = static_cast< GraphicCacheEntry* >( maGraphicCache.First() );
-
-            while( !bInserted && pEntry )
+            GraphicCacheEntryList::iterator it = maGraphicCache.begin();
+            while(  !bInserted
+                 && ( it != maGraphicCache.end() )
+                 )
             {
-                if( pEntry->HasGraphicObjectReference( *pCopyObj ) )
+                if( (*it)->HasGraphicObjectReference( *pCopyObj ) )
                 {
-                    pEntry->AddGraphicObjectReference( rObj, rSubstitute );
+                    (*it)->AddGraphicObjectReference( rObj, rSubstitute );
                     bInserted = sal_True;
                 }
                 else
                 {
-                    pEntry = static_cast< GraphicCacheEntry* >( maGraphicCache.Next() );
+                    ++it;
                 }
             }
         }
 
         if( !bInserted )
         {
-            GraphicCacheEntry* pEntry = static_cast< GraphicCacheEntry* >( maGraphicCache.First() );
+            GraphicCacheEntryList::iterator it = maGraphicCache.begin();
             ::std::auto_ptr< GraphicID > apID;
 
             if( !pID )
@@ -619,35 +632,38 @@ void GraphicCache::AddGraphicObject( const GraphicObject& rObj, Graphic& rSubsti
                 apID.reset( new GraphicID( rObj ) );
             }
 
-            while( !bInserted && pEntry )
+            while(  !bInserted
+                 && ( it != maGraphicCache.end() )
+                 )
             {
-                const GraphicID& rEntryID = pEntry->GetID();
+                const GraphicID& rEntryID = (*it)->GetID();
 
                 if( pID )
                 {
                     if( rEntryID.GetIDString() == *pID )
                     {
-                        pEntry->TryToSwapIn();
+                        (*it)->TryToSwapIn();
 
                         // since pEntry->TryToSwapIn can modify our current list, we have to
                         // iterate from beginning to add a reference to the appropriate
                         // CacheEntry object; after this, quickly jump out of the outer iteration
-                        for( pEntry = static_cast< GraphicCacheEntry* >( maGraphicCache.First() );
-                             !bInserted && pEntry;
-                             pEntry = static_cast< GraphicCacheEntry* >( maGraphicCache.Next() ) )
+                        for( GraphicCacheEntryList::iterator jt = maGraphicCache.begin();
+                             !bInserted && jt != maGraphicCache.end();
+                             ++jt
+                        )
                         {
-                            const GraphicID& rID = pEntry->GetID();
+                            const GraphicID& rID = (*jt)->GetID();
 
                             if( rID.GetIDString() == *pID )
                             {
-                                pEntry->AddGraphicObjectReference( rObj, rSubstitute );
+                                (*jt)->AddGraphicObjectReference( rObj, rSubstitute );
                                 bInserted = sal_True;
                             }
                         }
 
                         if( !bInserted )
                         {
-                            maGraphicCache.Insert( new GraphicCacheEntry( rObj ), LIST_APPEND );
+                            maGraphicCache.push_back( new GraphicCacheEntry( rObj ) );
                             bInserted = sal_True;
                         }
                     }
@@ -656,19 +672,19 @@ void GraphicCache::AddGraphicObject( const GraphicObject& rObj, Graphic& rSubsti
                 {
                     if( rEntryID == *apID )
                     {
-                        pEntry->AddGraphicObjectReference( rObj, rSubstitute );
+                        (*it)->AddGraphicObjectReference( rObj, rSubstitute );
                         bInserted = sal_True;
                     }
                 }
 
                 if( !bInserted )
-                    pEntry = static_cast< GraphicCacheEntry* >( maGraphicCache.Next() );
+                    ++it;
             }
         }
     }
 
     if( !bInserted )
-        maGraphicCache.Insert( new GraphicCacheEntry( rObj ), LIST_APPEND );
+        maGraphicCache.push_back( new GraphicCacheEntry( rObj ) );
 }
 
 // -----------------------------------------------------------------------------
@@ -676,16 +692,18 @@ void GraphicCache::AddGraphicObject( const GraphicObject& rObj, Graphic& rSubsti
 void GraphicCache::ReleaseGraphicObject( const GraphicObject& rObj )
 {
     // Release cached object
-    GraphicCacheEntry*  pEntry = (GraphicCacheEntry*) maGraphicCache.First();
-    bool                bRemoved = false;
+    bool    bRemoved = false;
 
-    while( !bRemoved && pEntry )
-    {
-        bRemoved = pEntry->ReleaseGraphicObjectReference( rObj );
+    for(
+        GraphicCacheEntryList::iterator it = maGraphicCache.begin();
+        !bRemoved && it != maGraphicCache.end();
+        ++it
+    ) {
+        bRemoved = (*it)->ReleaseGraphicObjectReference( rObj );
 
         if( bRemoved )
         {
-            if( 0 == pEntry->GetGraphicObjectReferenceCount() )
+            if( 0 == (*it)->GetGraphicObjectReferenceCount() )
             {
                 // if graphic cache entry has no more references,
                 // the corresponding display cache object can be removed
@@ -693,7 +711,7 @@ void GraphicCache::ReleaseGraphicObject( const GraphicObject& rObj )
 
                 while( pDisplayEntry )
                 {
-                    if( pDisplayEntry->GetReferencedCacheEntry() == pEntry )
+                    if( pDisplayEntry->GetReferencedCacheEntry() == *it )
                     {
                         mnUsedDisplaySize -= pDisplayEntry->GetCacheSize();
                         maDisplayCache.Remove( pDisplayEntry );
@@ -705,12 +723,10 @@ void GraphicCache::ReleaseGraphicObject( const GraphicObject& rObj )
                 }
 
                 // delete graphic cache entry
-                maGraphicCache.Remove( (void*) pEntry );
-                delete pEntry;
+                delete *it;
+                it = maGraphicCache.erase( it );
             }
         }
-        else
-            pEntry = (GraphicCacheEntry*) maGraphicCache.Next();
     }
 
     DBG_ASSERT( bRemoved, "GraphicCache::ReleaseGraphicObject(...): GraphicObject not found in cache" );
@@ -1013,9 +1029,15 @@ GraphicCacheEntry* GraphicCache::ImplGetCacheEntry( const GraphicObject& rObj )
 {
     GraphicCacheEntry* pRet = NULL;
 
-    for( void* pObj = maGraphicCache.First(); !pRet && pObj; pObj = maGraphicCache.Next() )
-        if( ( (GraphicCacheEntry*) pObj )->HasGraphicObjectReference( rObj ) )
-            pRet = (GraphicCacheEntry*) pObj;
+    for(
+        GraphicCacheEntryList::iterator it = maGraphicCache.begin();
+        !pRet && it != maGraphicCache.end();
+        ++it
+    ) {
+        if( (*it)->HasGraphicObjectReference( rObj ) ) {
+            pRet = *it;
+        }
+    }
 
     return pRet;
 }
diff --git a/svtools/source/graphic/grfcache.hxx b/svtools/source/graphic/grfcache.hxx
index 52f9c58..edc1aa6 100644
--- a/svtools/source/graphic/grfcache.hxx
+++ b/svtools/source/graphic/grfcache.hxx
@@ -32,6 +32,7 @@
 #include <vcl/graph.hxx>
 #include <vcl/timer.hxx>
 #include <svtools/grfmgr.hxx>
+#include <list>
 
 // -----------------------
 // - GraphicManagerCache -
@@ -42,10 +43,11 @@ class GraphicCacheEntry;
 class GraphicCache
 {
 private:
+    typedef std::list< GraphicCacheEntry* > GraphicCacheEntryList;
 
     GraphicManager&         mrMgr;
     Timer                   maReleaseTimer;
-    List                    maGraphicCache;
+    GraphicCacheEntryList   maGraphicCache;
     List                    maDisplayCache;
     sal_uLong               mnReleaseTimeoutSeconds;
     sal_uLong               mnMaxDisplaySize;


More information about the Libreoffice-commits mailing list