summaryrefslogtreecommitdiff
path: root/svx/source/xoutdev
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2019-04-17 15:19:25 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2019-04-20 08:02:25 +0200
commitec7ba61a6164c805f5a71b077715b7e1521a2d62 (patch)
tree4d4f3fb1ad960465897754601b0842c78db564bf /svx/source/xoutdev
parent7d58f26bf4dbeb4e138c2a91f039d8bc7fa00f0c (diff)
simplify SfxPoolItemArray_Impl (tdf#81765 related)
Since we want to look up items by pointer, just store them in a std::unordered_set, which allows fast find(). This dramatically simplifies most operations on this data structure. Fix a dodgy sd test that was relying on items with the same whichid being in the pool being in a certain order. Change-Id: I4d79fc718f95e3083a20788be1050fbe9fca7263 Reviewed-on: https://gerrit.libreoffice.org/70881 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'svx/source/xoutdev')
-rw-r--r--svx/source/xoutdev/xattr.cxx98
1 files changed, 35 insertions, 63 deletions
diff --git a/svx/source/xoutdev/xattr.cxx b/svx/source/xoutdev/xattr.cxx
index de1717d293f7..0830a9055f11 100644
--- a/svx/source/xoutdev/xattr.cxx
+++ b/svx/source/xoutdev/xattr.cxx
@@ -128,17 +128,15 @@ OUString NameOrIndex::CheckNamedItem( const NameOrIndex* pCheckItem, const sal_u
if (!aUniqueName.isEmpty() && pPool1)
{
- const sal_uInt32 nCount = pPool1->GetItemCount2( nWhich );
-
- for( sal_uInt32 nSurrogate = 0; nSurrogate < nCount; nSurrogate++ )
+ for (const SfxPoolItem* pItem : pPool1->GetItemSurrogates(nWhich))
{
- const NameOrIndex *pItem = static_cast<const NameOrIndex*>(pPool1->GetItem2( nWhich, nSurrogate ));
+ const NameOrIndex *pNameOrIndex = static_cast<const NameOrIndex*>(pItem);
- if( pItem && ( pItem->GetName() == pCheckItem->GetName() ) )
+ if( pNameOrIndex->GetName() == pCheckItem->GetName() )
{
// if there is already an item with the same name and the same
// value it's ok to set it
- if( !pCompareValueFunc( pItem, pCheckItem ) )
+ if( !pCompareValueFunc( pNameOrIndex, pCheckItem ) )
{
// same name but different value, we need a new name for this item
aUniqueName.clear();
@@ -215,20 +213,18 @@ OUString NameOrIndex::CheckNamedItem( const NameOrIndex* pCheckItem, const sal_u
if (aUniqueName.isEmpty() && pPool1)
{
- const sal_uInt32 nCount = pPool1->GetItemCount2( nWhich );
- const NameOrIndex *pItem;
- for( sal_uInt32 nSurrogate = 0; nSurrogate < nCount; nSurrogate++ )
+ for (const SfxPoolItem* pItem : pPool1->GetItemSurrogates(nWhich))
{
- pItem = static_cast<const NameOrIndex*>(pPool1->GetItem2( nWhich, nSurrogate ));
+ const NameOrIndex *pNameOrIndex = static_cast<const NameOrIndex*>(pItem);
- if( pItem && !pItem->GetName().isEmpty() )
+ if( !pNameOrIndex->GetName().isEmpty() )
{
- if( !bForceNew && pCompareValueFunc( pItem, pCheckItem ) )
- return pItem->GetName();
+ if( !bForceNew && pCompareValueFunc( pNameOrIndex, pCheckItem ) )
+ return pNameOrIndex->GetName();
- if( pItem->GetName().startsWith( aUser ) )
+ if( pNameOrIndex->GetName().startsWith( aUser ) )
{
- sal_Int32 nThisIndex = pItem->GetName().copy( aUser.getLength() ).toInt32();
+ sal_Int32 nThisIndex = pNameOrIndex->GetName().copy( aUser.getLength() ).toInt32();
if( nThisIndex >= nUserIndex )
nUserIndex = nThisIndex + 1;
}
@@ -1098,16 +1094,12 @@ std::unique_ptr<XLineStartItem> XLineStartItem::checkForUniqueItem( SdrModel* pM
// 2. if we have a name check if there is already an item with the
// same name in the documents pool with a different line end or start
- sal_uInt32 nCount, nSurrogate;
-
const SfxItemPool& rPool1 = pModel->GetItemPool();
if (!aUniqueName.isEmpty())
{
- nCount = rPool1.GetItemCount2(XATTR_LINESTART);
-
- for( nSurrogate = 0; nSurrogate < nCount; nSurrogate++ )
+ for (const SfxPoolItem* p : rPool1.GetItemSurrogates(XATTR_LINESTART))
{
- const XLineStartItem* pItem = rPool1.GetItem2(XATTR_LINESTART, nSurrogate);
+ auto pItem = dynamic_cast<const XLineStartItem*>(p);
if( pItem && ( pItem->GetName() == pLineStartItem->GetName() ) )
{
@@ -1125,11 +1117,9 @@ std::unique_ptr<XLineStartItem> XLineStartItem::checkForUniqueItem( SdrModel* pM
if( !bForceNew )
{
- nCount = rPool1.GetItemCount2(XATTR_LINEEND);
-
- for( nSurrogate = 0; nSurrogate < nCount; nSurrogate++ )
+ for (const SfxPoolItem* p : rPool1.GetItemSurrogates(XATTR_LINEEND))
{
- const XLineEndItem* pItem = rPool1.GetItem2(XATTR_LINEEND, nSurrogate);
+ auto pItem = dynamic_cast<const XLineEndItem*>(p);
if( pItem && ( pItem->GetName() == pLineStartItem->GetName() ) )
{
@@ -1150,10 +1140,9 @@ std::unique_ptr<XLineStartItem> XLineStartItem::checkForUniqueItem( SdrModel* pM
const SfxItemPool* pPool2 = pModel->GetStyleSheetPool() ? &pModel->GetStyleSheetPool()->GetPool() : nullptr;
if( !aUniqueName.isEmpty() && pPool2)
{
- nCount = pPool2->GetItemCount2( XATTR_LINESTART );
- for( nSurrogate = 0; nSurrogate < nCount; nSurrogate++ )
+ for (const SfxPoolItem* p : pPool2->GetItemSurrogates(XATTR_LINESTART))
{
- const XLineStartItem* pItem = pPool2->GetItem2( XATTR_LINESTART, nSurrogate );
+ auto pItem = dynamic_cast<const XLineStartItem*>(p);
if( pItem && ( pItem->GetName() == pLineStartItem->GetName() ) )
{
@@ -1171,10 +1160,9 @@ std::unique_ptr<XLineStartItem> XLineStartItem::checkForUniqueItem( SdrModel* pM
if( !bForceNew )
{
- nCount = pPool2->GetItemCount2( XATTR_LINEEND );
- for( nSurrogate = 0; nSurrogate < nCount; nSurrogate++ )
+ for (const SfxPoolItem* p : pPool2->GetItemSurrogates(XATTR_LINEEND))
{
- const XLineEndItem* pItem = pPool2->GetItem2( XATTR_LINEEND, nSurrogate );
+ auto pItem = dynamic_cast<const XLineEndItem*>(p);
if( pItem && ( pItem->GetName() == pLineStartItem->GetName() ) )
{
@@ -1201,12 +1189,9 @@ std::unique_ptr<XLineStartItem> XLineStartItem::checkForUniqueItem( SdrModel* pM
sal_Int32 nUserIndex = 1;
const OUString aUser(SvxResId(RID_SVXSTR_LINEEND));
- nCount = rPool1.GetItemCount2(XATTR_LINESTART);
- sal_uInt32 nSurrogate2;
-
- for (nSurrogate2 = 0; nSurrogate2 < nCount; nSurrogate2++)
+ for (const SfxPoolItem* p : rPool1.GetItemSurrogates(XATTR_LINESTART))
{
- const XLineStartItem* pItem = rPool1.GetItem2(XATTR_LINESTART, nSurrogate2);
+ auto pItem = dynamic_cast<const XLineStartItem*>(p);
if (pItem && !pItem->GetName().isEmpty())
{
@@ -1226,10 +1211,9 @@ std::unique_ptr<XLineStartItem> XLineStartItem::checkForUniqueItem( SdrModel* pM
}
}
- nCount = rPool1.GetItemCount2(XATTR_LINEEND);
- for (nSurrogate2 = 0; nSurrogate2 < nCount; nSurrogate2++)
+ for (const SfxPoolItem* p : rPool1.GetItemSurrogates(XATTR_LINEEND))
{
- const XLineEndItem* pItem = rPool1.GetItem2(XATTR_LINEEND, nSurrogate2);
+ auto pItem = dynamic_cast<const XLineEndItem*>(p);
if (pItem && !pItem->GetName().isEmpty())
{
@@ -1349,16 +1333,12 @@ std::unique_ptr<XLineEndItem> XLineEndItem::checkForUniqueItem( SdrModel* pModel
// 2. if we have a name check if there is already an item with the
// same name in the documents pool with a different line end or start
- sal_uInt16 nCount, nSurrogate;
-
const SfxItemPool& rPool1 = pModel->GetItemPool();
if (!aUniqueName.isEmpty())
{
- nCount = rPool1.GetItemCount2(XATTR_LINESTART);
-
- for( nSurrogate = 0; nSurrogate < nCount; nSurrogate++ )
+ for (const SfxPoolItem* p : rPool1.GetItemSurrogates(XATTR_LINESTART))
{
- const XLineStartItem* pItem = rPool1.GetItem2(XATTR_LINESTART, nSurrogate);
+ auto pItem = dynamic_cast<const XLineStartItem*>(p);
if( pItem && ( pItem->GetName() == pLineEndItem->GetName() ) )
{
@@ -1376,11 +1356,9 @@ std::unique_ptr<XLineEndItem> XLineEndItem::checkForUniqueItem( SdrModel* pModel
if( !bForceNew )
{
- nCount = rPool1.GetItemCount2(XATTR_LINEEND);
-
- for( nSurrogate = 0; nSurrogate < nCount; nSurrogate++ )
+ for (const SfxPoolItem* p : rPool1.GetItemSurrogates(XATTR_LINEEND))
{
- const XLineEndItem* pItem = rPool1.GetItem2(XATTR_LINEEND, nSurrogate);
+ auto pItem = dynamic_cast<const XLineEndItem*>(p);
if( pItem && ( pItem->GetName() == pLineEndItem->GetName() ) )
{
@@ -1401,10 +1379,9 @@ std::unique_ptr<XLineEndItem> XLineEndItem::checkForUniqueItem( SdrModel* pModel
const SfxItemPool* pPool2 = pModel->GetStyleSheetPool() ? &pModel->GetStyleSheetPool()->GetPool() : nullptr;
if( !aUniqueName.isEmpty() && pPool2)
{
- nCount = pPool2->GetItemCount2( XATTR_LINESTART );
- for( nSurrogate = 0; nSurrogate < nCount; nSurrogate++ )
+ for (const SfxPoolItem* p : pPool2->GetItemSurrogates(XATTR_LINESTART))
{
- const XLineStartItem* pItem = pPool2->GetItem2( XATTR_LINESTART, nSurrogate );
+ auto pItem = dynamic_cast<const XLineStartItem*>(p);
if( pItem && ( pItem->GetName() == pLineEndItem->GetName() ) )
{
@@ -1422,10 +1399,9 @@ std::unique_ptr<XLineEndItem> XLineEndItem::checkForUniqueItem( SdrModel* pModel
if( !bForceNew )
{
- nCount = pPool2->GetItemCount2( XATTR_LINEEND );
- for( nSurrogate = 0; nSurrogate < nCount; nSurrogate++ )
+ for (const SfxPoolItem* p : pPool2->GetItemSurrogates(XATTR_LINEEND))
{
- const XLineEndItem* pItem = pPool2->GetItem2( XATTR_LINEEND, nSurrogate );
+ auto pItem = dynamic_cast<const XLineEndItem*>(p);
if( pItem && ( pItem->GetName() == pLineEndItem->GetName() ) )
{
@@ -1452,12 +1428,9 @@ std::unique_ptr<XLineEndItem> XLineEndItem::checkForUniqueItem( SdrModel* pModel
sal_Int32 nUserIndex = 1;
const OUString aUser(SvxResId(RID_SVXSTR_LINEEND));
- nCount = rPool1.GetItemCount2(XATTR_LINESTART);
- sal_uInt32 nSurrogate2;
-
- for (nSurrogate2 = 0; nSurrogate2 < nCount; nSurrogate2++)
+ for (const SfxPoolItem* p : rPool1.GetItemSurrogates(XATTR_LINESTART))
{
- const XLineStartItem* pItem = rPool1.GetItem2(XATTR_LINESTART, nSurrogate2);
+ auto pItem = dynamic_cast<const XLineStartItem*>(p);
if (pItem && !pItem->GetName().isEmpty())
{
@@ -1477,10 +1450,9 @@ std::unique_ptr<XLineEndItem> XLineEndItem::checkForUniqueItem( SdrModel* pModel
}
}
- nCount = rPool1.GetItemCount2(XATTR_LINEEND);
- for (nSurrogate2 = 0; nSurrogate2 < nCount; nSurrogate2++)
+ for (const SfxPoolItem* p : rPool1.GetItemSurrogates(XATTR_LINEEND))
{
- const XLineEndItem* pItem = rPool1.GetItem2(XATTR_LINEEND, nSurrogate2);
+ auto pItem = dynamic_cast<const XLineEndItem*>(p);
if (pItem && !pItem->GetName().isEmpty())
{