[Libreoffice-commits] core.git: stoc/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Fri Aug 3 09:58:11 UTC 2018


 stoc/source/security/lru_cache.h |   26 ++++++++------------------
 1 file changed, 8 insertions(+), 18 deletions(-)

New commits:
commit ed1e2967064e098459324818baa5466ad2a90492
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Thu Aug 2 15:29:12 2018 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Fri Aug 3 11:57:42 2018 +0200

    loplugin:useuniqueptr in lru_cache
    
    Change-Id: I8ccd3acdcb160a19466da2bbf05527617c9f9ad2
    Reviewed-on: https://gerrit.libreoffice.org/58491
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/stoc/source/security/lru_cache.h b/stoc/source/security/lru_cache.h
index 28c34fec9eda..8d9f69fe1c5e 100644
--- a/stoc/source/security/lru_cache.h
+++ b/stoc/source/security/lru_cache.h
@@ -19,6 +19,7 @@
 #ifndef INCLUDED_STOC_SOURCE_SECURITY_LRU_CACHE_H
 #define INCLUDED_STOC_SOURCE_SECURITY_LRU_CACHE_H
 
+#include <memory>
 #include <unordered_map>
 
 // __CACHE_DIAGNOSE works only for OUString keys
@@ -49,7 +50,7 @@ class lru_cache
     t_key2element m_key2element;
     ::std::size_t m_size;
 
-    Entry * m_block;
+    std::unique_ptr<Entry[]> m_block;
     mutable Entry * m_head;
     mutable Entry * m_tail;
     inline void toFront( Entry * entry ) const;
@@ -59,10 +60,6 @@ public:
     */
     inline lru_cache();
 
-    /** Destructor: releases all cached elements and keys.
-    */
-    inline ~lru_cache();
-
     /** Retrieves a pointer to value in cache.  Returns 0, if none was found.
 
         @param key a key
@@ -89,19 +86,18 @@ inline void lru_cache< t_key, t_val, t_hashKey, t_equalKey >::setSize(
     ::std::size_t size )
 {
     m_key2element.clear();
-    delete [] m_block;
-    m_block = nullptr;
+    m_block.reset();
     m_size = size;
 
     if (0 < m_size)
     {
-        m_block = new Entry[ m_size ];
-        m_head = m_block;
-        m_tail = m_block + m_size -1;
+        m_block.reset( new Entry[ m_size ] );
+        m_head = m_block.get();
+        m_tail = m_block.get() + m_size -1;
         for ( ::std::size_t nPos = m_size; nPos--; )
         {
-            m_block[ nPos ].m_pred = m_block + nPos -1;
-            m_block[ nPos ].m_succ = m_block + nPos +1;
+            m_block[ nPos ].m_pred = m_block.get() + nPos -1;
+            m_block[ nPos ].m_succ = m_block.get() + nPos +1;
         }
     }
 }
@@ -116,12 +112,6 @@ inline lru_cache< t_key, t_val, t_hashKey, t_equalKey >::lru_cache()
 }
 
 template< typename t_key, typename t_val, typename t_hashKey, typename t_equalKey >
-inline lru_cache< t_key, t_val, t_hashKey, t_equalKey >::~lru_cache()
-{
-    delete [] m_block;
-}
-
-template< typename t_key, typename t_val, typename t_hashKey, typename t_equalKey >
 inline void lru_cache< t_key, t_val, t_hashKey, t_equalKey >::toFront(
     Entry * entry ) const
 {


More information about the Libreoffice-commits mailing list