sw/inc/unoxstyle.hxx | 8 ++++--- sw/source/core/unocore/unostyle.cxx | 37 +++++++++++++++++++++++------------- 2 files changed, 29 insertions(+), 16 deletions(-)
New commits: commit ae521367faa960086d05f9b182d42e61a2a56169 Author: Noel Grandin <[email protected]> AuthorDate: Tue Feb 3 16:51:26 2026 +0200 Commit: Miklos Vajna <[email protected]> CommitDate: Thu Feb 5 16:42:02 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]> diff --git a/sw/inc/unoxstyle.hxx b/sw/inc/unoxstyle.hxx index fb78d5f89aba..74130a967e47 100644 --- a/sw/inc/unoxstyle.hxx +++ b/sw/inc/unoxstyle.hxx @@ -33,6 +33,7 @@ #include <osl/diagnose.h> #include "coreframestyle.hxx" #include "unobasestyle.hxx" +#include <span> class StyleFamilyEntry; class SwStyleBase_Impl; @@ -79,9 +80,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> @@ -222,6 +222,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 ebdcf00fc230..c32226a949a9 100644 --- a/sw/source/core/unocore/unostyle.cxx +++ b/sw/source/core/unocore/unostyle.cxx @@ -557,11 +557,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); } }; @@ -2037,14 +2043,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 @@ -2059,22 +2070,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(); } @@ -2088,7 +2097,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) {
