Kaydet (Commit) 422a41ff authored tarafından Michael Meeks's avatar Michael Meeks

sot: remove horrible hiding of LRU cache map

Change-Id: Ic8df1012752e78d3326999a07dc15a99e982b896
üst 3b3d738c
...@@ -18,14 +18,6 @@ ...@@ -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 <string.h>
#include <osl/endian.h> #include <osl/endian.h>
#include <tools/string.hxx> #include <tools/string.hxx>
...@@ -37,19 +29,6 @@ ...@@ -37,19 +29,6 @@
#include "stgdir.hxx" #include "stgdir.hxx"
#include "stgio.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 CHECK_DIRTY 1
//#define READ_AFTER_WRITE 1 //#define READ_AFTER_WRITE 1
...@@ -110,7 +89,6 @@ StgCache::StgCache() ...@@ -110,7 +89,6 @@ StgCache::StgCache()
nError = SVSTREAM_OK; nError = SVSTREAM_OK;
bMyStream = sal_False; bMyStream = sal_False;
bFile = sal_False; bFile = sal_False;
pLRUCache = NULL;
pStorageStream = NULL; pStorageStream = NULL;
} }
...@@ -118,7 +96,6 @@ StgCache::~StgCache() ...@@ -118,7 +96,6 @@ StgCache::~StgCache()
{ {
Clear(); Clear();
SetStrm( NULL, sal_False ); SetStrm( NULL, sal_False );
delete (UsrStgPagePtr_Impl*)pLRUCache;
} }
void StgCache::SetPhysPageSize( short n ) void StgCache::SetPhysPageSize( short n )
...@@ -154,9 +131,7 @@ StgPage* StgCache::Create( sal_Int32 nPg ) ...@@ -154,9 +131,7 @@ StgPage* StgCache::Create( sal_Int32 nPg )
} }
else else
pElem->pNext1 = pElem->pLast1 = pElem; pElem->pNext1 = pElem->pLast1 = pElem;
if( !pLRUCache ) maLRUCache[pElem->nPage] = pElem;
pLRUCache = new UsrStgPagePtr_Impl();
(*(UsrStgPagePtr_Impl*)pLRUCache)[pElem->nPage] = pElem;
pCur = pElem; pCur = pElem;
// insert to Sorted // insert to Sorted
...@@ -194,8 +169,7 @@ void StgCache::Erase( StgPage* pElem ) ...@@ -194,8 +169,7 @@ void StgCache::Erase( StgPage* pElem )
pElem->pLast1->pNext1 = pElem->pNext1; pElem->pLast1->pNext1 = pElem->pNext1;
if( pCur == pElem ) if( pCur == pElem )
pCur = ( pElem->pNext1 == pElem ) ? NULL : pElem->pNext1; pCur = ( pElem->pNext1 == pElem ) ? NULL : pElem->pNext1;
if( pLRUCache ) maLRUCache.erase( pElem->nPage );
((UsrStgPagePtr_Impl*)pLRUCache)->erase( pElem->nPage );
// remove from Sorted // remove from Sorted
pElem->pNext2->pLast2 = pElem->pLast2; pElem->pNext2->pLast2 = pElem->pLast2;
pElem->pLast2->pNext2 = pElem->pNext2; pElem->pLast2->pNext2 = pElem->pNext2;
...@@ -219,18 +193,15 @@ void StgCache::Clear() ...@@ -219,18 +193,15 @@ void StgCache::Clear()
while( pCur != pElem ); while( pCur != pElem );
pCur = NULL; pCur = NULL;
pElem1 = NULL; pElem1 = NULL;
delete (UsrStgPagePtr_Impl*)pLRUCache; maLRUCache.clear();
pLRUCache = NULL;
} }
// Look for a cached page // Look for a cached page
StgPage* StgCache::Find( sal_Int32 nPage ) StgPage* StgCache::Find( sal_Int32 nPage )
{ {
if( !pLRUCache ) IndexToStgPage::iterator aIt = maLRUCache.find( nPage );
return NULL; if( aIt != maLRUCache.end() )
UsrStgPagePtr_Impl::iterator aIt = ((UsrStgPagePtr_Impl*)pLRUCache)->find( nPage );
if( aIt != ((UsrStgPagePtr_Impl*)pLRUCache)->end() )
{ {
// page found // page found
StgPage* pFound = (*aIt).second; StgPage* pFound = (*aIt).second;
......
...@@ -24,20 +24,28 @@ ...@@ -24,20 +24,28 @@
#include <tools/solar.h> #include <tools/solar.h>
#include <tools/stream.hxx> #include <tools/stream.hxx>
#include <stgelem.hxx> #include <stgelem.hxx>
#include <boost/unordered_map.hpp>
class UCBStorageStream; class UCBStorageStream;
class StgPage; class StgPage;
class StgDirEntry; class StgDirEntry;
class StorageBase; class StorageBase;
typedef boost::unordered_map
<
sal_Int32,
StgPage *,
boost::hash< sal_Int32 >,
std::equal_to< sal_Int32 >
> IndexToStgPage;
class StgCache { class StgCache {
StgPage* pCur; // top of LRU list StgPage* pCur; // top of LRU list
StgPage* pElem1; // top of ordered list StgPage* pElem1; // top of ordered list
sal_uLong nError; // error code sal_uLong nError; // error code
sal_Int32 nPages; // size of data area in pages sal_Int32 nPages; // size of data area in pages
sal_uInt16 nRef; // reference count 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 short nPageSize; // page size of the file
UCBStorageStream* pStorageStream; // holds reference to UCB storage stream UCBStorageStream* pStorageStream; // holds reference to UCB storage stream
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment