include/svl/itemprop.hxx | 8 ++++++-- svl/source/items/itemprop.cxx | 31 ++++++++++++++++--------------- sw/source/core/unocore/unostyle.cxx | 13 +------------ 3 files changed, 23 insertions(+), 29 deletions(-)
New commits: commit 6623e157bfb28800baee098a2dce119e29887bfb Author: Noel Grandin <[email protected]> AuthorDate: Wed Feb 4 08:37:23 2026 +0200 Commit: Miklos Vajna <[email protected]> CommitDate: Fri Feb 6 08:27:17 2026 +0100 tdf#170595 reduce exception throwing overhead where we are just going to ignore the exception anyway Change-Id: I2c05d94e2cf3582ca005aa4765bad0be85041895 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/198666 Reviewed-by: Miklos Vajna <[email protected]> Tested-by: Jenkins CollaboraOffice <[email protected]> diff --git a/include/svl/itemprop.hxx b/include/svl/itemprop.hxx index af48da4ed696..542e954df5bd 100644 --- a/include/svl/itemprop.hxx +++ b/include/svl/itemprop.hxx @@ -120,17 +120,21 @@ public: css::uno::Any getPropertyValue( const OUString &rName, const SfxItemSet& rSet ) const; + /// @param bIgnoreUnknownProperty if true, dont throw an exception when the property is not one we know about /// @throws css::uno::RuntimeException /// @throws css::lang::IllegalArgumentException static void setPropertyValue( const SfxItemPropertyMapEntry& rEntry, const css::uno::Any& aVal, - SfxItemSet& rSet ); + SfxItemSet& rSet, + bool bIgnoreUnknownProperty = false); + /// @param bIgnoreUnknownProperty if true, dont throw an exception when the property is not one we know about /// @throws css::uno::RuntimeException /// @throws css::lang::IllegalArgumentException /// @throws css::beans::UnknownPropertyException void setPropertyValue( const OUString& rPropertyName, const css::uno::Any& aVal, - SfxItemSet& rSet ) const; + SfxItemSet& rSet, + bool bIgnoreUnknownProperty = false) const; /// @throws css::beans::UnknownPropertyException css::beans::PropertyState diff --git a/svl/source/items/itemprop.cxx b/svl/source/items/itemprop.cxx index 128bc190c390..bd7e613c013a 100644 --- a/svl/source/items/itemprop.cxx +++ b/svl/source/items/itemprop.cxx @@ -163,39 +163,40 @@ Any SfxItemPropertySet::getPropertyValue( const OUString &rName, // static void SfxItemPropertySet::setPropertyValue( const SfxItemPropertyMapEntry& rEntry, const Any& aVal, - SfxItemSet& rSet ) + SfxItemSet& rSet, bool bIgnoreUnknownProperty ) { // get the SfxPoolItem const SfxPoolItem* pItem = nullptr; - std::unique_ptr<SfxPoolItem> pNewItem; SfxItemState eState = rSet.GetItemState( rEntry.nWID, true, &pItem ); if (SfxItemState::SET != eState && SfxItemPool::IsWhich(rEntry.nWID)) pItem = &rSet.GetPool()->GetUserOrPoolDefaultItem(rEntry.nWID); - if (pItem) + if (!pItem) + return; + std::unique_ptr<SfxPoolItem> pNewItem(pItem->Clone()); + if(!pNewItem) + return; + if( !pNewItem->PutValue( aVal, rEntry.nMemberId ) ) { - pNewItem.reset(pItem->Clone()); - } - if(pNewItem) - { - if( !pNewItem->PutValue( aVal, rEntry.nMemberId ) ) - { - throw IllegalArgumentException(); - } - // apply new item - rSet.Put( std::move(pNewItem) ); + if (bIgnoreUnknownProperty) + return; + throw IllegalArgumentException(); } + // apply new item + rSet.Put( std::move(pNewItem) ); } void SfxItemPropertySet::setPropertyValue( const OUString &rName, const Any& aVal, - SfxItemSet& rSet ) const + SfxItemSet& rSet, bool bIgnoreUnknownProperty ) const { const SfxItemPropertyMapEntry* pEntry = m_aMap.getByName( rName ); if ( !pEntry ) { + if (bIgnoreUnknownProperty) + return; throw UnknownPropertyException(rName); } - setPropertyValue(*pEntry, aVal, rSet); + setPropertyValue(*pEntry, aVal, rSet, bIgnoreUnknownProperty); } // static diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx index c32226a949a9..f4e8b0e8589a 100644 --- a/sw/source/core/unocore/unostyle.cxx +++ b/sw/source/core/unocore/unostyle.cxx @@ -3829,18 +3829,7 @@ PropValuesToAutoStyleItemSet(SwDoc& rDoc, IStyleAccess::SwAutoStyleFamily eFamil if(!bDone) { - try - { - pPropSet->setPropertyValue( rPropName, aValue, aSet ); - } - catch (const beans::UnknownPropertyException &) - { - OSL_FAIL( "Unknown property" ); - } - catch (const lang::IllegalArgumentException &) - { - OSL_FAIL( "Illegal argument" ); - } + pPropSet->setPropertyValue( rPropName, aValue, aSet, /*bIgnoreUnknownProperty*/true ); } }
