summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoel Grandin <noel@peralex.com>2012-05-23 16:13:53 +0200
committerMichael Stahl <mstahl@redhat.com>2012-05-25 00:17:08 +0200
commitb55cb6f2bd09ac91fabd5ce1a5bb5766e837e29f (patch)
tree1b8308007653464bb25a0ad1f65bd6e13ca53575
parent7d69ffe8c92521537521f3a66a089eb3ed5c2be2 (diff)
Inline SV_DECL_PTRARR_DEL(SwCacheObjArr) into a std::vector
..inside of the SwCache class. Change-Id: Ie8cf55c28a04d3776b99a8608880ac7a19f748b2
-rw-r--r--sw/source/core/bastyp/swcache.cxx38
-rw-r--r--sw/source/core/inc/swcache.hxx9
-rw-r--r--sw/source/core/layout/newfrm.cxx2
3 files changed, 27 insertions, 22 deletions
diff --git a/sw/source/core/bastyp/swcache.cxx b/sw/source/core/bastyp/swcache.cxx
index 9c0187f4cd0f..adbcb949f21a 100644
--- a/sw/source/core/bastyp/swcache.cxx
+++ b/sw/source/core/bastyp/swcache.cxx
@@ -30,8 +30,6 @@
#include <swcache.hxx>
#include <rtl/strbuf.hxx>
-SV_IMPL_PTRARR(SwCacheObjArr,SwCacheObj*);
-
#ifdef DBG_UTIL
#define INCREMENT( nVar ) ++nVar
#else
@@ -95,7 +93,7 @@ SwCache::SwCache( const sal_uInt16 nInitSize
, const rtl::OString &rNm
#endif
) :
- SwCacheObjArr( (sal_uInt8)nInitSize ),
+ m_aCacheObjects(),
pRealFirst( 0 ),
pFirst( 0 ),
pLast( 0 ),
@@ -118,6 +116,7 @@ SwCache::SwCache( const sal_uInt16 nInitSize
, m_nDecreaseMax( 0 )
#endif
{
+ m_aCacheObjects.reserve( (sal_uInt8)nInitSize );
}
#ifdef DBG_UTIL
@@ -183,6 +182,9 @@ SwCache::~SwCache()
OSL_TRACE(sOut.getStr());
}
Check();
+
+ for(SwCacheObjArr::const_iterator it = m_aCacheObjects.begin(); it != m_aCacheObjects.end(); ++it)
+ delete *it;
}
#endif
@@ -225,7 +227,7 @@ void SwCache::Flush( const sal_uInt8 )
pTmp = (SwCacheObj*)pObj;
pObj = pTmp->GetNext();
aFreePositions.push_back( pTmp->GetCachePos() );
- *(pData + pTmp->GetCachePos()) = (void*)0;
+ m_aCacheObjects[pTmp->GetCachePos()] = NULL;
delete pTmp;
INCREMENT( m_nFlushedObjects );
}
@@ -306,7 +308,7 @@ SwCacheObj *SwCache::Get( const void *pOwner, const sal_uInt16 nIndex,
const sal_Bool bToTop )
{
SwCacheObj *pRet;
- if ( 0 != (pRet = nIndex < Count() ? operator[]( nIndex ) : 0) )
+ if ( 0 != (pRet = nIndex < m_aCacheObjects.size() ? m_aCacheObjects[ nIndex ] : 0) )
{
if ( !pRet->IsOwner( pOwner ) )
pRet = 0;
@@ -377,23 +379,23 @@ void SwCache::DeleteObj( SwCacheObj *pObj )
pObj->GetNext()->SetPrev( pObj->GetPrev() );
aFreePositions.push_back( pObj->GetCachePos() );
- *(pData + pObj->GetCachePos()) = (void*)0;
+ m_aCacheObjects[pObj->GetCachePos()] = NULL;
delete pObj;
CHECK;
- if ( Count() > nCurMax &&
- (nCurMax <= (Count() - aFreePositions.size())) )
+ if ( m_aCacheObjects.size() > nCurMax &&
+ (nCurMax <= (m_aCacheObjects.size() - aFreePositions.size())) )
{
//Falls moeglich wieder verkleinern, dazu muessen allerdings ausreichend
//Freie Positionen bereitstehen.
//Unangenehmer Nebeneffekt ist, das die Positionen verschoben werden
//muessen, und die Eigentuemer der Objekte diese wahrscheinlich nicht
//wiederfinden werden.
- for ( sal_uInt16 i = 0; i < Count(); ++i )
+ for ( sal_uInt16 i = 0; i < m_aCacheObjects.size(); ++i )
{
- SwCacheObj *pTmpObj = operator[](i);
+ SwCacheObj *pTmpObj = m_aCacheObjects[i];
if ( !pTmpObj )
- { SwCacheObjArr::Remove( i, 1 );
+ { m_aCacheObjects.erase( m_aCacheObjects.begin() + i );
--i;
}
else
@@ -424,12 +426,12 @@ sal_Bool SwCache::Insert( SwCacheObj *pNew )
OSL_ENSURE( !pNew->GetPrev() && !pNew->GetNext(), "New but not new." );
sal_uInt16 nPos;//Wird hinter den if's zum setzen am Obj benutzt.
- if ( Count() < nCurMax )
+ if ( m_aCacheObjects.size() < nCurMax )
{
//Es ist noch Platz frei, also einfach einfuegen.
INCREMENT( m_nAppend );
- nPos = Count();
- SwCacheObjArr::C40_INSERT( SwCacheObj, pNew, nPos );
+ nPos = m_aCacheObjects.size();
+ m_aCacheObjects.push_back(pNew);
}
else if ( !aFreePositions.empty() )
{
@@ -437,7 +439,7 @@ sal_Bool SwCache::Insert( SwCacheObj *pNew )
INCREMENT( m_nInsertFree );
const sal_uInt16 nFreePos = aFreePositions.size() - 1;
nPos = aFreePositions[ nFreePos ];
- *(pData + nPos) = pNew;
+ m_aCacheObjects[nPos] = pNew;
aFreePositions.erase( aFreePositions.begin() + nFreePos );
}
else
@@ -468,7 +470,7 @@ sal_Bool SwCache::Insert( SwCacheObj *pNew )
pObj->GetNext()->SetPrev( pObj->GetPrev() );
}
delete pObj;
- *(pData + nPos) = pNew;
+ m_aCacheObjects[nPos] = pNew;
}
pNew->SetCachePos( nPos );
@@ -502,12 +504,12 @@ sal_Bool SwCache::Insert( SwCacheObj *pNew )
void SwCache::SetLRUOfst( const sal_uInt16 nOfst )
{
- if ( !pRealFirst || ((Count() - aFreePositions.size()) < nOfst) )
+ if ( !pRealFirst || ((m_aCacheObjects.size() - aFreePositions.size()) < nOfst) )
return;
CHECK;
pFirst = pRealFirst;
- for ( sal_uInt16 i = 0; i < Count() && i < nOfst; ++i )
+ for ( sal_uInt16 i = 0; i < m_aCacheObjects.size() && i < nOfst; ++i )
{
if ( pFirst->GetNext() && pFirst->GetNext()->GetNext() )
pFirst = pFirst->GetNext();
diff --git a/sw/source/core/inc/swcache.hxx b/sw/source/core/inc/swcache.hxx
index 63995eaa77c1..f4167dac97fe 100644
--- a/sw/source/core/inc/swcache.hxx
+++ b/sw/source/core/inc/swcache.hxx
@@ -61,10 +61,10 @@
class SwCacheObj;
-SV_DECL_PTRARR_DEL(SwCacheObjArr,SwCacheObj*,1)
-
-class SwCache : public SwCacheObjArr
+typedef std::vector<SwCacheObj*> SwCacheObjArr;
+class SwCache
{
+ SwCacheObjArr m_aCacheObjects;
std::vector<sal_uInt16> aFreePositions; //Freie Positionen fuer das Insert wenn
//die Maximalgrenze nicht erreicht ist.
//Immer wenn ein Objekt ausgetragen wird,
@@ -106,6 +106,7 @@ public:
//nur sal_uInt8 hineinstecken!!!
#ifdef DBG_UTIL
SwCache( const sal_uInt16 nInitSize, const rtl::OString &rNm );
+ // the destructor will free all objects still in the vector
~SwCache();
#else
SwCache( const sal_uInt16 nInitSize );
@@ -133,6 +134,8 @@ public:
inline SwCacheObj *First() { return pRealFirst; }
inline SwCacheObj *Last() { return pLast; }
inline SwCacheObj *Next( SwCacheObj *pCacheObj);
+ inline SwCacheObj* operator[](sal_uInt16 nIndex) { return m_aCacheObjects[nIndex]; }
+ inline sal_uInt16 size() { return m_aCacheObjects.size(); }
};
//Cache-Manipulation auf die sichere Art.
diff --git a/sw/source/core/layout/newfrm.cxx b/sw/source/core/layout/newfrm.cxx
index 40b4339a8933..2c01b92106ac 100644
--- a/sw/source/core/layout/newfrm.cxx
+++ b/sw/source/core/layout/newfrm.cxx
@@ -377,7 +377,7 @@ void _FrmFinit()
{
#if OSL_DEBUG_LEVEL > 0
// The cache may only contain null pointers at this time.
- for( sal_uInt16 n = SwFrm::GetCachePtr()->Count(); n; )
+ for( sal_uInt16 n = SwFrm::GetCachePtr()->size(); n; )
if( (*SwFrm::GetCachePtr())[ --n ] )
{
SwCacheObj* pObj = (*SwFrm::GetCachePtr())[ n ];