summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoel Grandin <noelgrandin@gmail.com>2022-05-28 18:14:29 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2022-05-28 20:50:40 +0200
commit9ae3863f2afaa07abda6af11daf34bf6b808c3af (patch)
treea6ac827f983b24f2995c5883a6f4687b43cbcd17
parent8f3e12b7a918935eae4e98c47cdc3b575e8bf089 (diff)
add ClearItem to the SfxItemSet iterators
to speed up operations when iterating over SfxItemSets Change-Id: Ie40327ffaf7faa801ccc12d2b05c546a7fe49802 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135079 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r--editeng/source/rtf/svxrtf.cxx6
-rw-r--r--include/svl/itemiter.hxx1
-rw-r--r--include/svl/itemset.hxx2
-rw-r--r--include/svl/whiter.hxx1
-rw-r--r--svl/source/items/itemiter.cxx6
-rw-r--r--svl/source/items/itemset.cxx74
-rw-r--r--svl/source/items/whiter.cxx7
-rw-r--r--sw/source/core/txtnode/thints.cxx4
-rw-r--r--sw/source/uibase/wrtsh/wrtsh1.cxx2
9 files changed, 64 insertions, 39 deletions
diff --git a/editeng/source/rtf/svxrtf.cxx b/editeng/source/rtf/svxrtf.cxx
index bb07beae826c..b06337a143b1 100644
--- a/editeng/source/rtf/svxrtf.cxx
+++ b/editeng/source/rtf/svxrtf.cxx
@@ -654,7 +654,7 @@ void SvxRTFParser::ClearStyleAttr_( SvxRTFItemStackType& rStkType )
if (SfxItemPool::IsWhich(nWhich) &&
SfxItemState::SET == aIter.GetItemState( false, &pItem ) &&
rPool.GetDefaultItem( nWhich ) == *pItem )
- rSet.ClearItem( nWhich ); // delete
+ aIter.ClearItem(); // delete
}
}
else
@@ -707,7 +707,7 @@ void SvxRTFParser::AttrGroupEnd() // process the current, delete from Stack
if( SfxItemState::SET == pCurrent->aAttrSet.GetItemState(
pItem->Which(), false, &pGet ) &&
*pItem == *pGet )
- pOld->aAttrSet.ClearItem( pItem->Which() );
+ aIter.ClearItem();
pItem = aIter.NextItem();
} while (pItem);
@@ -1109,7 +1109,7 @@ void SvxRTFItemStackType::Compress( const SvxRTFParser& rParser )
sal_uInt16 nWhich = pIterItem->Which();
if( SfxItemState::SET != pTmp->aAttrSet.GetItemState( nWhich,
false, &pItem ) || *pItem != *pIterItem)
- aMrgSet.ClearItem( nWhich );
+ aIter.ClearItem();
pIterItem = aIter.NextItem();
} while(pIterItem);
diff --git a/include/svl/itemiter.hxx b/include/svl/itemiter.hxx
index dfe3c9dc6e22..13cf14b61012 100644
--- a/include/svl/itemiter.hxx
+++ b/include/svl/itemiter.hxx
@@ -49,6 +49,7 @@ public:
SfxItemState GetItemState(bool bSrchInParent = true,
const SfxPoolItem** ppItem = nullptr) const;
+ void ClearItem();
private:
const SfxPoolItem* ImplNextItem();
diff --git a/include/svl/itemset.hxx b/include/svl/itemset.hxx
index 086ddc42f74e..b6404b6cc984 100644
--- a/include/svl/itemset.hxx
+++ b/include/svl/itemset.hxx
@@ -227,7 +227,7 @@ public:
void dumpAsXml(xmlTextWriterPtr pWriter) const;
private:
- sal_uInt16 ClearSingleItemImpl( sal_uInt16 nWhich );
+ sal_uInt16 ClearSingleItemImpl( sal_uInt16 nWhich, std::optional<sal_uInt16> oItemOffsetHint );
sal_uInt16 ClearAllItemsImpl();
SfxItemState GetItemStateImpl( sal_uInt16 nWhich,
bool bSrchInParent,
diff --git a/include/svl/whiter.hxx b/include/svl/whiter.hxx
index df8c6fea79f2..155d02d7f3ab 100644
--- a/include/svl/whiter.hxx
+++ b/include/svl/whiter.hxx
@@ -46,6 +46,7 @@ public:
sal_uInt16 FirstWhich();
SfxItemState GetItemState(bool bSrchInParent = true,
const SfxPoolItem** ppItem = nullptr) const;
+ void ClearItem();
};
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svl/source/items/itemiter.cxx b/svl/source/items/itemiter.cxx
index b1bdedf416e0..fd0f6240e0c6 100644
--- a/svl/source/items/itemiter.cxx
+++ b/svl/source/items/itemiter.cxx
@@ -62,4 +62,10 @@ SfxItemState SfxItemIter::GetItemState(bool bSrchInParent, const SfxPoolItem** p
return m_rSet.GetItemStateImpl(nWhich, bSrchInParent, ppItem, m_nCurrent);
}
+void SfxItemIter::ClearItem()
+{
+ sal_uInt16 nWhich = (*(m_rSet.m_ppItems + m_nCurrent))->Which();
+ const_cast<SfxItemSet&>(m_rSet).ClearSingleItemImpl(nWhich, m_nCurrent);
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svl/source/items/itemset.cxx b/svl/source/items/itemset.cxx
index 133603fe0f39..982cbc837898 100644
--- a/svl/source/items/itemset.cxx
+++ b/svl/source/items/itemset.cxx
@@ -199,50 +199,60 @@ sal_uInt16 SfxItemSet::ClearItem( sal_uInt16 nWhich )
if( !Count() )
return 0;
if( nWhich )
- return ClearSingleItemImpl(nWhich);
+ return ClearSingleItemImpl(nWhich, std::nullopt);
else
return ClearAllItemsImpl();
}
-sal_uInt16 SfxItemSet::ClearSingleItemImpl( sal_uInt16 nWhich )
+sal_uInt16 SfxItemSet::ClearSingleItemImpl( sal_uInt16 nWhich, std::optional<sal_uInt16> oItemOffsetHint )
{
sal_uInt16 nDel = 0;
- SfxPoolItem const** ppFnd = m_ppItems;
+ SfxPoolItem const** pFoundOne = nullptr;
- for (const WhichPair& rPair : m_pWhichRanges)
+ if (oItemOffsetHint)
{
- // Within this range?
- if( rPair.first <= nWhich && nWhich <= rPair.second )
+ pFoundOne = m_ppItems + *oItemOffsetHint;
+ assert(!*pFoundOne || IsInvalidItem(*pFoundOne) || (*pFoundOne)->IsVoidItem() || (*pFoundOne)->Which() == nWhich);
+ }
+ else
+ {
+ SfxPoolItem const** ppFnd = m_ppItems;
+ for (const WhichPair& rPair : m_pWhichRanges)
{
- // Actually set?
- ppFnd += nWhich - rPair.first;
- if( *ppFnd )
+ // Within this range?
+ if( rPair.first <= nWhich && nWhich <= rPair.second )
{
- // Due to the assertions in the sub calls, we need to do the following
- --m_nCount;
- const SfxPoolItem *pItemToClear = *ppFnd;
- *ppFnd = nullptr;
-
- if ( !IsInvalidItem(pItemToClear) )
- {
- if (SfxItemPool::IsWhich(nWhich))
- {
- const SfxPoolItem& rNew = m_pParent
- ? m_pParent->Get( nWhich )
- : m_pPool->GetDefaultItem( nWhich );
+ // Actually set?
+ ppFnd += nWhich - rPair.first;
+ pFoundOne = ppFnd;
- Changed( *pItemToClear, rNew );
- }
- if ( pItemToClear->Which() )
- m_pPool->Remove( *pItemToClear );
- }
- ++nDel;
+ // found => break
+ break;
}
+ ppFnd += rPair.second - rPair.first + 1;
+ }
+ }
+ if (pFoundOne && *pFoundOne)
+ {
+ // Due to the assertions in the sub calls, we need to do the following
+ --m_nCount;
+ const SfxPoolItem *pItemToClear = *pFoundOne;
+ *pFoundOne = nullptr;
- // found => break
- break;
+ if ( !IsInvalidItem(pItemToClear) )
+ {
+ if (SfxItemPool::IsWhich(nWhich))
+ {
+ const SfxPoolItem& rNew = m_pParent
+ ? m_pParent->Get( nWhich )
+ : m_pPool->GetDefaultItem( nWhich );
+
+ Changed( *pItemToClear, rNew );
+ }
+ if ( pItemToClear->Which() )
+ m_pPool->Remove( *pItemToClear );
}
- ppFnd += rPair.second - rPair.first + 1;
+ ++nDel;
}
return nDel;
}
@@ -902,7 +912,7 @@ void SfxItemSet::Intersect( const SfxItemSet& rSet )
while ( nWhich )
{
if( SfxItemState::UNKNOWN == rSet.GetItemState( nWhich, false ) )
- ClearItem( nWhich ); // Delete
+ aIter.ClearItem(); // Delete
nWhich = aIter.NextWhich();
}
}
@@ -948,7 +958,7 @@ void SfxItemSet::Differentiate( const SfxItemSet& rSet )
while ( nWhich )
{
if( SfxItemState::SET == rSet.GetItemState( nWhich, false ) )
- ClearItem( nWhich ); // Delete
+ aIter.ClearItem(); // Delete
nWhich = aIter.NextWhich();
}
}
diff --git a/svl/source/items/whiter.cxx b/svl/source/items/whiter.cxx
index 707349c70ea5..c89c6ed2794b 100644
--- a/svl/source/items/whiter.cxx
+++ b/svl/source/items/whiter.cxx
@@ -70,4 +70,11 @@ SfxItemState SfxWhichIter::GetItemState(bool bSrchInParent, const SfxPoolItem**
return m_rItemSet.GetItemStateImpl(nWhich, bSrchInParent, ppItem, nItemsOffsetHint);
}
+void SfxWhichIter::ClearItem()
+{
+ sal_uInt16 nWhich = m_pCurrentWhichPair->first + m_nOffsetFromStartOfCurrentWhichPair;
+ sal_uInt16 nItemOffsetHint = m_nItemsOffset + m_nOffsetFromStartOfCurrentWhichPair;
+ const_cast<SfxItemSet&>(m_rItemSet).ClearSingleItemImpl(nWhich, nItemOffsetHint);
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/txtnode/thints.cxx b/sw/source/core/txtnode/thints.cxx
index edad6745b2e3..30c620d625d3 100644
--- a/sw/source/core/txtnode/thints.cxx
+++ b/sw/source/core/txtnode/thints.cxx
@@ -899,7 +899,7 @@ void SwpHints::BuildPortions( SwTextNode& rNode, SwTextAttr& rNewHint,
{
// Do not clear item if the attribute is set in a character format:
if ( !pCurrentCharFormat || nullptr == CharFormat::GetItem( *pCurrentCharFormat, pItem->Which() ) )
- aNewSet.ClearItem( pItem->Which() );
+ aIter2.ClearItem();
}
}
while ((pItem = aIter2.NextItem()));
@@ -2365,7 +2365,7 @@ struct RemovePresentAttrs
const sal_uInt16 nWhich(pItem->Which());
if (CharFormat::IsItemIncluded(nWhich, pAutoStyle))
{
- m_rAttrSet.ClearItem(nWhich);
+ aIter.ClearItem();
}
}
}
diff --git a/sw/source/uibase/wrtsh/wrtsh1.cxx b/sw/source/uibase/wrtsh/wrtsh1.cxx
index 8fef09eac5e8..3756df8a9781 100644
--- a/sw/source/uibase/wrtsh/wrtsh1.cxx
+++ b/sw/source/uibase/wrtsh/wrtsh1.cxx
@@ -1880,7 +1880,7 @@ void SwWrtShell::AutoUpdatePara(SwTextFormatColl* pColl, const SfxItemSet& rStyl
if(SfxItemState::SET == aParaIter.GetItemState() &&
SfxItemState::SET == rStyleSet.GetItemState(nWhich))
{
- aCoreSet.ClearItem(nWhich);
+ aParaIter.ClearItem();
bReset = true;
}
}