Index: sot/source/sdstor/stgcache.cxx =================================================================== --- sot/source/sdstor/stgcache.cxx (revision 1383373) +++ sot/source/sdstor/stgcache.cxx (working copy) @@ -44,6 +44,9 @@ #include "stgdir.hxx" #include "stgio.hxx" +#include "precompiled_sot.hxx" +#include + /*************************************************************************/ //----------------------------------------------------------------------------- typedef std::hash_map @@ -73,10 +76,6 @@ bDirty = sal_False; nPage = 0; pData = new sal_uInt8[ nData ]; - pNext1 = - pNext2 = - pLast1 = - pLast2 = NULL; pOwner = NULL; } @@ -113,7 +112,6 @@ { nRef = 0; pStrm = NULL; - pCur = pElem1 = NULL; nPageSize = 512; nError = SVSTREAM_OK; bMyStream = sal_False; @@ -151,41 +149,9 @@ pElem->nPage = 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; - if( !pLRUCache ) - pLRUCache = new UsrStgPagePtr_Impl(); - (*(UsrStgPagePtr_Impl*)pLRUCache)[pElem->nPage] = pElem; - pCur = pElem; - - // insert to Sorted - if( !pElem1 ) - pElem1 = pElem->pNext2 = pElem->pLast2 = pElem; - else - { - StgPage* p = pElem1; - do - { - if( pElem->nPage < p->nPage ) - break; - p = p->pNext2; - } while( p != pElem1 ); - pElem->pNext2 = p; - pElem->pLast2 = p->pLast2; - pElem->pNext2->pLast2 = - pElem->pLast2->pNext2 = pElem; - if( p->nPage < pElem1->nPage ) - pElem1 = pElem; - } + if( !pLRUCache ) + pLRUCache = new UsrStgPagePtr_Impl(); + (*(UsrStgPagePtr_Impl*)pLRUCache)[pElem->nPage] = pElem; return pElem; } @@ -196,19 +162,10 @@ OSL_ENSURE( pElem, "The pointer should not be NULL!" ); if ( pElem ) { - OSL_ENSURE( pElem->pNext1 && pElem->pLast1, "The pointers may not be NULL!" ); + // 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; if( pLRUCache ) ((UsrStgPagePtr_Impl*)pLRUCache)->erase( pElem->nPage ); - // remove from Sorted - pElem->pNext2->pLast2 = pElem->pLast2; - pElem->pLast2->pNext2 = pElem->pNext2; - if( pElem1 == pElem ) - pElem1 = ( pElem->pNext2 == pElem ) ? NULL : pElem->pNext2; delete pElem; } } @@ -217,16 +174,10 @@ void StgCache::Clear() { - StgPage* pElem = pCur; - if( pCur ) do - { - StgPage* pDelete = pElem; - pElem = pElem->pNext1; - delete pDelete; - } - while( pCur != pElem ); - pCur = NULL; - pElem1 = NULL; + if( UsrStgPagePtr_Impl* pLRUCache = (UsrStgPagePtr_Impl*)this->pLRUCache ) + for( UsrStgPagePtr_Impl::iterator i = pLRUCache->begin(); i!=pLRUCache->end(); i++ ) + delete i->second; + delete (UsrStgPagePtr_Impl*)pLRUCache; pLRUCache = NULL; } @@ -243,19 +194,6 @@ // 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; @@ -306,6 +244,41 @@ sal_Bool StgCache::Commit( StgDirEntry* ) { +#if 1 + const bool bCommittedMustOrdered = true; + + if( UsrStgPagePtr_Impl* pLRUCache = (UsrStgPagePtr_Impl*)this->pLRUCache ) + if( bCommittedMustOrdered ) + { + std::vector< std::pair< sal_uInt32, StgPage * > > vPages( pLRUCache->size() ); + std::copy( pLRUCache->begin(), pLRUCache->end(), vPages.begin() ); + std::sort( vPages.begin(), vPages.end() ); + + for( std::vector< std::pair< sal_uInt32, StgPage * > >::iterator i = vPages.begin(); i!=vPages.end(); i++ ) + if( i->second && i->second->bDirty ) + { + sal_Bool b = Write( i->second->nPage, i->second->pData, 1 ); + if( !b ) + return sal_False; + i->second->bDirty = sal_False; + } + } + else + { + for( UsrStgPagePtr_Impl::iterator i = pLRUCache->begin(); i!=pLRUCache->end(); i++ ) + if( i->second && i->second->bDirty ) + { + sal_Bool b = Write( i->second->nPage, i->second->pData, 1 ); + if( !b ) + return sal_False; + i->second->bDirty = sal_False; + } + } + + pStrm->Flush(); + SetError( pStrm->GetError() ); + +#elif 1 StgPage* p = pElem1; if( p ) do { @@ -348,6 +321,7 @@ p = p->pNext1; } while( p != pElem1 ); #endif +#endif return sal_True; } @@ -559,3 +533,5 @@ return ( ( nPos + nPageSize - 1 ) / nPageSize ) * nPageSize - 1; } +const sal_uInt16 nMemPoolStgPage = (0x1000 - 64) / ( sizeof ( StgPage ) ); +IMPL_FIXEDMEMPOOL_NEWDEL( StgPage, nMemPoolStgPage, nMemPoolStgPage ) Index: sot/source/sdstor/stgcache.hxx =================================================================== --- sot/source/sdstor/stgcache.hxx (revision 1383373) +++ sot/source/sdstor/stgcache.hxx (working copy) @@ -32,6 +32,7 @@ #include #endif #include +#include "tools/mempool.hxx" class UCBStorageStream; @@ -41,8 +42,6 @@ class StorageBase; 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 @@ -94,8 +93,6 @@ class StgPage { friend class StgCache; 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 @@ -123,6 +120,7 @@ #endif } void SetPage( short, sal_Int32 ); // put an element + DECL_FIXEDMEMPOOL_NEWDEL( StgPage ); }; #endif