include/svl/itempool.hxx           |    3 +
 svl/source/items/itempool.cxx      |   16 +++++++-
 svx/source/unodraw/unomtabl.cxx    |   28 +++++++-------
 svx/source/xoutdev/xattr.cxx       |   72 ++++++++++++++++++-------------------
 sw/source/filter/ww8/rtfexport.cxx |    2 -
 5 files changed, 67 insertions(+), 54 deletions(-)

New commits:
commit 847738e5a93f63ead959a7cc60d65fd55737fee7
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Mon Jul 29 11:36:23 2024 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Mon Jul 29 13:48:02 2024 +0200

    use more GetItemSurrogatesForItem
    
    since it is considerably more efficient
    
    Change-Id: I224ff890f6dd52481621b46f912f1e8dbf65126c
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171182
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>
    Tested-by: Jenkins

diff --git a/include/svl/itempool.hxx b/include/svl/itempool.hxx
index 030a09d0f688..873d56bc0e75 100644
--- a/include/svl/itempool.hxx
+++ b/include/svl/itempool.hxx
@@ -321,8 +321,9 @@ public:
     // Read commit text for more information
     void GetItemSurrogates(ItemSurrogates& rTarget, sal_uInt16 nWhich) const;
 
-    // special version for read-oly itemSurrogates for NameOrIndex Items
+    // special version for read-only itemSurrogates for NameOrIndex Items
     void GetItemSurrogatesForItem(ItemSurrogates& rTarget, const SfxPoolItem& 
rItem) const;
+    void GetItemSurrogatesForItem(ItemSurrogates& rTarget, SfxItemType 
eItemType) const;
 
     sal_uInt16 GetFirstWhich() const { return mnStart; }
     sal_uInt16 GetLastWhich() const { return mnEnd; }
diff --git a/svl/source/items/itempool.cxx b/svl/source/items/itempool.cxx
index f624eb0aded9..8471e2050d19 100644
--- a/svl/source/items/itempool.cxx
+++ b/svl/source/items/itempool.cxx
@@ -882,19 +882,31 @@ void SfxItemPool::iterateItemSurrogates(
     }
 }
 
+void SfxItemPool::GetItemSurrogatesForItem(ItemSurrogates& rTarget, 
SfxItemType eItemType) const
+{
+    rTarget.clear();
+    const registeredNameOrIndex& 
rRegistered(GetMasterPool()->maRegisteredNameOrIndex);
+    registeredNameOrIndex::const_iterator aHit(rRegistered.find(eItemType));
+    if (aHit != rRegistered.end())
+    {
+        rTarget.reserve(aHit->second.size());
+        for (const auto& entry : aHit->second)
+            rTarget.push_back(entry.first);
+    }
+}
+
 void SfxItemPool::GetItemSurrogatesForItem(ItemSurrogates& rTarget, const 
SfxPoolItem& rItem) const
 {
     assert(rItem.isNameOrIndex() && "ITEM: only Items derived from NameOrIndex 
supported for this mechanism (!)");
+    rTarget.clear();
     const registeredNameOrIndex& 
rRegistered(GetMasterPool()->maRegisteredNameOrIndex);
     registeredNameOrIndex::const_iterator 
aHit(rRegistered.find(rItem.ItemType()));
     if (aHit != rRegistered.end())
     {
-        rTarget.clear();
         rTarget.reserve(aHit->second.size());
         for (const auto& entry : aHit->second)
             rTarget.push_back(entry.first);
     }
-        // rTarget = ItemSurrogates(aHit->second.begin(), aHit->second.end());
 }
 
 void SfxItemPool::GetItemSurrogates(ItemSurrogates& rTarget, sal_uInt16 
nWhich) const
diff --git a/svx/source/unodraw/unomtabl.cxx b/svx/source/unodraw/unomtabl.cxx
index 988b6da01e5f..236ba81ac774 100644
--- a/svx/source/unodraw/unomtabl.cxx
+++ b/svx/source/unodraw/unomtabl.cxx
@@ -285,17 +285,17 @@ void SAL_CALL SvxUnoMarkerTable::replaceByName( const 
OUString& aApiName, const
     ImplInsertByName( aName, aElement );
 }
 
-static bool getByNameFromPool( std::u16string_view rSearchName, SfxItemPool 
const * pPool, sal_uInt16 nWhich, uno::Any& rAny )
+static bool getByNameFromPool( std::u16string_view rSearchName, SfxItemPool 
const * pPool, SfxItemType eItemType, uno::Any& rAny )
 {
     if (pPool)
     {
         ItemSurrogates aSurrogates;
-        pPool->GetItemSurrogates(aSurrogates, nWhich);
+        pPool->GetItemSurrogatesForItem(aSurrogates, eItemType);
         for (const SfxPoolItem* p : aSurrogates)
         {
             const NameOrIndex *pItem = static_cast<const NameOrIndex*>(p);
 
-            if( pItem && pItem->GetName() == rSearchName )
+            if( pItem->GetName() == rSearchName )
             {
                 pItem->QueryValue( rAny );
                 return true;
@@ -319,10 +319,10 @@ uno::Any SAL_CALL SvxUnoMarkerTable::getByName( const 
OUString& aApiName )
     {
         do
         {
-            if (getByNameFromPool(aName, mpModelPool, XATTR_LINESTART, aAny))
+            if (getByNameFromPool(aName, mpModelPool, 
SfxItemType::XLineStartItemType, aAny)) // XATTR_LINESTART
                 break;
 
-            if (getByNameFromPool(aName, mpModelPool, XATTR_LINEEND, aAny))
+            if (getByNameFromPool(aName, mpModelPool, 
SfxItemType::XLineEndItemType, aAny)) // XATTR_LINEEND
                 break;
 
             throw container::NoSuchElementException();
@@ -333,15 +333,15 @@ uno::Any SAL_CALL SvxUnoMarkerTable::getByName( const 
OUString& aApiName )
     return aAny;
 }
 
-static void createNamesForPool( SfxItemPool const * pPool, sal_uInt16 nWhich, 
std::set< OUString >& rNameSet )
+static void createNamesForPool( SfxItemPool const * pPool, SfxItemType 
eItemType, std::set< OUString >& rNameSet )
 {
     ItemSurrogates aSurrogates;
-    pPool->GetItemSurrogates(aSurrogates, nWhich);
+    pPool->GetItemSurrogatesForItem(aSurrogates, eItemType);
     for (const SfxPoolItem* p : aSurrogates)
     {
         const NameOrIndex* pItem = static_cast<const NameOrIndex*>(p);
 
-        if( pItem == nullptr || pItem->GetName().isEmpty() )
+        if( pItem->GetName().isEmpty() )
             continue;
 
         OUString aName = SvxUnogetApiNameForItem(XATTR_LINEEND, 
pItem->GetName());
@@ -356,10 +356,10 @@ uno::Sequence< OUString > SAL_CALL 
SvxUnoMarkerTable::getElementNames()
     std::set< OUString > aNameSet;
 
     // search model pool for line starts
-    createNamesForPool( mpModelPool, XATTR_LINESTART, aNameSet );
+    createNamesForPool( mpModelPool, SfxItemType::XLineStartItemType, aNameSet 
); // XATTR_LINESTART
 
     // search model pool for line ends
-    createNamesForPool( mpModelPool, XATTR_LINEEND, aNameSet );
+    createNamesForPool( mpModelPool, SfxItemType::XLineEndItemType, aNameSet 
); // XATTR_LINEEND
 
     return comphelper::containerToSequence(aNameSet);
 }
@@ -379,7 +379,7 @@ sal_Bool SAL_CALL SvxUnoMarkerTable::hasByName( const 
OUString& aName )
     if (mpModelPool)
     {
         ItemSurrogates aSurrogates;
-        mpModelPool->GetItemSurrogates(aSurrogates, XATTR_LINESTART);
+        mpModelPool->GetItemSurrogatesForItem(aSurrogates, 
SfxItemType::XLineStartItemType); // XATTR_LINESTART
         for (const SfxPoolItem* p : aSurrogates)
         {
             pItem = static_cast<const NameOrIndex*>(p);
@@ -392,7 +392,7 @@ sal_Bool SAL_CALL SvxUnoMarkerTable::hasByName( const 
OUString& aName )
     if (mpModelPool)
     {
         ItemSurrogates aSurrogates;
-        mpModelPool->GetItemSurrogates(aSurrogates, XATTR_LINEEND);
+        mpModelPool->GetItemSurrogatesForItem(aSurrogates, 
SfxItemType::XLineEndItemType); // XATTR_LINEEND
         for (const SfxPoolItem* p : aSurrogates)
         {
             pItem = static_cast<const NameOrIndex*>(p);
@@ -419,7 +419,7 @@ sal_Bool SAL_CALL SvxUnoMarkerTable::hasElements(  )
     if (mpModelPool)
     {
         ItemSurrogates aSurrogates;
-        mpModelPool->GetItemSurrogates(aSurrogates, XATTR_LINESTART);
+        mpModelPool->GetItemSurrogatesForItem(aSurrogates, 
SfxItemType::XLineStartItemType); // XATTR_LINESTART
         for (const SfxPoolItem* p : aSurrogates)
         {
             pItem = static_cast<const NameOrIndex*>(p);
@@ -431,7 +431,7 @@ sal_Bool SAL_CALL SvxUnoMarkerTable::hasElements(  )
     if (mpModelPool)
     {
         ItemSurrogates aSurrogates;
-        mpModelPool->GetItemSurrogates(aSurrogates, XATTR_LINEEND);
+        mpModelPool->GetItemSurrogatesForItem(aSurrogates, 
SfxItemType::XLineEndItemType); // XATTR_LINEEND
         for (const SfxPoolItem* p : aSurrogates)
         {
             pItem = static_cast<const NameOrIndex*>(p);
diff --git a/svx/source/xoutdev/xattr.cxx b/svx/source/xoutdev/xattr.cxx
index bbcfe8e28678..79b38289d65f 100644
--- a/svx/source/xoutdev/xattr.cxx
+++ b/svx/source/xoutdev/xattr.cxx
@@ -1255,12 +1255,12 @@ std::unique_ptr<XLineStartItem> 
XLineStartItem::checkForUniqueItem( SdrModel& rM
     if (!aUniqueName.isEmpty())
     {
         ItemSurrogates aSurrogates;
-        rPool1.GetItemSurrogates(aSurrogates, XATTR_LINESTART);
+        rPool1.GetItemSurrogatesForItem(aSurrogates, 
SfxItemType::XLineStartItemType); // XATTR_LINESTART
         for (const SfxPoolItem* p : aSurrogates)
         {
-            auto pItem = dynamic_cast<const XLineStartItem*>(p);
+            auto pItem = static_cast<const XLineStartItem*>(p);
 
-            if( pItem && ( pItem->GetName() == pLineStartItem->GetName() ) )
+            if( pItem->GetName() == pLineStartItem->GetName() )
             {
                 // if there is already an item with the same name and the same
                 // value it's ok to set it
@@ -1276,12 +1276,12 @@ std::unique_ptr<XLineStartItem> 
XLineStartItem::checkForUniqueItem( SdrModel& rM
 
         if( !bForceNew )
         {
-            rPool1.GetItemSurrogates(aSurrogates, XATTR_LINEEND);
+            rPool1.GetItemSurrogatesForItem(aSurrogates, 
SfxItemType::XLineEndItemType); // XATTR_LINEEND
             for (const SfxPoolItem* p : aSurrogates)
             {
-                auto pItem = dynamic_cast<const XLineEndItem*>(p);
+                auto pItem = static_cast<const XLineEndItem*>(p);
 
-                if( pItem && ( pItem->GetName() == pLineStartItem->GetName() ) 
)
+                if( pItem->GetName() == pLineStartItem->GetName() )
                 {
                     // if there is already an item with the same name and the 
same
                     // value it's ok to set it
@@ -1301,12 +1301,12 @@ std::unique_ptr<XLineStartItem> 
XLineStartItem::checkForUniqueItem( SdrModel& rM
     if( !aUniqueName.isEmpty() && pPool2)
     {
         ItemSurrogates aSurrogates;
-        pPool2->GetItemSurrogates(aSurrogates, XATTR_LINESTART);
+        pPool2->GetItemSurrogatesForItem(aSurrogates, 
SfxItemType::XLineStartItemType); // XATTR_LINESTART
         for (const SfxPoolItem* p : aSurrogates)
         {
-            auto pItem = dynamic_cast<const XLineStartItem*>(p);
+            auto pItem = static_cast<const XLineStartItem*>(p);
 
-            if( pItem && ( pItem->GetName() == pLineStartItem->GetName() ) )
+            if( pItem->GetName() == pLineStartItem->GetName() )
             {
                 // if there is already an item with the same name and the same
                 // value it's ok to set it
@@ -1322,12 +1322,12 @@ std::unique_ptr<XLineStartItem> 
XLineStartItem::checkForUniqueItem( SdrModel& rM
 
         if( !bForceNew )
         {
-            pPool2->GetItemSurrogates(aSurrogates, XATTR_LINEEND);
+            pPool2->GetItemSurrogatesForItem(aSurrogates, 
SfxItemType::XLineEndItemType); // XATTR_LINEEND
             for (const SfxPoolItem* p : aSurrogates)
             {
-                auto pItem = dynamic_cast<const XLineEndItem*>(p);
+                auto pItem = static_cast<const XLineEndItem*>(p);
 
-                if( pItem && ( pItem->GetName() == pLineStartItem->GetName() ) 
)
+                if( pItem->GetName() == pLineStartItem->GetName() )
                 {
                     // if there is already an item with the same name and the 
same
                     // value it's ok to set it
@@ -1353,12 +1353,12 @@ std::unique_ptr<XLineStartItem> 
XLineStartItem::checkForUniqueItem( SdrModel& rM
         const OUString aUser(SvxResId(RID_SVXSTR_LINEEND));
 
         ItemSurrogates aSurrogates;
-        rPool1.GetItemSurrogates(aSurrogates, XATTR_LINESTART);
+        rPool1.GetItemSurrogatesForItem(aSurrogates, 
SfxItemType::XLineStartItemType); // XATTR_LINESTART
         for (const SfxPoolItem* p : aSurrogates)
         {
-            auto pItem = dynamic_cast<const XLineStartItem*>(p);
+            auto pItem = static_cast<const XLineStartItem*>(p);
 
-            if (pItem && !pItem->GetName().isEmpty())
+            if (!pItem->GetName().isEmpty())
             {
                 if (!bForceNew && pItem->GetLineStartValue() == 
pLineStartItem->GetLineStartValue())
                 {
@@ -1376,12 +1376,12 @@ std::unique_ptr<XLineStartItem> 
XLineStartItem::checkForUniqueItem( SdrModel& rM
             }
         }
 
-        rPool1.GetItemSurrogates(aSurrogates, XATTR_LINEEND);
+        rPool1.GetItemSurrogatesForItem(aSurrogates, 
SfxItemType::XLineEndItemType); // XATTR_LINEEND
         for (const SfxPoolItem* p : aSurrogates)
         {
-            auto pItem = dynamic_cast<const XLineEndItem*>(p);
+            auto pItem = static_cast<const XLineEndItem*>(p);
 
-            if (pItem && !pItem->GetName().isEmpty())
+            if (!pItem->GetName().isEmpty())
             {
                 if (!bForceNew && pItem->GetLineEndValue() == 
pLineStartItem->GetLineStartValue())
                 {
@@ -1500,12 +1500,12 @@ std::unique_ptr<XLineEndItem> 
XLineEndItem::checkForUniqueItem( SdrModel& rModel
     if (!aUniqueName.isEmpty())
     {
         ItemSurrogates aSurrogates;
-        rPool1.GetItemSurrogates(aSurrogates, XATTR_LINESTART);
+        rPool1.GetItemSurrogatesForItem(aSurrogates, 
SfxItemType::XLineStartItemType); // XATTR_LINESTART
         for (const SfxPoolItem* p : aSurrogates)
         {
-            auto pItem = dynamic_cast<const XLineStartItem*>(p);
+            auto pItem = static_cast<const XLineStartItem*>(p);
 
-            if( pItem && ( pItem->GetName() == pLineEndItem->GetName() ) )
+            if( pItem->GetName() == pLineEndItem->GetName() )
             {
                 // if there is already an item with the same name and the same
                 // value it's ok to set it
@@ -1521,12 +1521,12 @@ std::unique_ptr<XLineEndItem> 
XLineEndItem::checkForUniqueItem( SdrModel& rModel
 
         if( !bForceNew )
         {
-            rPool1.GetItemSurrogates(aSurrogates, XATTR_LINEEND);
+            rPool1.GetItemSurrogatesForItem(aSurrogates, 
SfxItemType::XLineEndItemType); // XATTR_LINEEND
             for (const SfxPoolItem* p : aSurrogates)
             {
-                auto pItem = dynamic_cast<const XLineEndItem*>(p);
+                auto pItem = static_cast<const XLineEndItem*>(p);
 
-                if( pItem && ( pItem->GetName() == pLineEndItem->GetName() ) )
+                if( pItem->GetName() == pLineEndItem->GetName() )
                 {
                     // if there is already an item with the same name and the 
same
                     // value it's ok to set it
@@ -1546,12 +1546,12 @@ std::unique_ptr<XLineEndItem> 
XLineEndItem::checkForUniqueItem( SdrModel& rModel
     if( !aUniqueName.isEmpty() && pPool2)
     {
         ItemSurrogates aSurrogates;
-        pPool2->GetItemSurrogates(aSurrogates, XATTR_LINESTART);
+        pPool2->GetItemSurrogatesForItem(aSurrogates, 
SfxItemType::XLineStartItemType); // XATTR_LINESTART
         for (const SfxPoolItem* p : aSurrogates)
         {
-            auto pItem = dynamic_cast<const XLineStartItem*>(p);
+            auto pItem = static_cast<const XLineStartItem*>(p);
 
-            if( pItem && ( pItem->GetName() == pLineEndItem->GetName() ) )
+            if( pItem->GetName() == pLineEndItem->GetName() )
             {
                 // if there is already an item with the same name and the same
                 // value it's ok to set it
@@ -1567,12 +1567,12 @@ std::unique_ptr<XLineEndItem> 
XLineEndItem::checkForUniqueItem( SdrModel& rModel
 
         if( !bForceNew )
         {
-            pPool2->GetItemSurrogates(aSurrogates, XATTR_LINEEND);
+            pPool2->GetItemSurrogatesForItem(aSurrogates, 
SfxItemType::XLineEndItemType); // XATTR_LINEEND
             for (const SfxPoolItem* p : aSurrogates)
             {
-                auto pItem = dynamic_cast<const XLineEndItem*>(p);
+                auto pItem = static_cast<const XLineEndItem*>(p);
 
-                if( pItem && ( pItem->GetName() == pLineEndItem->GetName() ) )
+                if( pItem->GetName() == pLineEndItem->GetName() )
                 {
                     // if there is already an item with the same name and the 
same
                     // value it's ok to set it
@@ -1598,12 +1598,12 @@ std::unique_ptr<XLineEndItem> 
XLineEndItem::checkForUniqueItem( SdrModel& rModel
         const OUString aUser(SvxResId(RID_SVXSTR_LINEEND));
 
         ItemSurrogates aSurrogates;
-        rPool1.GetItemSurrogates(aSurrogates, XATTR_LINESTART);
+        rPool1.GetItemSurrogatesForItem(aSurrogates, 
SfxItemType::XLineStartItemType); // XATTR_LINESTART
         for (const SfxPoolItem* p : aSurrogates)
         {
-            auto pItem = dynamic_cast<const XLineStartItem*>(p);
+            auto pItem = static_cast<const XLineStartItem*>(p);
 
-            if (pItem && !pItem->GetName().isEmpty())
+            if (!pItem->GetName().isEmpty())
             {
                 if (!bForceNew && pItem->GetLineStartValue() == 
pLineEndItem->GetLineEndValue())
                 {
@@ -1621,12 +1621,12 @@ std::unique_ptr<XLineEndItem> 
XLineEndItem::checkForUniqueItem( SdrModel& rModel
             }
         }
 
-        rPool1.GetItemSurrogates(aSurrogates, XATTR_LINEEND);
+        rPool1.GetItemSurrogatesForItem(aSurrogates, 
SfxItemType::XLineEndItemType); // XATTR_LINEEND
         for (const SfxPoolItem* p : aSurrogates)
         {
-            auto pItem = dynamic_cast<const XLineEndItem*>(p);
+            auto pItem = static_cast<const XLineEndItem*>(p);
 
-            if (pItem && !pItem->GetName().isEmpty())
+            if (!pItem->GetName().isEmpty())
             {
                 if (!bForceNew && pItem->GetLineEndValue() == 
pLineEndItem->GetLineEndValue())
                 {
diff --git a/sw/source/filter/ww8/rtfexport.cxx 
b/sw/source/filter/ww8/rtfexport.cxx
index 460dd409660f..6503a23b8a4e 100644
--- a/sw/source/filter/ww8/rtfexport.cxx
+++ b/sw/source/filter/ww8/rtfexport.cxx
@@ -1417,7 +1417,7 @@ void RtfExport::OutColorTable()
     }
 
     // TextFrame or paragraph background solid fill.
-    rPool.GetItemSurrogates(aSurrogates, XATTR_FILLCOLOR);
+    rPool.GetItemSurrogatesForItem(aSurrogates, 
SfxItemType::XFillColorItemType);
     for (const SfxPoolItem* pItem : aSurrogates)
     {
         const auto& rColorItem = static_cast<const XFillColorItem&>(*pItem);

Reply via email to