summaryrefslogtreecommitdiff
path: root/stoc
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2018-08-02 15:27:42 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2018-08-03 11:06:38 +0200
commita0c2958552e82c3795b094a0538beab521679628 (patch)
tree235dcfc3fdc3a04388ca56fe70c111adca7e764c /stoc
parent8d5b917d188a1f59d9c0df61424fbe960ddced90 (diff)
loplugin:useuniqueptr in LRU_Cache
Change-Id: I30d008f01318f9e484b08398ed1ca1b41f90946a Reviewed-on: https://gerrit.libreoffice.org/58490 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'stoc')
-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)