include/svl/itemset.hxx       |    3 +++
 svl/source/items/itemiter.cxx |    7 ++-----
 svl/source/items/itemset.cxx  |   41 +++++++++++++++++++++--------------------
 3 files changed, 26 insertions(+), 25 deletions(-)

New commits:
commit 3072f7cbadf456814db2b4857e5931ca7a48ab51
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Sun May 11 09:13:01 2025 +0200
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Sun May 11 15:19:00 2025 +0200

    Optimize SfxItemIter::GetItemState using SfxItemSet::GetItemState_ForIter
    
    Avoids a lookup in the unordered map, where we already have an iterator.
    
    Change-Id: Ie65c588a9ec7b7c3c1ad3ba2181f6c76ec9b7e9c
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/185168
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/svl/source/items/itemiter.cxx b/svl/source/items/itemiter.cxx
index 6eaa33dc5702..652c511e56da 100644
--- a/svl/source/items/itemiter.cxx
+++ b/svl/source/items/itemiter.cxx
@@ -25,16 +25,13 @@ SfxItemState SfxItemIter::GetItemState(bool bSrchInParent, 
const SfxPoolItem** p
     if (IsAtEnd())
         return SfxItemState::UNKNOWN;
 
-    const sal_uInt16 nWhich(maCurrent->first);
-    SfxItemState eState(
-        m_rSet.GetItemState_ForWhichID(SfxItemState::UNKNOWN, nWhich, true, 
ppItem));
+    SfxItemState eState(SfxItemSet::GetItemState_ForIter(maCurrent, ppItem));
 
     // search in parent?
     if (bSrchInParent && nullptr != m_rSet.GetParent()
         && (SfxItemState::UNKNOWN == eState || SfxItemState::DEFAULT == 
eState))
     {
-        // nOffset was only valid for *local* SfxItemSet, need to continue 
with WhichID
-        // const sal_uInt16 nWhich(m_rSet.GetWhichByOffset(m_nCurrent));
+        const sal_uInt16 nWhich(maCurrent->first);
         eState = m_rSet.GetParent()->GetItemState_ForWhichID(eState, nWhich, 
true, ppItem);
     }
 
commit 4dab3d017ff2668ef00417a51908ab7987132b9a
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Sun May 11 08:39:25 2025 +0200
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Sun May 11 15:18:51 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>

diff --git a/include/svl/itemset.hxx b/include/svl/itemset.hxx
index f6d825832374..858b43bc4f6b 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