From ed1e2967064e098459324818baa5466ad2a90492 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Thu, 2 Aug 2018 15:29:12 +0200 Subject: loplugin:useuniqueptr in lru_cache Change-Id: I8ccd3acdcb160a19466da2bbf05527617c9f9ad2 Reviewed-on: https://gerrit.libreoffice.org/58491 Tested-by: Jenkins Reviewed-by: Noel Grandin --- stoc/source/security/lru_cache.h | 26 ++++++++------------------ 1 file 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 #include // __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 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; } } } @@ -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 > inline void lru_cache< t_key, t_val, t_hashKey, t_equalKey >::toFront( Entry * entry ) const -- cgit