sw/inc/unoxstyle.hxx | 7 ++++++- sw/source/core/unocore/unostyle.cxx | 18 +++++++++++++++--- sw/source/writerfilter/dmapper/StyleSheetTable.cxx | 17 ++++++++++------- 3 files changed, 31 insertions(+), 11 deletions(-)
New commits: commit aac7afb4c1703be5c4a3b136d054d4c7b1265c77 Author: Noel Grandin <[email protected]> AuthorDate: Tue Feb 3 16:23:32 2026 +0200 Commit: Miklos Vajna <[email protected]> CommitDate: Thu Feb 5 08:48:53 2026 +0100 tdf#170595 elide some exception throw overhead which we are just going to ignore Change-Id: I4921a1871437f3d51733e790e631290aa40d1389 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/198663 Tested-by: Jenkins CollaboraOffice <[email protected]> Reviewed-by: Miklos Vajna <[email protected]> diff --git a/sw/inc/unoxstyle.hxx b/sw/inc/unoxstyle.hxx index 8c77c6fa24c2..fb78d5f89aba 100644 --- a/sw/inc/unoxstyle.hxx +++ b/sw/inc/unoxstyle.hxx @@ -80,7 +80,8 @@ protected: 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); + const css::uno::Sequence<css::uno::Any>& aValues, + bool bIgnoreUnknown); SfxStyleSheetBase* GetStyleSheetBase(); void PrepareStyleBase(SwStyleBase_Impl& rBase); template <sal_uInt16> @@ -217,6 +218,10 @@ public: css::awt::FontSlant& reCharStylePosture, css::awt::FontSlant& reCharStylePostureComplex, sal_Int16& rnCharStyleCaseMap, sal_Int16& rnCharStyleRelief, bool& rbCharStyleContoured, bool& rbCharStyleShadowed, sal_Int16& rnCharStyleStrikeThrough, bool& rbCharStyleHidden); + // Set without throwing exceptions for unknown props, which is faster than throwing and then + // ignoring. + SW_DLLPUBLIC void setPropertyValueIgnoreUnknown(const OUString& aPropertyName, + const css::uno::Any& aValue); }; 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 3b5431225998..a1df24174d23 100644 --- a/sw/source/core/unocore/unostyle.cxx +++ b/sw/source/core/unocore/unostyle.cxx @@ -2040,7 +2040,7 @@ void SwXStyle::SetStyleProperty(const SfxItemPropertyMapEntry& rEntry, const Sfx } } -void SwXStyle::SetPropertyValues_Impl(const uno::Sequence<OUString>& rPropertyNames, const uno::Sequence<uno::Any>& rValues) +void SwXStyle::SetPropertyValues_Impl(const uno::Sequence<OUString>& rPropertyNames, const uno::Sequence<uno::Any>& rValues, bool bIgnoreUnknown) { if(!m_pDoc) throw uno::RuntimeException(); @@ -2068,7 +2068,11 @@ void SwXStyle::SetPropertyValues_Impl(const uno::Sequence<OUString>& rPropertyNa { const SfxItemPropertyMapEntry* pEntry = rMap.getByName(pNames[nProp]); if(!pEntry || (!m_bIsConditional && pNames[nProp] == UNO_NAME_PARA_STYLE_CONDITIONS)) + { + if (bIgnoreUnknown) + continue; throw beans::UnknownPropertyException("Unknown property: " + pNames[nProp], getXWeak()); + } if(pEntry->nFlags & beans::PropertyAttribute::READONLY) throw beans::PropertyVetoException ("Property is read-only: " + pNames[nProp], getXWeak()); if(aBaseImpl.getNewBase().is()) @@ -2087,7 +2091,7 @@ void SwXStyle::setPropertyValues(const uno::Sequence<OUString>& rPropertyNames, // workaround for bad designed API try { - SetPropertyValues_Impl( rPropertyNames, rValues ); + SetPropertyValues_Impl( rPropertyNames, rValues, /*bIgnoreUnknown*/false ); } catch (const beans::UnknownPropertyException &rException) { @@ -2561,7 +2565,15 @@ void SwXStyle::setPropertyValue(const OUString& rPropertyName, const uno::Any& r SolarMutexGuard aGuard; const uno::Sequence<OUString> aProperties(&rPropertyName, 1); const uno::Sequence<uno::Any> aValues(&rValue, 1); - SetPropertyValues_Impl(aProperties, aValues); + SetPropertyValues_Impl(aProperties, aValues, /*bIgnoreUnknown*/false); +} + +void SwXStyle::setPropertyValueIgnoreUnknown(const OUString& rPropertyName, const uno::Any& rValue) +{ + SolarMutexGuard aGuard; + const uno::Sequence<OUString> aProperties(&rPropertyName, 1); + const uno::Sequence<uno::Any> aValues(&rValue, 1); + SetPropertyValues_Impl(aProperties, aValues, /*bIgnoreUnknown*/true); } beans::PropertyState SwXStyle::getPropertyState(const OUString& rPropertyName) diff --git a/sw/source/writerfilter/dmapper/StyleSheetTable.cxx b/sw/source/writerfilter/dmapper/StyleSheetTable.cxx index 546d39ed9553..b796d02e93b6 100644 --- a/sw/source/writerfilter/dmapper/StyleSheetTable.cxx +++ b/sw/source/writerfilter/dmapper/StyleSheetTable.cxx @@ -2137,7 +2137,7 @@ OUString StyleSheetTable::getOrCreateCharStyle( const PropertyValueVector_t& rCh { try { - xStyle->setPropertyValue( rCharProp.Name, rCharProp.Value ); + xStyle->setPropertyValueIgnoreUnknown( rCharProp.Name, rCharProp.Value ); } catch( const uno::Exception& ) { commit 625c7541a9ed252c2f360ffb70bdd6b375527fda Author: Noel Grandin <[email protected]> AuthorDate: Tue Feb 3 15:56:29 2026 +0200 Commit: Miklos Vajna <[email protected]> CommitDate: Thu Feb 5 08:48:45 2026 +0100 tdf#170595 no need to call HasListCharStyle if we are just going to create a new style anyway Change-Id: Ib7c70b1fe64bd12ed2e500c0fee686f45b94985f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/198662 Reviewed-by: Miklos Vajna <[email protected]> Tested-by: Miklos Vajna <[email protected]> diff --git a/sw/source/writerfilter/dmapper/StyleSheetTable.cxx b/sw/source/writerfilter/dmapper/StyleSheetTable.cxx index 727534971ea0..546d39ed9553 100644 --- a/sw/source/writerfilter/dmapper/StyleSheetTable.cxx +++ b/sw/source/writerfilter/dmapper/StyleSheetTable.cxx @@ -2116,15 +2116,18 @@ void StyleSheetTable::applyDefaults(bool bParaProperties) OUString StyleSheetTable::getOrCreateCharStyle( const PropertyValueVector_t& rCharProperties, bool bAlwaysCreate ) { - //find out if any of the styles already has the required properties then return its name - OUString sListLabel = m_pImpl->HasListCharStyle(rCharProperties); - // Don't try to reuse an existing character style if requested. - if( !sListLabel.isEmpty() && !bAlwaysCreate) - return sListLabel; + if (!bAlwaysCreate) + { + //find out if any of the styles already has the required properties then return its name + OUString sListLabel = m_pImpl->HasListCharStyle(rCharProperties); + // Don't try to reuse an existing character style if requested. + if( !sListLabel.isEmpty()) + return sListLabel; + } //create a new one otherwise const rtl::Reference< SwXStyleFamily >& xCharStyles = m_pImpl->m_rDMapper.GetCharacterStyles(); - sListLabel = m_pImpl->m_rDMapper.GetUnusedCharacterStyleName(); + OUString sListLabel = m_pImpl->m_rDMapper.GetUnusedCharacterStyleName(); if (!m_pImpl->m_xTextDocument) throw uno::RuntimeException(); try
