Kaydet (Commit) 3d44b720 authored tarafından Noel Grandin's avatar Noel Grandin

loplugin:useuniqueptr in SfxItemPool_Impl

Change-Id: Ic3d695dd3ad4ee5ca6537f65d643d8736e3a5700
Reviewed-on: https://gerrit.libreoffice.org/52886Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 73c29a29
......@@ -77,7 +77,7 @@ private:
public:
// for default SfxItemSet::CTOR, set default WhichRanges
void FillItemIdRanges_Impl( sal_uInt16*& pWhichRanges ) const;
void FillItemIdRanges_Impl( std::unique_ptr<sal_uInt16[]>& pWhichRanges ) const;
const sal_uInt16* GetFrozenIdRanges() const;
protected:
......
......@@ -80,7 +80,7 @@ void PoolItemTest::testPool()
}
// Test rehash
for (SfxPoolItemArray_Impl *pSlice : pImpl->maPoolItems)
for (auto & pSlice : pImpl->maPoolItems)
{
if (pSlice)
pSlice->ReHash();
......
......@@ -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
......
......@@ -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;
......
......@@ -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]{});
......
......@@ -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 )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment