editeng/source/editeng/impedit4.cxx | 8 ++------ include/svl/itempool.hxx | 2 +- include/svx/DocumentColorHelper.hxx | 4 +--- sc/source/core/data/document.cxx | 4 +--- sc/source/core/data/fillinfo.cxx | 4 +--- sc/source/filter/xml/xmlexprt.cxx | 4 +--- sc/source/filter/xml/xmlfonte.cxx | 8 ++------ sc/source/ui/docshell/DocumentModelAccessor.cxx | 4 +--- sd/source/ui/unoidl/unomodel.cxx | 4 +--- svl/source/items/itempool.cxx | 8 +++----- svx/source/unodraw/UnoNameItemTable.cxx | 20 +++++--------------- svx/source/unodraw/UnoNamespaceMap.cxx | 6 ++---- sw/source/filter/writer/writer.cxx | 4 +--- sw/source/filter/xml/xmlexp.cxx | 4 +--- 14 files changed, 23 insertions(+), 61 deletions(-)
New commits: commit 8dd04408a999b3066c6c593292d2ea3630021bb5 Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Sat May 24 11:33:17 2025 +0500 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Sat May 24 10:48:39 2025 +0200 Make GetItemSurrogates return a value, instead of using an out argument In all cases, it was used with a local variable created for each call. Change-Id: I436bdd8e611c02425b39d8d44366a4980e19dba8 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/185729 Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> Tested-by: Jenkins diff --git a/editeng/source/editeng/impedit4.cxx b/editeng/source/editeng/impedit4.cxx index 54580a5439b4..c8ae50031c19 100644 --- a/editeng/source/editeng/impedit4.cxx +++ b/editeng/source/editeng/impedit4.cxx @@ -329,9 +329,7 @@ ErrCode ImpEditEngine::WriteRTF( SvStream& rOutput, EditSelection aSel, bool bCl aFontTable.emplace_back( new SvxFontItem( maEditDoc.GetItemPool().GetUserOrPoolDefaultItem( EE_CHAR_FONTINFO_CTL ) ) ); for (auto nWhich : { EE_CHAR_FONTINFO, EE_CHAR_FONTINFO_CJK, EE_CHAR_FONTINFO_CTL }) { - ItemSurrogates aSurrogates; - maEditDoc.GetItemPool().GetItemSurrogates(aSurrogates, nWhich); - for (const SfxPoolItem* pItem : aSurrogates) + for (const SfxPoolItem* pItem : maEditDoc.GetItemPool().GetItemSurrogates(nWhich)) { SvxFontItem const*const pFontItem = static_cast<const SvxFontItem*>(pItem); bool bAlreadyExist = false; @@ -411,9 +409,7 @@ ErrCode ImpEditEngine::WriteRTF( SvStream& rOutput, EditSelection aSel, bool bCl { aColorList.push_back(rDefault.GetValue()); } - ItemSurrogates aSurrogates; - maEditDoc.GetItemPool().GetItemSurrogates(aSurrogates, EE_CHAR_COLOR); - for (const SfxPoolItem* pItem : aSurrogates) + for (const SfxPoolItem* pItem : maEditDoc.GetItemPool().GetItemSurrogates(EE_CHAR_COLOR)) { auto pColorItem(dynamic_cast<SvxColorItem const*>(pItem)); if (pColorItem && pColorItem->GetValue() != COL_AUTO) // may be null! diff --git a/include/svl/itempool.hxx b/include/svl/itempool.hxx index 0f378ea50b8d..0a781aa3e03a 100644 --- a/include/svl/itempool.hxx +++ b/include/svl/itempool.hxx @@ -321,7 +321,7 @@ public: // Read-only access to registered SfxPoolItems // NOTE: In *no* case use const_cast and change those Items (!) // Read commit text for more information - void GetItemSurrogates(ItemSurrogates& rTarget, sal_uInt16 nWhich) const; + ItemSurrogates GetItemSurrogates(sal_uInt16 nWhich) const; // special version for read-only itemSurrogates for NameOrIndex Items void GetItemSurrogatesForItem(ItemSurrogates& rTarget, const SfxPoolItem& rItem) const; diff --git a/include/svx/DocumentColorHelper.hxx b/include/svx/DocumentColorHelper.hxx index 83884adcfa51..9388b7cba815 100644 --- a/include/svx/DocumentColorHelper.hxx +++ b/include/svx/DocumentColorHelper.hxx @@ -26,9 +26,7 @@ inline Color getColorFromItem(const SvxBrushItem* pItem) { return pItem->GetColo template <class T> void queryColors(const sal_uInt16 nAttrib, const SfxItemPool* pPool, std::set<Color>& rOutput) { - ItemSurrogates aSurrogates; - pPool->GetItemSurrogates(aSurrogates, nAttrib); - for (const SfxPoolItem* pItem : aSurrogates) + for (const SfxPoolItem* pItem : pPool->GetItemSurrogates(nAttrib)) { auto pColorItem = static_cast<const T*>(pItem); Color aColor(getColorFromItem(pColorItem)); diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx index d183b996339e..df51a6d91d27 100644 --- a/sc/source/core/data/document.cxx +++ b/sc/source/core/data/document.cxx @@ -5195,9 +5195,7 @@ static HasAttrFlags OptimizeHasAttrib( HasAttrFlags nMask, const ScDocumentPool* // (as in fillinfo) bool bAnyItem = false; - ItemSurrogates aSurrogates; - pPool->GetItemSurrogates(aSurrogates, ATTR_ROTATE_VALUE); - for (const SfxPoolItem* pItem : aSurrogates) + for (const SfxPoolItem* pItem : pPool->GetItemSurrogates(ATTR_ROTATE_VALUE)) { // 90 or 270 degrees is former SvxOrientationItem - only look for other values // (see ScPatternAttr::GetCellOrientation) diff --git a/sc/source/core/data/fillinfo.cxx b/sc/source/core/data/fillinfo.cxx index d3739b2878ef..c27d6d9e64f0 100644 --- a/sc/source/core/data/fillinfo.cxx +++ b/sc/source/core/data/fillinfo.cxx @@ -186,9 +186,7 @@ public: bool isRotateItemUsed(const ScDocumentPool *pPool) { - ItemSurrogates aSurrogates; - pPool->GetItemSurrogates(aSurrogates, ATTR_ROTATE_VALUE); - return aSurrogates.size() > 0; + return pPool->GetItemSurrogates(ATTR_ROTATE_VALUE).size() > 0; } void initRowInfo(const ScDocument* pDoc, RowInfo* pRowInfo, const SCSIZE nMaxRow, diff --git a/sc/source/filter/xml/xmlexprt.cxx b/sc/source/filter/xml/xmlexprt.cxx index d15dc2788435..fcfe6283c286 100644 --- a/sc/source/filter/xml/xmlexprt.cxx +++ b/sc/source/filter/xml/xmlexprt.cxx @@ -5378,9 +5378,7 @@ XMLNumberFormatAttributesExportHelper* ScXMLExport::GetNumberFormatAttributesExp void ScXMLExport::CollectUserDefinedNamespaces(const SfxItemPool* pPool, sal_uInt16 nAttrib) { - ItemSurrogates aSurrogates; - pPool->GetItemSurrogates(aSurrogates, nAttrib); - for (const SfxPoolItem* pItem : aSurrogates) + for (const SfxPoolItem* pItem : pPool->GetItemSurrogates(nAttrib)) { const SvXMLAttrContainerItem *pUnknown(static_cast<const SvXMLAttrContainerItem *>(pItem)); if( pUnknown->GetAttrCount() > 0 ) diff --git a/sc/source/filter/xml/xmlfonte.cxx b/sc/source/filter/xml/xmlfonte.cxx index a2230349dc8a..fa321c2616ed 100644 --- a/sc/source/filter/xml/xmlfonte.cxx +++ b/sc/source/filter/xml/xmlfonte.cxx @@ -59,9 +59,7 @@ void ScXMLFontAutoStylePool_Impl::AddFontItems(const sal_uInt16* pWhichIds, sal_ pFont->GetFamily(), pFont->GetPitch(), pFont->GetCharSet() ); } - ItemSurrogates aSurrogates; - pItemPool->GetItemSurrogates( aSurrogates, nWhichId ); - for (const SfxPoolItem* pItem : aSurrogates) + for (const SfxPoolItem* pItem : pItemPool->GetItemSurrogates(nWhichId)) { const SvxFontItem *pFont(static_cast<const SvxFontItem *>(pItem)); Add( pFont->GetFamilyName(), pFont->GetStyleName(), @@ -111,9 +109,7 @@ ScXMLFontAutoStylePool_Impl::ScXMLFontAutoStylePool_Impl(ScDocument* pDoc, ScXML for (sal_uInt16 nPageWhichId : aPageWhichIds) { - ItemSurrogates aSurrogates; - rPagePool.GetItemSurrogates( aSurrogates, nPageWhichId ); - for (const SfxPoolItem* pItem : aSurrogates) + for (const SfxPoolItem* pItem : rPagePool.GetItemSurrogates(nPageWhichId)) { const ScPageHFItem* pPageItem = static_cast<const ScPageHFItem*>(pItem); const EditTextObject* pLeftArea(pPageItem->GetLeftArea()); diff --git a/sc/source/ui/docshell/DocumentModelAccessor.cxx b/sc/source/ui/docshell/DocumentModelAccessor.cxx index 0b7425c05d03..633b13b98a0e 100644 --- a/sc/source/ui/docshell/DocumentModelAccessor.cxx +++ b/sc/source/ui/docshell/DocumentModelAccessor.cxx @@ -23,9 +23,7 @@ std::vector<sfx::CurrencyID> DocumentModelAccessor::getDocumentCurrencies() cons { std::vector<sfx::CurrencyID> aCurrencyIDs; - ItemSurrogates aSurrogates; - m_pDocument->GetPool()->GetItemSurrogates(aSurrogates, ATTR_VALUE_FORMAT); - for (const SfxPoolItem* pItem : aSurrogates) + for (const SfxPoolItem* pItem : m_pDocument->GetPool()->GetItemSurrogates(ATTR_VALUE_FORMAT)) { auto* pIntItem = static_cast<const SfxUInt32Item*>(pItem); sal_Int32 nFormat = pIntItem->GetValue(); diff --git a/sd/source/ui/unoidl/unomodel.cxx b/sd/source/ui/unoidl/unomodel.cxx index 9dcae67d86ea..e569fa25c077 100644 --- a/sd/source/ui/unoidl/unomodel.cxx +++ b/sd/source/ui/unoidl/unomodel.cxx @@ -2973,8 +2973,7 @@ uno::Any SAL_CALL SdXImpressDocument::getPropertyValue( const OUString& Property for(sal_uInt16 nWhichId : aWhichIds) { - ItemSurrogates aSurrogates; - rPool.GetItemSurrogates(aSurrogates, nWhichId); + ItemSurrogates aSurrogates = rPool.GetItemSurrogates(nWhichId); const sal_uInt32 nItems(aSurrogates.size()); aSeq.realloc( aSeq.getLength() + nItems*5 + 5 ); @@ -3001,7 +3000,6 @@ uno::Any SAL_CALL SdXImpressDocument::getPropertyValue( const OUString& Property } - aSeq.realloc( nSeqIndex ); aAny <<= aSeq; break; } diff --git a/svl/source/items/itempool.cxx b/svl/source/items/itempool.cxx index db62b26e8955..49fa7bf9b5df 100644 --- a/svl/source/items/itempool.cxx +++ b/svl/source/items/itempool.cxx @@ -901,12 +901,10 @@ void SfxItemPool::GetItemSurrogatesForItem(ItemSurrogates& rTarget, const SfxPoo GetItemSurrogatesForItem(rTarget, rItem.ItemType()); } -void SfxItemPool::GetItemSurrogates(ItemSurrogates& rTarget, sal_uInt16 nWhich) const +ItemSurrogates SfxItemPool::GetItemSurrogates(sal_uInt16 nWhich) const { - rTarget.clear(); - if (0 == nWhich) - return; + return {}; // NOTE: This is pre-collected, in this case mainly to // remove all double listings of SfxPoolItems which can @@ -928,7 +926,7 @@ void SfxItemPool::GetItemSurrogates(ItemSurrogates& rTarget, sal_uInt16 nWhich) if (rCand->Which() == nWhich && nullptr != rCand->getItem()) aNewSurrogates.insert(rCand->getItem()); - rTarget = ItemSurrogates(aNewSurrogates.begin(), aNewSurrogates.end()); + return ItemSurrogates(aNewSurrogates.begin(), aNewSurrogates.end()); } sal_uInt16 SfxItemPool::GetWhichIDFromSlotID(sal_uInt16 nSlotId, bool bDeep) const diff --git a/svx/source/unodraw/UnoNameItemTable.cxx b/svx/source/unodraw/UnoNameItemTable.cxx index a4fc0f9dd4cc..f7315e18b412 100644 --- a/svx/source/unodraw/UnoNameItemTable.cxx +++ b/svx/source/unodraw/UnoNameItemTable.cxx @@ -183,10 +183,8 @@ void SAL_CALL SvxUnoNameItemTable::replaceByName( const OUString& aApiName, cons if (mpModelPool) { SampleItem aSample(mnWhich, aName); - ItemSurrogates aSurrogates; - mpModelPool->GetItemSurrogates(aSurrogates, mnWhich); - for (const SfxPoolItem* pNameOrIndex : aSurrogates) + for (const SfxPoolItem* pNameOrIndex : mpModelPool->GetItemSurrogates(mnWhich)) if (aSample == *pNameOrIndex) if (isValid(static_cast<const NameOrIndex*>(pNameOrIndex))) { @@ -215,10 +213,8 @@ uno::Any SAL_CALL SvxUnoNameItemTable::getByName( const OUString& aApiName ) if (mpModelPool && !aName.isEmpty()) { SampleItem aSample(mnWhich, aName); - ItemSurrogates aSurrogates; - mpModelPool->GetItemSurrogates(aSurrogates, mnWhich); - for (const SfxPoolItem* pFindItem : aSurrogates) + for (const SfxPoolItem* pFindItem : mpModelPool->GetItemSurrogates(mnWhich)) if (aSample == *pFindItem) if (isValid(static_cast<const NameOrIndex*>(pFindItem))) { @@ -240,9 +236,7 @@ uno::Sequence< OUString > SAL_CALL SvxUnoNameItemTable::getElementNames( ) if (mpModelPool) { - ItemSurrogates aSurrogates; - mpModelPool->GetItemSurrogates(aSurrogates, mnWhich); - for (const SfxPoolItem* pItem : aSurrogates) + for (const SfxPoolItem* pItem : mpModelPool->GetItemSurrogates(mnWhich)) { const NameOrIndex *pNameOrIndex = static_cast<const NameOrIndex*>(pItem); @@ -270,10 +264,8 @@ sal_Bool SAL_CALL SvxUnoNameItemTable::hasByName( const OUString& aApiName ) return false; SampleItem aSample(mnWhich, aName); - ItemSurrogates aSurrogates; - mpModelPool->GetItemSurrogates(aSurrogates, mnWhich); - for (const SfxPoolItem* pFindItem : aSurrogates) + for (const SfxPoolItem* pFindItem : mpModelPool->GetItemSurrogates(mnWhich)) if (aSample == *pFindItem) if (isValid(static_cast<const NameOrIndex*>(pFindItem))) return true; @@ -286,9 +278,7 @@ sal_Bool SAL_CALL SvxUnoNameItemTable::hasElements( ) if (mpModelPool) { - ItemSurrogates aSurrogates; - mpModelPool->GetItemSurrogates(aSurrogates, mnWhich); - for (const SfxPoolItem* pItem : aSurrogates) + for (const SfxPoolItem* pItem : mpModelPool->GetItemSurrogates(mnWhich)) { const NameOrIndex *pNameOrIndex = static_cast<const NameOrIndex*>(pItem); diff --git a/svx/source/unodraw/UnoNamespaceMap.cxx b/svx/source/unodraw/UnoNamespaceMap.cxx index 85e92438039e..0ca0a7f5e5e8 100644 --- a/svx/source/unodraw/UnoNamespaceMap.cxx +++ b/svx/source/unodraw/UnoNamespaceMap.cxx @@ -127,8 +127,7 @@ NamespaceIteratorImpl::NamespaceIteratorImpl( sal_uInt16* pWhichIds, SfxItemPool mnItem = -1; if (mpWhichId && (0 != *mpWhichId) && mpPool) { - ItemSurrogates aSurrogates; - mpPool->GetItemSurrogates(aSurrogates, *mpWhichId); + ItemSurrogates aSurrogates = mpPool->GetItemSurrogates(*mpWhichId); mvItems.reserve(aSurrogates.size()); for (const SfxPoolItem* pItem : aSurrogates) mvItems.push_back(static_cast<const SvXMLAttrContainerItem*>(pItem)); @@ -164,8 +163,7 @@ bool NamespaceIteratorImpl::next( OUString& rPrefix, OUString& rURL ) mvItems.clear(); if (mpPool) { - ItemSurrogates aSurrogates; - mpPool->GetItemSurrogates(aSurrogates, *mpWhichId); + ItemSurrogates aSurrogates = mpPool->GetItemSurrogates(*mpWhichId); mvItems.reserve(aSurrogates.size()); for (const SfxPoolItem* pItem2 : aSurrogates) mvItems.push_back(static_cast<const SvXMLAttrContainerItem*>(pItem2)); diff --git a/sw/source/filter/writer/writer.cxx b/sw/source/filter/writer/writer.cxx index 3d8ead0cc4c9..56ae833b6dfd 100644 --- a/sw/source/filter/writer/writer.cxx +++ b/sw/source/filter/writer/writer.cxx @@ -381,9 +381,7 @@ void Writer::AddFontItems_( SfxItemPool& rPool, TypedWhichId<SvxFontItem> nWhich else { // nWhich is one of EE_CHAR_FONTINFO / EE_CHAR_FONTINFO_CJK / rPool, EE_CHAR_FONTINFO_CTL - ItemSurrogates aSurrogates; - rPool.GetItemSurrogates(aSurrogates, nWhich); - for (const SfxPoolItem* pItem : aSurrogates) + for (const SfxPoolItem* pItem : rPool.GetItemSurrogates(nWhich)) AddFontItem( rPool, *static_cast<const SvxFontItem*>(pItem) ); } } diff --git a/sw/source/filter/xml/xmlexp.cxx b/sw/source/filter/xml/xmlexp.cxx index db43a13594ca..07d011f0e05a 100644 --- a/sw/source/filter/xml/xmlexp.cxx +++ b/sw/source/filter/xml/xmlexp.cxx @@ -170,9 +170,7 @@ ErrCode SwXMLExport::exportDoc( enum XMLTokenEnum eClass ) EE_CHAR_XMLATTRIBS }; for( sal_uInt16 nWhichId : aWhichIds ) { - ItemSurrogates aSurrogates; - rPool.GetItemSurrogates(aSurrogates, nWhichId); - for (const SfxPoolItem* pItem : aSurrogates) + for (const SfxPoolItem* pItem : rPool.GetItemSurrogates(nWhichId)) { auto pUnknown = dynamic_cast<const SvXMLAttrContainerItem*>( pItem ); OSL_ENSURE( pUnknown, "illegal attribute container item" );