[Libreoffice-commits] .: 3 commits - sot/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Wed Sep 19 06:58:21 PDT 2012


 sot/source/sdstor/stgcache.cxx |  115 +++--------------------------------------
 sot/source/sdstor/stgcache.hxx |   15 +++--
 sot/source/sdstor/stgstrms.cxx |    5 -
 3 files changed, 21 insertions(+), 114 deletions(-)

New commits:
commit b7db3b8e1af45b27a0a7e33f7a7640af94dc96b8
Author: Michael Meeks <michael.meeks at suse.com>
Date:   Wed Sep 19 14:57:46 2012 +0100

    sot: remove un-used LRU cache
    
    Change-Id: I3d011a1aae47b6961b1cea2bf544af2c88bd611e

diff --git a/sot/source/sdstor/stgcache.cxx b/sot/source/sdstor/stgcache.cxx
index 74094f8..dd0b17f 100644
--- a/sot/source/sdstor/stgcache.cxx
+++ b/sot/source/sdstor/stgcache.cxx
@@ -45,10 +45,7 @@ StgPage::StgPage( StgCache* p, short n )
     bDirty = sal_False;
     nPage  = 0;
     pData  = new sal_uInt8[ nData ];
-    pNext1 =
-    pNext2 =
-    pLast1 =
-    pLast2 = NULL;
+    pNext2 = pLast2 = NULL;
 }
 
 StgPage::~StgPage()
@@ -84,7 +81,7 @@ StgCache::StgCache()
 {
     nRef = 0;
     pStrm = NULL;
-    pCur = pElem1 = NULL;
+    pElem1 = NULL;
     nPageSize = 512;
     nError = SVSTREAM_OK;
     bMyStream = sal_False;
@@ -112,7 +109,6 @@ void StgCache::SetPhysPageSize( short n )
 }
 
 // Create a new cache element
-// pCur points to this element
 
 StgPage* StgCache::Create( sal_Int32 nPg )
 {
@@ -121,18 +117,7 @@ StgPage* StgCache::Create( sal_Int32 nPg )
     // For data security, clear the buffer contents
     memset( pElem->pData, 0, pElem->nData );
 
-    // insert to LRU
-    if( pCur )
-    {
-        pElem->pNext1 = pCur;
-        pElem->pLast1 = pCur->pLast1;
-        pElem->pNext1->pLast1 =
-        pElem->pLast1->pNext1 = pElem;
-    }
-    else
-        pElem->pNext1 = pElem->pLast1 = pElem;
     maLRUCache[pElem->nPage] = pElem;
-    pCur = pElem;
 
     // insert to Sorted
     if( !pElem1 )
@@ -163,12 +148,6 @@ void StgCache::Erase( StgPage* pElem )
     OSL_ENSURE( pElem, "The pointer should not be NULL!" );
     if ( pElem )
     {
-        OSL_ENSURE( pElem->pNext1 && pElem->pLast1, "The pointers may not be NULL!" );
-        //remove from LRU
-        pElem->pNext1->pLast1 = pElem->pLast1;
-        pElem->pLast1->pNext1 = pElem->pNext1;
-        if( pCur == pElem )
-            pCur = ( pElem->pNext1 == pElem ) ? NULL : pElem->pNext1;
         maLRUCache.erase( pElem->nPage );
         // remove from Sorted
         pElem->pNext2->pLast2 = pElem->pLast2;
@@ -183,15 +162,14 @@ void StgCache::Erase( StgPage* pElem )
 
 void StgCache::Clear()
 {
-    StgPage* pElem = pCur;
-    if( pCur ) do
+    StgPage *pElem = pElem1;
+    if( pElem ) do
     {
         StgPage* pDelete = pElem;
-        pElem = pElem->pNext1;
+        pElem = pElem->pNext2;
         delete pDelete;
     }
-    while( pCur != pElem );
-    pCur = NULL;
+    while( pElem != pElem1 );
     pElem1 = NULL;
     maLRUCache.clear();
 }
@@ -206,19 +184,6 @@ StgPage* StgCache::Find( sal_Int32 nPage )
         // page found
         StgPage* pFound = (*aIt).second;
         OSL_ENSURE( pFound, "The pointer may not be NULL!" );
-
-        if( pFound != pCur )
-        {
-            OSL_ENSURE( pFound->pNext1 && pFound->pLast1, "The pointers may not be NULL!" );
-            // remove from LRU
-            pFound->pNext1->pLast1 = pFound->pLast1;
-            pFound->pLast1->pNext1 = pFound->pNext1;
-            // insert to LRU
-            pFound->pNext1 = pCur;
-            pFound->pLast1 = pCur->pLast1;
-            pFound->pNext1->pLast1 =
-            pFound->pLast1->pNext1 = pFound;
-        }
         return pFound;
     }
     return NULL;
@@ -283,34 +248,6 @@ sal_Bool StgCache::Commit()
     } while( p != pElem1 );
     pStrm->Flush();
     SetError( pStrm->GetError() );
-#ifdef CHECK_DIRTY
-    p = pElem1;
-    if( p ) do
-    {
-        if( p->bDirty )
-        {
-            ErrorBox( NULL, WB_OK, String("SO2: Dirty Block in Ordered List") ).Execute();
-            sal_Bool b = Write( p->nPage, p->pData, 1 );
-            if( !b )
-                return sal_False;
-            p->bDirty = sal_False;
-        }
-        p = p->pNext2;
-    } while( p != pElem1 );
-    p = pElem1;
-    if( p ) do
-    {
-        if( p->bDirty )
-        {
-            ErrorBox( NULL, WB_OK, String("SO2: Dirty Block in LRU List") ).Execute();
-            sal_Bool b = Write( p->nPage, p->pData, 1 );
-            if( !b )
-                return sal_False;
-            p->bDirty = sal_False;
-        }
-        p = p->pNext1;
-    } while( p != pElem1 );
-#endif
     return sal_True;
 }
 
diff --git a/sot/source/sdstor/stgcache.hxx b/sot/source/sdstor/stgcache.hxx
index 3420423..dc1d88d 100644
--- a/sot/source/sdstor/stgcache.hxx
+++ b/sot/source/sdstor/stgcache.hxx
@@ -91,7 +91,6 @@ public:
 class StgPage {
     friend class StgCache;
     StgCache* pCache;                       // the cache
-    StgPage *pNext1, *pLast1;               // LRU chain
     StgPage *pNext2, *pLast2;               // ordered chain
     sal_Int32   nPage;                          // page #
     sal_uInt8*  pData;                          // nPageSize characters
commit 422a41ff11b915aea2813f3a674f06b689df65b2
Author: Michael Meeks <michael.meeks at suse.com>
Date:   Wed Sep 19 14:39:32 2012 +0100

    sot: remove horrible hiding of LRU cache map
    
    Change-Id: Ic8df1012752e78d3326999a07dc15a99e982b896

diff --git a/sot/source/sdstor/stgcache.cxx b/sot/source/sdstor/stgcache.cxx
index fc2c877..74094f8 100644
--- a/sot/source/sdstor/stgcache.cxx
+++ b/sot/source/sdstor/stgcache.cxx
@@ -18,14 +18,6 @@
  */
 
 
-#if defined(_MSC_VER) && (_MSC_VER<1200)
-#include <tools/presys.h>
-#endif
-#include <boost/unordered_map.hpp>
-#if defined(_MSC_VER) && (_MSC_VER<1200)
-#include <tools/postsys.h>
-#endif
-
 #include <string.h>
 #include <osl/endian.h>
 #include <tools/string.hxx>
@@ -37,19 +29,6 @@
 #include "stgdir.hxx"
 #include "stgio.hxx"
 
-/*************************************************************************/
-//-----------------------------------------------------------------------------
-typedef boost::unordered_map
-<
-    sal_Int32,
-    StgPage *,
-    boost::hash< sal_Int32 >,
-    std::equal_to< sal_Int32 >
-> UsrStgPagePtr_Impl;
-#ifdef _MSC_VER
-#pragma warning( disable: 4786 )
-#endif
-
 //#define   CHECK_DIRTY 1
 //#define   READ_AFTER_WRITE 1
 
@@ -110,7 +89,6 @@ StgCache::StgCache()
     nError = SVSTREAM_OK;
     bMyStream = sal_False;
     bFile = sal_False;
-    pLRUCache = NULL;
     pStorageStream = NULL;
 }
 
@@ -118,7 +96,6 @@ StgCache::~StgCache()
 {
     Clear();
     SetStrm( NULL, sal_False );
-    delete (UsrStgPagePtr_Impl*)pLRUCache;
 }
 
 void StgCache::SetPhysPageSize( short n )
@@ -154,9 +131,7 @@ StgPage* StgCache::Create( sal_Int32 nPg )
     }
     else
         pElem->pNext1 = pElem->pLast1 = pElem;
-    if( !pLRUCache )
-        pLRUCache = new UsrStgPagePtr_Impl();
-    (*(UsrStgPagePtr_Impl*)pLRUCache)[pElem->nPage] = pElem;
+    maLRUCache[pElem->nPage] = pElem;
     pCur = pElem;
 
     // insert to Sorted
@@ -194,8 +169,7 @@ void StgCache::Erase( StgPage* pElem )
         pElem->pLast1->pNext1 = pElem->pNext1;
         if( pCur == pElem )
             pCur = ( pElem->pNext1 == pElem ) ? NULL : pElem->pNext1;
-        if( pLRUCache )
-            ((UsrStgPagePtr_Impl*)pLRUCache)->erase( pElem->nPage );
+        maLRUCache.erase( pElem->nPage );
         // remove from Sorted
         pElem->pNext2->pLast2 = pElem->pLast2;
         pElem->pLast2->pNext2 = pElem->pNext2;
@@ -219,18 +193,15 @@ void StgCache::Clear()
     while( pCur != pElem );
     pCur = NULL;
     pElem1 = NULL;
-    delete (UsrStgPagePtr_Impl*)pLRUCache;
-    pLRUCache = NULL;
+    maLRUCache.clear();
 }
 
 // Look for a cached page
 
 StgPage* StgCache::Find( sal_Int32 nPage )
 {
-    if( !pLRUCache )
-        return NULL;
-    UsrStgPagePtr_Impl::iterator aIt = ((UsrStgPagePtr_Impl*)pLRUCache)->find( nPage );
-    if( aIt != ((UsrStgPagePtr_Impl*)pLRUCache)->end() )
+    IndexToStgPage::iterator aIt = maLRUCache.find( nPage );
+    if( aIt != maLRUCache.end() )
     {
         // page found
         StgPage* pFound = (*aIt).second;
diff --git a/sot/source/sdstor/stgcache.hxx b/sot/source/sdstor/stgcache.hxx
index a9fcc85..3420423 100644
--- a/sot/source/sdstor/stgcache.hxx
+++ b/sot/source/sdstor/stgcache.hxx
@@ -24,20 +24,28 @@
 #include <tools/solar.h>
 #include <tools/stream.hxx>
 #include <stgelem.hxx>
+#include <boost/unordered_map.hpp>
 
 class UCBStorageStream;
-
 class StgPage;
 class StgDirEntry;
 class StorageBase;
 
+typedef boost::unordered_map
+<
+    sal_Int32,
+    StgPage *,
+    boost::hash< sal_Int32 >,
+    std::equal_to< sal_Int32 >
+> IndexToStgPage;
+
 class StgCache {
     StgPage* pCur;                          // top of LRU list
     StgPage* pElem1;                        // top of ordered list
     sal_uLong nError;                           // error code
     sal_Int32 nPages;                           // size of data area in pages
     sal_uInt16 nRef;                            // reference count
-    void * pLRUCache;                       // hash table of cached objects
+    IndexToStgPage maLRUCache;              // hash of index to cached pages
     short nPageSize;                        // page size of the file
     UCBStorageStream* pStorageStream;       // holds reference to UCB storage stream
 
commit 3b3d738c167c04541fd16022ef7221cedd1e3b66
Author: Michael Meeks <michael.meeks at suse.com>
Date:   Wed Sep 19 13:23:59 2012 +0100

    sot: remove unused Owner construct on StgPage
    
    Change-Id: Idd6616ac11e16b4c4631c607a3dc92417a796521

diff --git a/sot/source/sdstor/stgcache.cxx b/sot/source/sdstor/stgcache.cxx
index cf6f8cb..fc2c877 100644
--- a/sot/source/sdstor/stgcache.cxx
+++ b/sot/source/sdstor/stgcache.cxx
@@ -70,7 +70,6 @@ StgPage::StgPage( StgCache* p, short n )
     pNext2 =
     pLast1 =
     pLast2 = NULL;
-    pOwner = NULL;
 }
 
 StgPage::~StgPage()
diff --git a/sot/source/sdstor/stgcache.hxx b/sot/source/sdstor/stgcache.hxx
index 517e27a..a9fcc85 100644
--- a/sot/source/sdstor/stgcache.hxx
+++ b/sot/source/sdstor/stgcache.hxx
@@ -85,7 +85,6 @@ class StgPage {
     StgCache* pCache;                       // the cache
     StgPage *pNext1, *pLast1;               // LRU chain
     StgPage *pNext2, *pLast2;               // ordered chain
-    StgDirEntry* pOwner;                    // owner
     sal_Int32   nPage;                          // page #
     sal_uInt8*  pData;                          // nPageSize characters
     short   nData;                          // size of this page
@@ -97,7 +96,6 @@ public:
     sal_Int32 GetPage()                     { return nPage;             }
     void* GetData()                     { return pData;             }
     short GetSize()                     { return nData;             }
-    void  SetOwner( StgDirEntry* p )    { pOwner = p;               }
     // routines for accessing FAT pages
     // Assume that the data is a FAT page and get/put FAT data.
     sal_Int32 GetPage( short nOff )
diff --git a/sot/source/sdstor/stgstrms.cxx b/sot/source/sdstor/stgstrms.cxx
index 927fb53..feb90c4 100644
--- a/sot/source/sdstor/stgstrms.cxx
+++ b/sot/source/sdstor/stgstrms.cxx
@@ -868,7 +868,6 @@ void* StgDataStrm::GetPtr( sal_Int32 Pos, sal_Bool bForce, sal_Bool bDirty )
         StgPage* pPg = rIo.Get( nPage, bForce );
         if (pPg && nOffset < pPg->GetSize())
         {
-            pPg->SetOwner( pEntry );
             if( bDirty )
                 pPg->SetDirty();
             return ((sal_uInt8 *)pPg->GetData()) + nOffset;
@@ -905,7 +904,6 @@ sal_Int32 StgDataStrm::Read( void* pBuf, sal_Int32 n )
                 if( pPg )
                 {
                     // data is present, so use the cached data
-                    pPg->SetOwner( pEntry );
                     memcpy( p, pPg->GetData(), nBytes );
                     nRes = nBytes;
                 }
@@ -919,7 +917,6 @@ sal_Int32 StgDataStrm::Read( void* pBuf, sal_Int32 n )
                 pPg = rIo.Get( nPage, sal_False );
                 if( !pPg )
                     break;
-                pPg->SetOwner( pEntry );
                 memcpy( p, (sal_uInt8*)pPg->GetData() + nOffset, nBytes );
                 nRes = nBytes;
             }
@@ -966,7 +963,6 @@ sal_Int32 StgDataStrm::Write( const void* pBuf, sal_Int32 n )
                 if( pPg )
                 {
                     // data is present, so use the cached data
-                    pPg->SetOwner( pEntry );
                     memcpy( pPg->GetData(), p, nBytes );
                     pPg->SetDirty();
                     nRes = nBytes;
@@ -981,7 +977,6 @@ sal_Int32 StgDataStrm::Write( const void* pBuf, sal_Int32 n )
                 pPg = rIo.Get( nPage, sal_False );
                 if( !pPg )
                     break;
-                pPg->SetOwner( pEntry );
                 memcpy( (sal_uInt8*)pPg->GetData() + nOffset, p, nBytes );
                 pPg->SetDirty();
                 nRes = nBytes;


More information about the Libreoffice-commits mailing list