diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-04-12 15:40:12 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-04-16 08:22:30 +0200 |
commit | 3d44b720f58366398e7f59c00dba6339712a670f (patch) | |
tree | 452e2be1ea47d4ea5e903c05705ffb6e52ef8577 /svl | |
parent | 73c29a2978f967d317235d524aad535a6bafbff0 (diff) |
loplugin:useuniqueptr in SfxItemPool_Impl
Change-Id: Ic3d695dd3ad4ee5ca6537f65d643d8736e3a5700
Reviewed-on: https://gerrit.libreoffice.org/52886
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'svl')
-rw-r--r-- | svl/qa/unit/items/test_itempool.cxx | 2 | ||||
-rw-r--r-- | svl/source/inc/poolio.hxx | 10 | ||||
-rw-r--r-- | svl/source/items/itempool.cxx | 24 | ||||
-rw-r--r-- | svl/source/items/itemset.cxx | 2 | ||||
-rw-r--r-- | svl/source/items/poolio.cxx | 2 |
5 files changed, 17 insertions, 23 deletions
diff --git a/svl/qa/unit/items/test_itempool.cxx b/svl/qa/unit/items/test_itempool.cxx index a3132be80b0a..cde5dee62f2c 100644 --- a/svl/qa/unit/items/test_itempool.cxx +++ b/svl/qa/unit/items/test_itempool.cxx @@ -80,7 +80,7 @@ void PoolItemTest::testPool() } // Test rehash - for (SfxPoolItemArray_Impl *pSlice : pImpl->maPoolItems) + for (auto & pSlice : pImpl->maPoolItems) { if (pSlice) pSlice->ReHash(); diff --git a/svl/source/inc/poolio.hxx b/svl/source/inc/poolio.hxx index 538c89994603..359b88c863dd 100644 --- a/svl/source/inc/poolio.hxx +++ b/svl/source/inc/poolio.hxx @@ -71,14 +71,14 @@ public: struct SfxItemPool_Impl { SfxBroadcaster aBC; - std::vector<SfxPoolItemArray_Impl*> maPoolItems; + std::vector<std::unique_ptr<SfxPoolItemArray_Impl>> maPoolItems; std::vector<SfxItemPoolUser*> maSfxItemPoolUsers; /// ObjectUser section OUString aName; std::vector<SfxPoolItem*> maPoolDefaults; std::vector<SfxPoolItem*>* mpStaticDefaults; SfxItemPool* mpMaster; SfxItemPool* mpSecondary; - sal_uInt16* mpPoolRanges; + std::unique_ptr<sal_uInt16[]> mpPoolRanges; sal_uInt16 mnStart; sal_uInt16 mnEnd; MapUnit eDefMetric; @@ -105,13 +105,9 @@ struct SfxItemPool_Impl void DeleteItems() { - for (auto pPoolItemArray : maPoolItems) - delete pPoolItemArray; maPoolItems.clear(); maPoolDefaults.clear(); - - delete[] mpPoolRanges; - mpPoolRanges = nullptr; + mpPoolRanges.reset(); } // unit testing diff --git a/svl/source/items/itempool.cxx b/svl/source/items/itempool.cxx index 07eab0ab3435..76e9d90b485f 100644 --- a/svl/source/items/itempool.cxx +++ b/svl/source/items/itempool.cxx @@ -620,11 +620,11 @@ const SfxPoolItem& SfxItemPool::Put( const SfxPoolItem& rItem, sal_uInt16 nWhich typeid(rItem) == typeid(GetDefaultItem(nWhich))); const sal_uInt16 nIndex = GetIndex_Impl(nWhich); - SfxPoolItemArray_Impl* pItemArr = pImpl->maPoolItems[nIndex]; + SfxPoolItemArray_Impl* pItemArr = pImpl->maPoolItems[nIndex].get(); if (!pItemArr) { - pImpl->maPoolItems[nIndex] = new SfxPoolItemArray_Impl; - pItemArr = pImpl->maPoolItems[nIndex]; + pImpl->maPoolItems[nIndex].reset(new SfxPoolItemArray_Impl); + pItemArr = pImpl->maPoolItems[nIndex].get(); } std::vector<SfxPoolItem*>::iterator ppFree; @@ -753,7 +753,7 @@ void SfxItemPool::Remove( const SfxPoolItem& rItem ) return; // Find Item in own Pool - SfxPoolItemArray_Impl* pItemArr = pImpl->maPoolItems[nIndex]; + SfxPoolItemArray_Impl* pItemArr = pImpl->maPoolItems[nIndex].get(); assert(pItemArr && "removing Item not in Pool"); SfxPoolItemArray_Impl::PoolItemPtrToIndexMap::const_iterator it; @@ -826,7 +826,7 @@ void SfxItemPool::FreezeIdRanges() } -void SfxItemPool::FillItemIdRanges_Impl( sal_uInt16*& pWhichRanges ) const +void SfxItemPool::FillItemIdRanges_Impl( std::unique_ptr<sal_uInt16[]>& pWhichRanges ) const { DBG_ASSERT( !pImpl->mpPoolRanges, "GetFrozenRanges() would be faster!" ); @@ -835,20 +835,20 @@ void SfxItemPool::FillItemIdRanges_Impl( sal_uInt16*& pWhichRanges ) const for( pPool = this; pPool; pPool = pPool->pImpl->mpSecondary ) ++nLevel; - pWhichRanges = new sal_uInt16[ 2*nLevel + 1 ]; + pWhichRanges.reset(new sal_uInt16[ 2*nLevel + 1 ]); nLevel = 0; for( pPool = this; pPool; pPool = pPool->pImpl->mpSecondary ) { - *(pWhichRanges+(nLevel++)) = pPool->pImpl->mnStart; - *(pWhichRanges+(nLevel++)) = pPool->pImpl->mnEnd; - *(pWhichRanges+nLevel) = 0; + pWhichRanges[nLevel++] = pPool->pImpl->mnStart; + pWhichRanges[nLevel++] = pPool->pImpl->mnEnd; + pWhichRanges[nLevel] = 0; } } const sal_uInt16* SfxItemPool::GetFrozenIdRanges() const { - return pImpl->mpPoolRanges; + return pImpl->mpPoolRanges.get(); } const SfxPoolItem *SfxItemPool::GetItem2Default(sal_uInt16 nWhich) const @@ -870,7 +870,7 @@ const SfxPoolItem *SfxItemPool::GetItem2(sal_uInt16 nWhich, sal_uInt32 nOfst) co if ( nOfst == SFX_ITEMS_DEFAULT ) return (*pImpl->mpStaticDefaults)[ GetIndex_Impl(nWhich) ]; - SfxPoolItemArray_Impl* pItemArr = pImpl->maPoolItems[GetIndex_Impl(nWhich)]; + SfxPoolItemArray_Impl* pItemArr = pImpl->maPoolItems[GetIndex_Impl(nWhich)].get(); if( pItemArr && nOfst < pItemArr->size() ) return (*pItemArr)[nOfst]; @@ -887,7 +887,7 @@ sal_uInt32 SfxItemPool::GetItemCount2(sal_uInt16 nWhich) const return 0; } - SfxPoolItemArray_Impl* pItemArr = pImpl->maPoolItems[GetIndex_Impl(nWhich)]; + SfxPoolItemArray_Impl* pItemArr = pImpl->maPoolItems[GetIndex_Impl(nWhich)].get(); if ( pItemArr ) return pItemArr->size(); return 0; diff --git a/svl/source/items/itemset.cxx b/svl/source/items/itemset.cxx index 784e23a33e22..e967089e17ee 100644 --- a/svl/source/items/itemset.cxx +++ b/svl/source/items/itemset.cxx @@ -94,8 +94,6 @@ SfxItemSet::SfxItemSet(SfxItemPool& rPool) { m_pWhichRanges = const_cast<sal_uInt16*>(m_pPool->GetFrozenIdRanges()); assert( m_pWhichRanges && "don't create ItemSets with full range before FreezeIdRanges()" ); - if (!m_pWhichRanges) - m_pPool->FillItemIdRanges_Impl( m_pWhichRanges ); const sal_uInt16 nSize = TotalCount(); m_pItems.reset(new const SfxPoolItem*[nSize]{}); diff --git a/svl/source/items/poolio.cxx b/svl/source/items/poolio.cxx index 4d73a8af581f..c73e85c2b0ac 100644 --- a/svl/source/items/poolio.cxx +++ b/svl/source/items/poolio.cxx @@ -104,7 +104,7 @@ bool SfxItemPool::CheckItemInPool(const SfxPoolItem *pItem) const if( IsStaticDefaultItem(pItem) || IsPoolDefaultItem(pItem) ) return true; - SfxPoolItemArray_Impl* pItemArr = pImpl->maPoolItems[GetIndex_Impl(pItem->Which())]; + SfxPoolItemArray_Impl* pItemArr = pImpl->maPoolItems[GetIndex_Impl(pItem->Which())].get(); DBG_ASSERT(pItemArr, "ItemArr is not available"); for ( size_t i = 0; i < pItemArr->size(); ++i ) |