stoc/source/corereflection/lrucache.hxx |   23 +++++++----------------
 1 file changed, 7 insertions(+), 16 deletions(-)

New commits:
commit a0c2958552e82c3795b094a0538beab521679628
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Thu Aug 2 15:27:42 2018 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Fri Aug 3 11:06:38 2018 +0200

    loplugin:useuniqueptr in LRU_Cache
    
    Change-Id: I30d008f01318f9e484b08398ed1ca1b41f90946a
    Reviewed-on: https://gerrit.libreoffice.org/58490
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

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)
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to