Kaydet (Commit) 8f501827 authored tarafından Noel Grandin's avatar Noel Grandin Kaydeden (comit) Michael Stahl

Convert class SwOLELRUCache from Svptrarr to std::deque

Change-Id: I9c63a346db6b8ba3d463d5a9d78ccc21b7f6be5f
üst 64fff617
...@@ -68,7 +68,7 @@ using namespace utl; ...@@ -68,7 +68,7 @@ using namespace utl;
using namespace com::sun::star::uno; using namespace com::sun::star::uno;
using namespace com::sun::star; using namespace com::sun::star;
class SwOLELRUCache : private SvPtrarr, private utl::ConfigItem class SwOLELRUCache : private std::deque<SwOLEObj*>, private utl::ConfigItem
{ {
sal_uInt16 nLRU_InitSize; sal_uInt16 nLRU_InitSize;
sal_Bool bInUnload; sal_Bool bInUnload;
...@@ -83,16 +83,15 @@ public: ...@@ -83,16 +83,15 @@ public:
void Load(); void Load();
void SetInUnload( sal_Bool bFlag ) { bInUnload = bFlag; } void SetInUnload( sal_Bool bFlag ) { bInUnload = bFlag; }
using SvPtrarr::Count;
void InsertObj( SwOLEObj& rObj ); void InsertObj( SwOLEObj& rObj );
void RemoveObj( SwOLEObj& rObj ); void RemoveObj( SwOLEObj& rObj );
void RemovePtr( SwOLEObj* pObj ) void RemovePtr( SwOLEObj* pObj )
{ {
sal_uInt16 nPos = SvPtrarr::GetPos( pObj ); iterator it = std::find( begin(), end(), pObj );
if( USHRT_MAX != nPos ) if( it != end() )
SvPtrarr::Remove( nPos ); erase( it );
} }
}; };
...@@ -898,7 +897,7 @@ String SwOLEObj::GetDescription() ...@@ -898,7 +897,7 @@ String SwOLEObj::GetDescription()
SwOLELRUCache::SwOLELRUCache() SwOLELRUCache::SwOLELRUCache()
: SvPtrarr( 64 ), : std::deque<SwOLEObj*>(),
utl::ConfigItem(OUString(RTL_CONSTASCII_USTRINGPARAM("Office.Common/Cache"))), utl::ConfigItem(OUString(RTL_CONSTASCII_USTRINGPARAM("Office.Common/Cache"))),
nLRU_InitSize( 20 ), nLRU_InitSize( 20 ),
bInUnload( sal_False ) bInUnload( sal_False )
...@@ -939,13 +938,13 @@ void SwOLELRUCache::Load() ...@@ -939,13 +938,13 @@ void SwOLELRUCache::Load()
if( nVal < nLRU_InitSize ) if( nVal < nLRU_InitSize )
{ {
// size of cache has been changed // size of cache has been changed
sal_uInt16 nCount = SvPtrarr::Count(); sal_uInt16 nCount = size();
sal_uInt16 nPos = nCount; sal_uInt16 nPos = nCount;
// try to remove the last entries until new maximum size is reached // try to remove the last entries until new maximum size is reached
while( nCount > nVal ) while( nCount > nVal )
{ {
SwOLEObj* pObj = (SwOLEObj*) SvPtrarr::GetObject( --nPos ); SwOLEObj* pObj = operator[]( --nPos );
if ( pObj->UnloadObject() ) if ( pObj->UnloadObject() )
nCount--; nCount--;
if ( !nPos ) if ( !nPos )
...@@ -961,21 +960,21 @@ void SwOLELRUCache::Load() ...@@ -961,21 +960,21 @@ void SwOLELRUCache::Load()
void SwOLELRUCache::InsertObj( SwOLEObj& rObj ) void SwOLELRUCache::InsertObj( SwOLEObj& rObj )
{ {
SwOLEObj* pObj = &rObj; SwOLEObj* pObj = &rObj;
sal_uInt16 nPos = SvPtrarr::GetPos( pObj ); iterator it = std::find( begin(), end(), pObj );
if( nPos ) if( it != begin() )
{ {
// object is currently not the first in cache // object is currently not the first in cache
if( USHRT_MAX != nPos ) if( it != end() )
SvPtrarr::Remove( nPos ); erase( it );
SvPtrarr::Insert( pObj, 0 ); push_front( pObj );
// try to remove objects if necessary (of course not the freshly inserted one at nPos=0) // try to remove objects if necessary (of course not the freshly inserted one at nPos=0)
sal_uInt16 nCount = SvPtrarr::Count(); sal_uInt16 nCount = size();
nPos = nCount-1; sal_uInt16 nPos = nCount-1;
while( nPos && nCount > nLRU_InitSize ) while( nPos && nCount > nLRU_InitSize )
{ {
pObj = (SwOLEObj*) SvPtrarr::GetObject( nPos-- ); pObj = operator[]( nPos-- );
if ( pObj->UnloadObject() ) if ( pObj->UnloadObject() )
nCount--; nCount--;
} }
...@@ -984,10 +983,10 @@ void SwOLELRUCache::InsertObj( SwOLEObj& rObj ) ...@@ -984,10 +983,10 @@ void SwOLELRUCache::InsertObj( SwOLEObj& rObj )
void SwOLELRUCache::RemoveObj( SwOLEObj& rObj ) void SwOLELRUCache::RemoveObj( SwOLEObj& rObj )
{ {
sal_uInt16 nPos = SvPtrarr::GetPos( &rObj ); iterator it = std::find( begin(), end(), &rObj );
if ( nPos != 0xFFFF ) if ( it != end() )
SvPtrarr::Remove( nPos ); erase( it );
if( !Count() ) if( empty() )
DELETEZ( pOLELRU_Cache ); DELETEZ( pOLELRU_Cache );
} }
......
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