summaryrefslogtreecommitdiff
path: root/svx/source/unodraw/unomtabl.cxx
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/unodraw/unomtabl.cxx
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/unodraw/unomtabl.cxx')
-rw-r--r--svx/source/unodraw/unomtabl.cxx119
1 files changed, 57 insertions, 62 deletions
diff --git a/svx/source/unodraw/unomtabl.cxx b/svx/source/unodraw/unomtabl.cxx
index 01d639df58ed..0dc25307cfaa 100644
--- a/svx/source/unodraw/unomtabl.cxx
+++ b/svx/source/unodraw/unomtabl.cxx
@@ -231,30 +231,29 @@ void SAL_CALL SvxUnoMarkerTable::replaceByName( const OUString& aApiName, const
// if it is not in our own sets, modify the pool!
bool bFound = false;
- sal_uInt32 nSurrogate;
- const sal_uInt32 nStartCount = mpModelPool ? mpModelPool->GetItemCount2( XATTR_LINESTART ) : 0;
- for( nSurrogate = 0; nSurrogate < nStartCount; nSurrogate++ )
- {
- NameOrIndex *pItem = const_cast<NameOrIndex*>(static_cast<const NameOrIndex*>(mpModelPool->GetItem2( XATTR_LINESTART, nSurrogate)));
- if( pItem && pItem->GetName() == aName )
+ if (mpModelPool)
+ for (const SfxPoolItem* p : mpModelPool->GetItemSurrogates(XATTR_LINESTART))
{
- pItem->PutValue( aElement, 0 );
- bFound = true;
- break;
+ NameOrIndex *pItem = const_cast<NameOrIndex*>(static_cast<const NameOrIndex*>(p));
+ if( pItem && pItem->GetName() == aName )
+ {
+ pItem->PutValue( aElement, 0 );
+ bFound = true;
+ break;
+ }
}
- }
- const sal_uInt32 nEndCount = mpModelPool ? mpModelPool->GetItemCount2( XATTR_LINEEND ) : 0;
- for( nSurrogate = 0; nSurrogate < nEndCount; nSurrogate++ )
- {
- NameOrIndex *pItem = const_cast<NameOrIndex*>(static_cast<const NameOrIndex*>(mpModelPool->GetItem2( XATTR_LINEEND, nSurrogate)));
- if( pItem && pItem->GetName() == aName )
+ if (mpModelPool)
+ for (const SfxPoolItem* p : mpModelPool->GetItemSurrogates(XATTR_LINEEND))
{
- pItem->PutValue( aElement, 0 );
- bFound = true;
- break;
+ NameOrIndex *pItem = const_cast<NameOrIndex*>(static_cast<const NameOrIndex*>(p));
+ if( pItem && pItem->GetName() == aName )
+ {
+ pItem->PutValue( aElement, 0 );
+ bFound = true;
+ break;
+ }
}
- }
if( !bFound )
throw container::NoSuchElementException();
@@ -264,17 +263,17 @@ void SAL_CALL SvxUnoMarkerTable::replaceByName( const OUString& aApiName, const
static bool getByNameFromPool( const OUString& rSearchName, SfxItemPool const * pPool, sal_uInt16 nWhich, uno::Any& rAny )
{
- const sal_uInt32 nSurrogateCount = pPool ? pPool->GetItemCount2( nWhich ) : 0;
- for( sal_uInt32 nSurrogate = 0; nSurrogate < nSurrogateCount; nSurrogate++ )
- {
- const NameOrIndex *pItem = static_cast<const NameOrIndex*>(pPool->GetItem2( nWhich, nSurrogate ));
-
- if( pItem && pItem->GetName() == rSearchName )
+ if (pPool)
+ for (const SfxPoolItem* p : pPool->GetItemSurrogates(nWhich))
{
- pItem->QueryValue( rAny );
- return true;
+ const NameOrIndex *pItem = static_cast<const NameOrIndex*>(p);
+
+ if( pItem && pItem->GetName() == rSearchName )
+ {
+ pItem->QueryValue( rAny );
+ return true;
+ }
}
- }
return false;
}
@@ -308,11 +307,9 @@ uno::Any SAL_CALL SvxUnoMarkerTable::getByName( const OUString& aApiName )
static void createNamesForPool( SfxItemPool const * pPool, sal_uInt16 nWhich, std::set< OUString >& rNameSet )
{
- const sal_uInt32 nSuroCount = pPool->GetItemCount2( nWhich );
-
- for(sal_uInt32 nSurrogate = 0; nSurrogate < nSuroCount; ++nSurrogate)
+ for (const SfxPoolItem* p : pPool->GetItemSurrogates(nWhich))
{
- const NameOrIndex* pItem = static_cast<const NameOrIndex*>(pPool->GetItem2( nWhich, nSurrogate ));
+ const NameOrIndex* pItem = static_cast<const NameOrIndex*>(p);
if( pItem == nullptr || pItem->GetName().isEmpty() )
continue;
@@ -349,23 +346,22 @@ sal_Bool SAL_CALL SvxUnoMarkerTable::hasByName( const OUString& aName )
const NameOrIndex *pItem;
aSearchName = SvxUnogetInternalNameForItem(XATTR_LINESTART, aName);
- sal_uInt32 nStartCount = mpModelPool ? mpModelPool->GetItemCount2( XATTR_LINESTART ) : 0;
- sal_uInt32 nSurrogate;
- for( nSurrogate = 0; nSurrogate < nStartCount; nSurrogate++ )
- {
- pItem = static_cast<const NameOrIndex*>(mpModelPool->GetItem2( XATTR_LINESTART, nSurrogate));
- if( pItem && pItem->GetName() == aSearchName )
- return true;
- }
+ if (mpModelPool)
+ for (const SfxPoolItem* p : mpModelPool->GetItemSurrogates(XATTR_LINESTART))
+ {
+ pItem = static_cast<const NameOrIndex*>(p);
+ if( pItem && pItem->GetName() == aSearchName )
+ return true;
+ }
aSearchName = SvxUnogetInternalNameForItem(XATTR_LINEEND, aName);
- sal_uInt32 nEndCount = mpModelPool ? mpModelPool->GetItemCount2( XATTR_LINEEND ) : 0;
- for( nSurrogate = 0; nSurrogate < nEndCount; nSurrogate++ )
- {
- pItem = static_cast<const NameOrIndex*>(mpModelPool->GetItem2( XATTR_LINEEND, nSurrogate));
- if( pItem && pItem->GetName() == aSearchName )
- return true;
- }
+ if (mpModelPool)
+ for (const SfxPoolItem* p : mpModelPool->GetItemSurrogates(XATTR_LINEEND))
+ {
+ pItem = static_cast<const NameOrIndex*>(p);
+ if( pItem && pItem->GetName() == aSearchName )
+ return true;
+ }
return false;
}
@@ -382,22 +378,21 @@ sal_Bool SAL_CALL SvxUnoMarkerTable::hasElements( )
const NameOrIndex *pItem;
- const sal_uInt32 nStartCount = mpModelPool ? mpModelPool->GetItemCount2( XATTR_LINESTART ) : 0;
- sal_uInt32 nSurrogate;
- for( nSurrogate = 0; nSurrogate < nStartCount; nSurrogate++ )
- {
- pItem = static_cast<const NameOrIndex*>(mpModelPool->GetItem2( XATTR_LINESTART, nSurrogate));
- if( pItem && !pItem->GetName().isEmpty() )
- return true;
- }
+ if (mpModelPool)
+ for (const SfxPoolItem* p : mpModelPool->GetItemSurrogates(XATTR_LINESTART))
+ {
+ pItem = static_cast<const NameOrIndex*>(p);
+ if( pItem && !pItem->GetName().isEmpty() )
+ return true;
+ }
- const sal_uInt32 nEndCount = mpModelPool ? mpModelPool->GetItemCount2( XATTR_LINEEND ) : 0;
- for( nSurrogate = 0; nSurrogate < nEndCount; nSurrogate++ )
- {
- pItem = static_cast<const NameOrIndex*>(mpModelPool->GetItem2( XATTR_LINEEND, nSurrogate));
- if( pItem && !pItem->GetName().isEmpty() )
- return true;
- }
+ if (mpModelPool)
+ for (const SfxPoolItem* p : mpModelPool->GetItemSurrogates(XATTR_LINEEND))
+ {
+ pItem = static_cast<const NameOrIndex*>(p);
+ if( pItem && !pItem->GetName().isEmpty() )
+ return true;
+ }
return false;
}