Kaydet (Commit) ed1e2967 authored tarafından Noel Grandin's avatar Noel Grandin

loplugin:useuniqueptr in lru_cache

Change-Id: I8ccd3acdcb160a19466da2bbf05527617c9f9ad2
Reviewed-on: https://gerrit.libreoffice.org/58491
Tested-by: Jenkins
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 03e0d86f
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#ifndef INCLUDED_STOC_SOURCE_SECURITY_LRU_CACHE_H #ifndef INCLUDED_STOC_SOURCE_SECURITY_LRU_CACHE_H
#define INCLUDED_STOC_SOURCE_SECURITY_LRU_CACHE_H #define INCLUDED_STOC_SOURCE_SECURITY_LRU_CACHE_H
#include <memory>
#include <unordered_map> #include <unordered_map>
// __CACHE_DIAGNOSE works only for OUString keys // __CACHE_DIAGNOSE works only for OUString keys
...@@ -49,7 +50,7 @@ class lru_cache ...@@ -49,7 +50,7 @@ class lru_cache
t_key2element m_key2element; t_key2element m_key2element;
::std::size_t m_size; ::std::size_t m_size;
Entry * m_block; std::unique_ptr<Entry[]> m_block;
mutable Entry * m_head; mutable Entry * m_head;
mutable Entry * m_tail; mutable Entry * m_tail;
inline void toFront( Entry * entry ) const; inline void toFront( Entry * entry ) const;
...@@ -59,10 +60,6 @@ public: ...@@ -59,10 +60,6 @@ public:
*/ */
inline lru_cache(); 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. /** Retrieves a pointer to value in cache. Returns 0, if none was found.
@param key a key @param key a key
...@@ -89,19 +86,18 @@ inline void lru_cache< t_key, t_val, t_hashKey, t_equalKey >::setSize( ...@@ -89,19 +86,18 @@ inline void lru_cache< t_key, t_val, t_hashKey, t_equalKey >::setSize(
::std::size_t size ) ::std::size_t size )
{ {
m_key2element.clear(); m_key2element.clear();
delete [] m_block; m_block.reset();
m_block = nullptr;
m_size = size; m_size = size;
if (0 < m_size) if (0 < m_size)
{ {
m_block = new Entry[ m_size ]; m_block.reset( new Entry[ m_size ] );
m_head = m_block; m_head = m_block.get();
m_tail = m_block + m_size -1; m_tail = m_block.get() + m_size -1;
for ( ::std::size_t nPos = m_size; nPos--; ) for ( ::std::size_t nPos = m_size; nPos--; )
{ {
m_block[ nPos ].m_pred = m_block + nPos -1; m_block[ nPos ].m_pred = m_block.get() + nPos -1;
m_block[ nPos ].m_succ = m_block + nPos +1; m_block[ nPos ].m_succ = m_block.get() + nPos +1;
} }
} }
} }
...@@ -115,12 +111,6 @@ inline lru_cache< t_key, t_val, t_hashKey, t_equalKey >::lru_cache() ...@@ -115,12 +111,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 > 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( inline void lru_cache< t_key, t_val, t_hashKey, t_equalKey >::toFront(
Entry * entry ) const Entry * entry ) const
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment