[Libreoffice-commits] core.git: svl/source

Jochen Nitschke j.nitschke+logerrit at ok.de
Fri Sep 2 14:44:42 UTC 2016


 svl/source/inc/poolio.hxx     |    8 ++---
 svl/source/items/itempool.cxx |   58 +++++++++++++++++++++---------------------
 svl/source/items/poolio.cxx   |    6 +---
 3 files changed, 34 insertions(+), 38 deletions(-)

New commits:
commit bffce5c5c12deaa15bbd6484f30631f766ba2ee7
Author: Jochen Nitschke <j.nitschke+logerrit at ok.de>
Date:   Thu Sep 1 21:49:59 2016 +0200

    convert ppPoolDefaults to std::vector
    
    Change-Id: I13ba5b66f3ea70bae28181f580579c73a4353f68
    Reviewed-on: https://gerrit.libreoffice.org/28599
    Reviewed-by: Noel Grandin <noelgrandin at gmail.com>
    Tested-by: Jenkins <ci at libreoffice.org>

diff --git a/svl/source/inc/poolio.hxx b/svl/source/inc/poolio.hxx
index 4a32196..c33a494 100644
--- a/svl/source/inc/poolio.hxx
+++ b/svl/source/inc/poolio.hxx
@@ -91,7 +91,7 @@ struct SfxItemPool_Impl
     std::vector<SfxPoolItemArray_Impl*> maPoolItems;
     std::vector<SfxItemPoolUser*>   maSfxItemPoolUsers; /// ObjectUser section
     OUString                        aName;
-    SfxPoolItem**                   ppPoolDefaults;
+    std::vector<SfxPoolItem*>       maPoolDefaults;
     SfxPoolItem**                   ppStaticDefaults;
     SfxItemPool*                    mpMaster;
     SfxItemPool*                    mpSecondary;
@@ -114,7 +114,7 @@ struct SfxItemPool_Impl
     SfxItemPool_Impl( SfxItemPool* pMaster, const OUString& rName, sal_uInt16 nStart, sal_uInt16 nEnd )
         : maPoolItems(nEnd - nStart + 1, static_cast<SfxPoolItemArray_Impl*>(nullptr))
         , aName(rName)
-        , ppPoolDefaults(new SfxPoolItem* [nEnd - nStart + 1])
+        , maPoolDefaults(nEnd - nStart + 1)
         , ppStaticDefaults(nullptr)
         , mpMaster(pMaster)
         , mpSecondary(nullptr)
@@ -137,7 +137,6 @@ struct SfxItemPool_Impl
         , mbPersistentRefCounts(false)
     {
         DBG_ASSERT(mnStart, "Start-Which-Id must be greater 0" );
-        memset( ppPoolDefaults, 0, sizeof( SfxPoolItem* ) * (nEnd - nStart + 1));
     }
 
     ~SfxItemPool_Impl()
@@ -151,11 +150,10 @@ struct SfxItemPool_Impl
         for (; itr != itrEnd; ++itr)
             delete *itr;
         maPoolItems.clear();
+        maPoolDefaults.clear();
 
         delete[] mpPoolRanges;
         mpPoolRanges = nullptr;
-        delete[] ppPoolDefaults;
-        ppPoolDefaults = nullptr;
     }
 
     void readTheItems(SvStream & rStream, sal_uInt32 nCount, sal_uInt16 nVersion,
diff --git a/svl/source/items/itempool.cxx b/svl/source/items/itempool.cxx
index ecde96a..5d1b6a7 100644
--- a/svl/source/items/itempool.cxx
+++ b/svl/source/items/itempool.cxx
@@ -103,7 +103,7 @@ const SfxPoolItem* SfxItemPool::GetPoolDefaultItem( sal_uInt16 nWhich ) const
 {
     const SfxPoolItem* pRet;
     if( IsInRange( nWhich ) )
-        pRet = *(pImpl->ppPoolDefaults + GetIndex_Impl( nWhich ));
+        pRet = pImpl->maPoolDefaults[GetIndex_Impl(nWhich)];
     else if( pImpl->mpSecondary )
         pRet = pImpl->mpSecondary->GetPoolDefaultItem( nWhich );
     else
@@ -237,11 +237,11 @@ SfxItemPool::SfxItemPool
         SetDefaults( rPool.pImpl->ppStaticDefaults );
 
     // Copy Pool Defaults
-    for ( sal_uInt16 n = 0; n <= pImpl->mnEnd - pImpl->mnStart; ++n )
-        if ( (*( rPool.pImpl->ppPoolDefaults + n )) )
+    for (size_t n = 0; n < pImpl->maPoolDefaults.size(); ++n )
+        if (rPool.pImpl->maPoolDefaults[n])
         {
-            (*( pImpl->ppPoolDefaults + n )) = (*( rPool.pImpl->ppPoolDefaults + n ))->Clone(this);
-            (*( pImpl->ppPoolDefaults + n ))->SetKind( SFX_ITEMS_POOLDEFAULT );
+            pImpl->maPoolDefaults[n] = rPool.pImpl->maPoolDefaults[n]->Clone(this); //resets kind
+            pImpl->maPoolDefaults[n]->SetKind(SFX_ITEMS_POOLDEFAULT);
         }
 
     // Copy Version map
@@ -346,7 +346,7 @@ void SfxItemPool::ReleaseDefaults
 
 SfxItemPool::~SfxItemPool()
 {
-    if ( !pImpl->maPoolItems.empty() && pImpl->ppPoolDefaults )
+    if ( !pImpl->maPoolItems.empty() && !pImpl->maPoolDefaults.empty() )
         Delete();
 
     if (pImpl->mpMaster != nullptr && pImpl->mpMaster != this)
@@ -485,7 +485,7 @@ SfxItemPool* SfxItemPool::Clone() const
 void SfxItemPool::Delete()
 {
     // Already deleted?
-    if ( pImpl->maPoolItems.empty() || !pImpl->ppPoolDefaults )
+    if (pImpl->maPoolItems.empty() || pImpl->maPoolDefaults.empty())
         return;
 
     // Inform e.g. running Requests
@@ -494,7 +494,7 @@ void SfxItemPool::Delete()
     // Iterate through twice: first for the SetItems.
     // We separate this into two loops (for clarity's sake)
     std::vector<SfxPoolItemArray_Impl*>::iterator itrItemArr = pImpl->maPoolItems.begin();
-    SfxPoolItem** ppDefaultItem = pImpl->ppPoolDefaults;
+    auto itDefaultItem = pImpl->maPoolDefaults.begin();
     SfxPoolItem** ppStaticDefaultItem = pImpl->ppStaticDefaults;
     sal_uInt16 nArrCnt;
 
@@ -502,7 +502,7 @@ void SfxItemPool::Delete()
     if (pImpl->ppStaticDefaults != nullptr) {
         for ( nArrCnt = GetSize_Impl();
               nArrCnt;
-              --nArrCnt, ++itrItemArr, ++ppDefaultItem, ++ppStaticDefaultItem )
+              --nArrCnt, ++itrItemArr, ++itDefaultItem, ++ppStaticDefaultItem)
         {
             // *ppStaticDefaultItem could've already been deleted in a class derived
             // from SfxItemPool
@@ -522,24 +522,24 @@ void SfxItemPool::Delete()
                         }
                     DELETEZ( *itrItemArr );
                 }
-                if ( *ppDefaultItem )
+                if (*itDefaultItem)
                 {
 #ifdef DBG_UTIL
-                    SetRefCount( **ppDefaultItem, 0 );
+                    SetRefCount(**itDefaultItem, 0);
 #endif
-                    DELETEZ( *ppDefaultItem );
+                    DELETEZ(*itDefaultItem);
                 }
             }
         }
     }
 
     itrItemArr = pImpl->maPoolItems.begin();
-    ppDefaultItem = pImpl->ppPoolDefaults;
+    itDefaultItem = pImpl->maPoolDefaults.begin();
 
     // Now for the easy Items
     for ( nArrCnt = GetSize_Impl();
             nArrCnt;
-            --nArrCnt, ++itrItemArr, ++ppDefaultItem )
+            --nArrCnt, ++itrItemArr, ++itDefaultItem)
     {
         if ( *itrItemArr )
         {
@@ -554,12 +554,12 @@ void SfxItemPool::Delete()
                 }
             DELETEZ( *itrItemArr );
         }
-        if ( *ppDefaultItem )
+        if (*itDefaultItem)
         {
 #ifdef DBG_UTIL
-            SetRefCount( **ppDefaultItem, 0 );
+            SetRefCount(**itDefaultItem, 0);
 #endif
-            delete *ppDefaultItem;
+            DELETEZ(*itDefaultItem);
         }
     }
 
@@ -571,16 +571,16 @@ void SfxItemPool::SetPoolDefaultItem(const SfxPoolItem &rItem)
 {
     if ( IsInRange(rItem.Which()) )
     {
-        SfxPoolItem **ppOldDefault =
-            pImpl->ppPoolDefaults + GetIndex_Impl(rItem.Which());
+        auto& rOldDefault =
+            pImpl->maPoolDefaults[GetIndex_Impl(rItem.Which())];
         SfxPoolItem *pNewDefault = rItem.Clone(this);
         pNewDefault->SetKind(SFX_ITEMS_POOLDEFAULT);
-        if ( *ppOldDefault )
+        if (rOldDefault)
         {
-            (*ppOldDefault)->SetRefCount(0);
-            DELETEZ( *ppOldDefault );
+            rOldDefault->SetRefCount(0);
+            DELETEZ(rOldDefault);
         }
-        *ppOldDefault = pNewDefault;
+        rOldDefault = pNewDefault;
     }
     else if ( pImpl->mpSecondary )
         pImpl->mpSecondary->SetPoolDefaultItem(rItem);
@@ -598,12 +598,12 @@ void SfxItemPool::ResetPoolDefaultItem( sal_uInt16 nWhichId )
 {
     if ( IsInRange(nWhichId) )
     {
-        SfxPoolItem **ppOldDefault =
-            pImpl->ppPoolDefaults + GetIndex_Impl( nWhichId );
-        if ( *ppOldDefault )
+        auto& rOldDefault =
+            pImpl->maPoolDefaults[GetIndex_Impl(nWhichId)];
+        if (rOldDefault)
         {
-            (*ppOldDefault)->SetRefCount(0);
-            DELETEZ( *ppOldDefault );
+            rOldDefault->SetRefCount(0);
+            DELETEZ(rOldDefault);
         }
     }
     else if ( pImpl->mpSecondary )
@@ -844,7 +844,7 @@ const SfxPoolItem& SfxItemPool::GetDefaultItem( sal_uInt16 nWhich ) const
 
     DBG_ASSERT( pImpl->ppStaticDefaults, "no defaults known - don't ask me for defaults" );
     sal_uInt16 nPos = GetIndex_Impl(nWhich);
-    SfxPoolItem *pDefault = *(pImpl->ppPoolDefaults + nPos);
+    SfxPoolItem* pDefault = pImpl->maPoolDefaults[nPos];
     if ( pDefault )
         return *pDefault;
     return **(pImpl->ppStaticDefaults + nPos);
diff --git a/svl/source/items/poolio.cxx b/svl/source/items/poolio.cxx
index ae7eb18..1fbf5ce 100644
--- a/svl/source/items/poolio.cxx
+++ b/svl/source/items/poolio.cxx
@@ -254,10 +254,8 @@ SvStream &SfxItemPool::Store(SvStream &rStream) const
     if ( !rStream.GetError() )
     {
         SfxMultiMixRecordWriter aDefsRec( &rStream, SFX_ITEMPOOL_REC_DEFAULTS );
-        sal_uInt16 nCount = GetSize_Impl();
-        for ( sal_uInt16 n = 0; n < nCount; ++n )
+        for (const SfxPoolItem* pDefaultItem : pImpl->maPoolDefaults)
         {
-            const SfxPoolItem* pDefaultItem = pImpl->ppPoolDefaults[n];
             if ( pDefaultItem )
             {
                 // Get version
@@ -695,7 +693,7 @@ SvStream &SfxItemPool::Load(SvStream &rStream)
                     ( *( pImpl->ppStaticDefaults + GetIndex_Impl(nWhich) ) )
                     ->Create( rStream, nVersion );
             pItem->SetKind( SFX_ITEMS_POOLDEFAULT );
-            *( pImpl->ppPoolDefaults + GetIndex_Impl(nWhich) ) = pItem;
+            pImpl->maPoolDefaults[GetIndex_Impl(nWhich)] = pItem;
         }
     }
 


More information about the Libreoffice-commits mailing list