summaryrefslogtreecommitdiff
path: root/sw/source/core/bastyp
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2019-01-09 12:52:54 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2019-01-10 08:16:27 +0100
commitb8f497a06d585dbae3adadb4d177fe84fdb1b5fa (patch)
tree81a49d027648531906191c52d6fc7be026dff182 /sw/source/core/bastyp
parent50887c9010515fe9fe61b3067f502cd28333773a (diff)
use unique_ptr in SwCache
Change-Id: I2b961380dcb5eb26ce517f7b56e5c32f5e6429e4 Reviewed-on: https://gerrit.libreoffice.org/66011 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sw/source/core/bastyp')
-rw-r--r--sw/source/core/bastyp/swcache.cxx23
1 files changed, 9 insertions, 14 deletions
diff --git a/sw/source/core/bastyp/swcache.cxx b/sw/source/core/bastyp/swcache.cxx
index 2693578c8b21..6abbbb51faea 100644
--- a/sw/source/core/bastyp/swcache.cxx
+++ b/sw/source/core/bastyp/swcache.cxx
@@ -125,9 +125,6 @@ SwCache::~SwCache()
<< "; number of Cache reductions: " << m_nDecreaseMax);
Check();
#endif
-
- for(const auto& rpObj : m_aCacheObjects)
- delete rpObj;
}
void SwCache::IncreaseMax( const sal_uInt16 nAdd )
@@ -163,8 +160,7 @@ void SwCache::Flush()
pTmp = pObj;
pObj = pTmp->GetNext();
m_aFreePositions.push_back( pTmp->GetCachePos() );
- m_aCacheObjects[pTmp->GetCachePos()] = nullptr;
- delete pTmp;
+ m_aCacheObjects[pTmp->GetCachePos()].reset(); // deletes pTmp
INCREMENT( m_nFlushedObjects );
}
}
@@ -236,7 +232,7 @@ SwCacheObj *SwCache::Get( const void *pOwner, const sal_uInt16 nIndex,
const bool bToTop )
{
SwCacheObj *pRet;
- if ( nullptr != (pRet = (nIndex < m_aCacheObjects.size()) ? m_aCacheObjects[ nIndex ] : nullptr) )
+ if ( nullptr != (pRet = (nIndex < m_aCacheObjects.size()) ? m_aCacheObjects[ nIndex ].get() : nullptr) )
{
if ( !pRet->IsOwner( pOwner ) )
pRet = nullptr;
@@ -300,8 +296,7 @@ void SwCache::DeleteObj( SwCacheObj *pObj )
pObj->GetNext()->SetPrev( pObj->GetPrev() );
m_aFreePositions.push_back( pObj->GetCachePos() );
- m_aCacheObjects[pObj->GetCachePos()] = nullptr;
- delete pObj;
+ m_aCacheObjects[pObj->GetCachePos()] = nullptr; // deletes pObj
CHECK;
if ( m_aCacheObjects.size() > m_nCurMax &&
@@ -312,9 +307,10 @@ void SwCache::DeleteObj( SwCacheObj *pObj )
// these might not find them afterwards
for ( size_t i = 0; i < m_aCacheObjects.size(); ++i )
{
- SwCacheObj *pTmpObj = m_aCacheObjects[i];
+ SwCacheObj *pTmpObj = m_aCacheObjects[i].get();
if ( !pTmpObj )
- { m_aCacheObjects.erase( m_aCacheObjects.begin() + i );
+ {
+ m_aCacheObjects.erase( m_aCacheObjects.begin() + i );
--i;
}
else
@@ -346,7 +342,7 @@ bool SwCache::Insert( SwCacheObj *pNew )
// there is still space; insert directly
INCREMENT( m_nAppend );
nPos = m_aCacheObjects.size();
- m_aCacheObjects.push_back(pNew);
+ m_aCacheObjects.emplace_back(pNew);
}
else if ( !m_aFreePositions.empty() )
{
@@ -354,7 +350,7 @@ bool SwCache::Insert( SwCacheObj *pNew )
INCREMENT( m_nInsertFree );
const sal_uInt16 nFreePos = m_aFreePositions.size() - 1;
nPos = m_aFreePositions[ nFreePos ];
- m_aCacheObjects[nPos] = pNew;
+ m_aCacheObjects[nPos].reset(pNew);
m_aFreePositions.erase( m_aFreePositions.begin() + nFreePos );
}
else
@@ -403,8 +399,7 @@ bool SwCache::Insert( SwCacheObj *pNew )
{
pObj->GetNext()->SetPrev( pObj->GetPrev() );
}
- delete pObj;
- m_aCacheObjects[nPos] = pNew;
+ m_aCacheObjects[nPos].reset(pNew);
}
pNew->SetCachePos( nPos );