include/svl/itemset.hxx      |    3 +++
 svl/source/items/itemset.cxx |   41 +++++++++++++++++++++--------------------
 2 files changed, 24 insertions(+), 20 deletions(-)

New commits:
commit a4507d3a1d2d1276183acedee4ed112beaf1c057
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Sun May 11 08:39:25 2025 +0200
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Mon May 12 11:06:49 2025 +0200

    Optimize SfxItemSet::Equals
    
    No need to lookup the element in this - we already have the iterator.
    Introduces SfxItemSet::GetItemState_ForIter for the task.
    
    Change-Id: Ib85706201c452b5345df411c317e79bcf6c17238
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/185167
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>
    (cherry picked from commit 4dab3d017ff2668ef00417a51908ab7987132b9a)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/185193
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>

diff --git a/include/svl/itemset.hxx b/include/svl/itemset.hxx
index fe510a8c4c78..9a83cad194d3 100644
--- a/include/svl/itemset.hxx
+++ b/include/svl/itemset.hxx
@@ -288,6 +288,9 @@ private:
 
     // GetItemStateImpl for input type WhichID
     SfxItemState GetItemState_ForWhichID( SfxItemState eState, sal_uInt16 
nWhich, bool bSrchInParent, const SfxPoolItem **ppItem) const;
+
+    // GetItemStateImpl for iterator in m_aPoolItemMap
+    static SfxItemState GetItemState_ForIter(PoolItemMap::const_iterator aHit, 
const SfxPoolItem **ppItem);
 };
 
 //  Handles all Ranges. Ranges are automatically modified by putting items.
diff --git a/svl/source/items/itemset.cxx b/svl/source/items/itemset.cxx
index d8aceb8dbb42..3c0d1cbd4783 100644
--- a/svl/source/items/itemset.cxx
+++ b/svl/source/items/itemset.cxx
@@ -474,27 +474,30 @@ void SfxItemSet::ClearInvalidItems()
     }
 }
 
-SfxItemState SfxItemSet::GetItemState_ForWhichID( SfxItemState eState, 
sal_uInt16 nWhich, bool bSrchInParent, const SfxPoolItem **ppItem) const
+SfxItemState SfxItemSet::GetItemState_ForIter(PoolItemMap::const_iterator 
aHit, const SfxPoolItem **ppItem)
 {
-    PoolItemMap::const_iterator aHit(m_aPoolItemMap.find(nWhich));
+    if (IsInvalidItem(aHit->second))
+        // Different ones are present
+        return SfxItemState::INVALID;
 
-    if (aHit != m_aPoolItemMap.end())
-    {
-        if (IsInvalidItem(aHit->second))
-            // Different ones are present
-            return SfxItemState::INVALID;
+    if (IsDisabledItem(aHit->second))
+        // Item is Disabled
+        return SfxItemState::DISABLED;
 
-        if (IsDisabledItem(aHit->second))
-            // Item is Disabled
-            return SfxItemState::DISABLED;
+    // if we have the Item, add it to output an hand back
+    if (nullptr != ppItem)
+        *ppItem = aHit->second;
 
-        // if we have the Item, add it to output an hand back
-        if (nullptr != ppItem)
-            *ppItem = aHit->second;
+    // Item is set
+    return SfxItemState::SET;
+}
 
-        // Item is set
-        return SfxItemState::SET;
-    }
+SfxItemState SfxItemSet::GetItemState_ForWhichID( SfxItemState eState, 
sal_uInt16 nWhich, bool bSrchInParent, const SfxPoolItem **ppItem) const
+{
+    PoolItemMap::const_iterator aHit(m_aPoolItemMap.find(nWhich));
+
+    if (aHit != m_aPoolItemMap.end())
+        return GetItemState_ForIter(aHit, ppItem);
 
     if (GetRanges().doesContainWhich(nWhich))
     {
@@ -505,7 +508,6 @@ SfxItemState SfxItemSet::GetItemState_ForWhichID( 
SfxItemState eState, sal_uInt1
     // search in parent?
     if (bSrchInParent && nullptr != GetParent() && (SfxItemState::UNKNOWN == 
eState || SfxItemState::DEFAULT == eState))
     {
-        // nOffset was only valid for *local* SfxItemSet, need to continue 
with WhichID
         // Use the *highest* SfxItemState as result
         return GetParent()->GetItemState_ForWhichID( eState, nWhich, true, 
ppItem);
     }
@@ -1273,14 +1275,13 @@ bool SfxItemSet::Equals(const SfxItemSet &rCmp, bool 
bComparePool) const
         const SfxPoolItem *pItem1(nullptr);
         const SfxPoolItem *pItem2(nullptr);
         const sal_uInt16 nWhich(aCandidate->first);
-        const SfxItemState 
aStateA(GetItemState_ForWhichID(SfxItemState::UNKNOWN, nWhich, false, &pItem1));
+        const SfxItemState aStateA(GetItemState_ForIter(aCandidate, &pItem1));
         const SfxItemState 
aStateB(rCmp.GetItemState_ForWhichID(SfxItemState::UNKNOWN, nWhich, false, 
&pItem2));
 
         if (aStateA != aStateB)
             return false;
 
-        // only compare items if SfxItemState::SET, else the item ptrs are not 
set
-        if (SfxItemState::SET == aStateA && !SfxPoolItem::areSame(pItem1, 
pItem2))
+        if (!SfxPoolItem::areSame(pItem1, pItem2))
             return false;
     }
 

Reply via email to