summaryrefslogtreecommitdiff
path: root/stoc
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2018-08-02 15:29:12 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2018-08-03 11:57:42 +0200
commited1e2967064e098459324818baa5466ad2a90492 (patch)
tree12e8411f9b1093fa8874aeee99e2979f20a8bc38 /stoc
parent03e0d86fe221ee3d8a8595fcd4ccf682101255f1 (diff)
loplugin:useuniqueptr in lru_cache
Change-Id: I8ccd3acdcb160a19466da2bbf05527617c9f9ad2 Reviewed-on: https://gerrit.libreoffice.org/58491 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'stoc')
-rw-r--r--stoc/source/security/lru_cache.h26
1 files changed, 8 insertions, 18 deletions
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
{