include/svl/itemprop.hxx | 8 ++++- svl/source/items/itemprop.cxx | 31 +++++++++++----------- sw/inc/unoxstyle.hxx | 8 +++-- sw/source/core/unocore/unostyle.cxx | 50 ++++++++++++++++++------------------ 4 files changed, 52 insertions(+), 45 deletions(-)
New commits: commit a9e9afd7df59df33b87099c7b532b60643d02ef7 Author: Noel Grandin <[email protected]> AuthorDate: Wed Feb 4 08:37:23 2026 +0200 Commit: Noel Grandin <[email protected]> CommitDate: Thu Feb 26 06:51:26 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]> (cherry picked from commit 6623e157bfb28800baee098a2dce119e29887bfb) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/200320 Reviewed-by: Noel Grandin <[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 01a76c637b7f..74095500e50c 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 9de2c9eead48..75463927fd78 100644 --- a/sw/source/core/unocore/unostyle.cxx +++ b/sw/source/core/unocore/unostyle.cxx @@ -3830,18 +3830,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 ); } } commit b68868ea165a3323165ea4c78119c1a62f28dfc8 Author: Noel Grandin <[email protected]> AuthorDate: Tue Feb 3 16:51:26 2026 +0200 Commit: Noel Grandin <[email protected]> CommitDate: Thu Feb 26 06:51:16 2026 +0100 tdf#170595 apply SwXStyle properties in one call instead of one at a time, which avoids some overhead Change-Id: I7aad2abf87dfc97b966527c824cc80b74f8b94f6 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/198665 Reviewed-by: Miklos Vajna <[email protected]> Tested-by: Jenkins CollaboraOffice <[email protected]> (cherry picked from commit ae521367faa960086d05f9b182d42e61a2a56169) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/200319 Tested-by: Noel Grandin <[email protected]> Reviewed-by: Noel Grandin <[email protected]> diff --git a/sw/inc/unoxstyle.hxx b/sw/inc/unoxstyle.hxx index 49014c3abc7c..69a644721cdd 100644 --- a/sw/inc/unoxstyle.hxx +++ b/sw/inc/unoxstyle.hxx @@ -34,6 +34,7 @@ #include "coreframestyle.hxx" #include "unobasestyle.hxx" #include "names.hxx" +#include <span> class StyleFamilyEntry; class SwStyleBase_Impl; @@ -80,9 +81,8 @@ protected: template <sal_uInt16> void SetPropertyValue(const SfxItemPropertyMapEntry&, const SfxItemPropertySet&, const css::uno::Any&, SwStyleBase_Impl&); - void SetPropertyValues_Impl(const css::uno::Sequence<OUString>& aPropertyNames, - const css::uno::Sequence<css::uno::Any>& aValues, - bool bIgnoreUnknown); + void SetPropertyValues_Impl(std::span<const OUString> aPropertyNames, + std::span<const css::uno::Any> aValues, bool bIgnoreUnknown); SfxStyleSheetBase* GetStyleSheetBase(); void PrepareStyleBase(SwStyleBase_Impl& rBase); template <sal_uInt16> @@ -223,6 +223,8 @@ public: // ignoring. SW_DLLPUBLIC void setPropertyValueIgnoreUnknown(const OUString& aPropertyName, const css::uno::Any& aValue); + void SetPropertyValues(std::span<const OUString> aPropertyNames, + std::span<const css::uno::Any> aValues); }; typedef cppu::ImplInheritanceHelper<SwXStyle, css::document::XEventsSupplier> SwXFrameStyle_Base; diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx index b1a36cf0d8a3..9de2c9eead48 100644 --- a/sw/source/core/unocore/unostyle.cxx +++ b/sw/source/core/unocore/unostyle.cxx @@ -559,11 +559,17 @@ public: { m_vPropertyValues.clear(); } void Apply(SwXStyle& rStyle) { + std::vector<OUString> aPropNames; + std::vector<css::uno::Any> aPropVals; for(const auto& rPropertyPair : m_vPropertyValues) { if(rPropertyPair.second.hasValue()) - rStyle.setPropertyValue(rPropertyPair.first, rPropertyPair.second); + { + aPropNames.push_back(rPropertyPair.first); + aPropVals.push_back(rPropertyPair.second); + } } + rStyle.SetPropertyValues(aPropNames, aPropVals); } }; @@ -2041,14 +2047,19 @@ void SwXStyle::SetStyleProperty(const SfxItemPropertyMapEntry& rEntry, const Sfx } } -void SwXStyle::SetPropertyValues_Impl(const uno::Sequence<OUString>& rPropertyNames, const uno::Sequence<uno::Any>& rValues, bool bIgnoreUnknown) +void SwXStyle::SetPropertyValues(std::span<const OUString> rPropertyNames, std::span<const uno::Any> rValues) +{ + SetPropertyValues_Impl(rPropertyNames, rValues, /*bIgnoreUnknown*/false); +} + +void SwXStyle::SetPropertyValues_Impl(std::span<const OUString> rPropertyNames, std::span<const uno::Any> rValues, bool bIgnoreUnknown) { if(!m_pDoc) throw uno::RuntimeException(); sal_uInt16 nPropSetId = m_bIsConditional ? PROPERTY_MAP_CONDITIONAL_PARA_STYLE : m_rEntry.propMapType(); const SfxItemPropertySet* pPropSet = aSwMapProvider.GetPropertySet(nPropSetId); const SfxItemPropertyMap &rMap = pPropSet->getPropertyMap(); - if(rPropertyNames.getLength() != rValues.getLength()) + if(rPropertyNames.size() != rValues.size()) throw lang::IllegalArgumentException(); SwStyleBase_Impl aBaseImpl(*m_pDoc, m_sStyleUIName, &GetDoc()->GetDfltTextFormatColl()->GetAttrSet()); // add pDfltTextFormatColl as parent @@ -2063,22 +2074,20 @@ void SwXStyle::SetPropertyValues_Impl(const uno::Sequence<OUString>& rPropertyNa if(!aBaseImpl.getNewBase().is() && !m_bIsDescriptor) throw uno::RuntimeException(); - const OUString* pNames = rPropertyNames.getConstArray(); - const uno::Any* pValues = rValues.getConstArray(); - for(sal_Int32 nProp = 0; nProp < rPropertyNames.getLength(); ++nProp) + for(size_t nProp = 0; nProp < rPropertyNames.size(); ++nProp) { - const SfxItemPropertyMapEntry* pEntry = rMap.getByName(pNames[nProp]); - if(!pEntry || (!m_bIsConditional && pNames[nProp] == UNO_NAME_PARA_STYLE_CONDITIONS)) + const SfxItemPropertyMapEntry* pEntry = rMap.getByName(rPropertyNames[nProp]); + if(!pEntry || (!m_bIsConditional && rPropertyNames[nProp] == UNO_NAME_PARA_STYLE_CONDITIONS)) { if (bIgnoreUnknown) continue; - throw beans::UnknownPropertyException("Unknown property: " + pNames[nProp], getXWeak()); + throw beans::UnknownPropertyException("Unknown property: " + rPropertyNames[nProp], getXWeak()); } if(pEntry->nFlags & beans::PropertyAttribute::READONLY) - throw beans::PropertyVetoException ("Property is read-only: " + pNames[nProp], getXWeak()); + throw beans::PropertyVetoException ("Property is read-only: " + rPropertyNames[nProp], getXWeak()); if(aBaseImpl.getNewBase().is()) - SetStyleProperty(*pEntry, *pPropSet, pValues[nProp], aBaseImpl); - else if(!m_pPropertiesImpl->SetProperty(pNames[nProp], pValues[nProp])) + SetStyleProperty(*pEntry, *pPropSet, rValues[nProp], aBaseImpl); + else if(!m_pPropertiesImpl->SetProperty(rPropertyNames[nProp], rValues[nProp])) throw lang::IllegalArgumentException(); } @@ -2092,7 +2101,9 @@ void SwXStyle::setPropertyValues(const uno::Sequence<OUString>& rPropertyNames, // workaround for bad designed API try { - SetPropertyValues_Impl( rPropertyNames, rValues, /*bIgnoreUnknown*/false ); + SetPropertyValues_Impl( std::span<const OUString>{ rPropertyNames.getConstArray(), static_cast<size_t>(rPropertyNames.getLength()) }, + std::span<const uno::Any>{ rValues.getConstArray(), static_cast<size_t>(rValues.getLength()) }, + /*bIgnoreUnknown*/false ); } catch (const beans::UnknownPropertyException &rException) {
