summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--stoc/source/corereflection/lrucache.hxx23
1 files changed, 7 insertions, 16 deletions
diff --git a/stoc/source/corereflection/lrucache.hxx b/stoc/source/corereflection/lrucache.hxx
index bab65f87786f..e9a89bebd66f 100644
--- a/stoc/source/corereflection/lrucache.hxx
+++ b/stoc/source/corereflection/lrucache.hxx
@@ -26,6 +26,7 @@
#include <rtl/ustring.hxx>
#include <sal/log.hxx>
+#include <memory>
#include <unordered_map>
/** Implementation of a least recently used (lru) cache.
@@ -47,7 +48,7 @@ class LRU_Cache
sal_Int32 _nCachedElements;
t_Key2Element _aKey2Element;
- CacheEntry * _pBlock;
+ std::unique_ptr<CacheEntry[]> _pBlock;
mutable CacheEntry * _pHead;
mutable CacheEntry * _pTail;
inline void toFront( CacheEntry * pEntry ) const;
@@ -58,10 +59,6 @@ public:
@param nCachedElements number of elements to be cached; default param set to 128
*/
explicit inline LRU_Cache();
- /** Destructor: releases all cached elements and keys.
- <br>
- */
- inline ~LRU_Cache();
/** Retrieves a value from the cache. Returns default constructed value,
if none was found.
@@ -95,24 +92,18 @@ inline LRU_Cache< t_Key, t_Val, t_KeyHash >::LRU_Cache()
{
if (_nCachedElements > 0)
{
- _pBlock = new CacheEntry[_nCachedElements];
- _pHead = _pBlock;
- _pTail = _pBlock + _nCachedElements -1;
+ _pBlock.reset(new CacheEntry[_nCachedElements]);
+ _pHead = _pBlock.get();
+ _pTail = _pBlock.get() + _nCachedElements -1;
for ( sal_Int32 nPos = _nCachedElements; nPos--; )
{
- _pBlock[nPos].pPred = _pBlock + nPos -1;
- _pBlock[nPos].pSucc = _pBlock + nPos +1;
+ _pBlock[nPos].pPred = _pBlock.get() + nPos -1;
+ _pBlock[nPos].pSucc = _pBlock.get() + nPos +1;
}
}
}
template< class t_Key, class t_Val, class t_KeyHash >
-inline LRU_Cache< t_Key, t_Val, t_KeyHash >::~LRU_Cache()
-{
- delete [] _pBlock;
-}
-
-template< class t_Key, class t_Val, class t_KeyHash >
inline void LRU_Cache< t_Key, t_Val, t_KeyHash >::toFront( CacheEntry * pEntry ) const
{
if (pEntry != _pHead)