include/svl/itemprop.hxx            |    8 ++++-
 svl/source/items/itemprop.cxx       |   12 ++++++--
 sw/inc/unoxstyle.hxx                |    8 +++--
 sw/source/core/unocore/unostyle.cxx |   50 ++++++++++++++++++------------------
 4 files changed, 45 insertions(+), 33 deletions(-)

New commits:
commit a4f0e30df3ede9b5172398fc8b2c95d8c23bfbfd
Author:     Noel Grandin <[email protected]>
AuthorDate: Wed Feb 4 08:37:23 2026 +0200
Commit:     Noel Grandin <[email protected]>
CommitDate: Fri Feb 6 15:46: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/+/198641
    Reviewed-by: Noel Grandin <[email protected]>
    Tested-by: Jenkins

diff --git a/include/svl/itemprop.hxx b/include/svl/itemprop.hxx
index ad3cd5fcccb2..0447189e93b9 100644
--- a/include/svl/itemprop.hxx
+++ b/include/svl/itemprop.hxx
@@ -122,17 +122,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 74ce5c9f527b..4813acdecb5a 100644
--- a/svl/source/items/itemprop.cxx
+++ b/svl/source/items/itemprop.cxx
@@ -164,7 +164,7 @@ 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;
@@ -177,21 +177,27 @@ void SfxItemPropertySet::setPropertyValue( const 
SfxItemPropertyMapEntry& rEntry
     if(!pNewItem)
         return;
     if( !pNewItem->PutValue( aVal, rEntry.nMemberId ) )
+    {
+        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 39c8a33f5cf5..f38bfc6b680e 100644
--- a/sw/source/core/unocore/unostyle.cxx
+++ b/sw/source/core/unocore/unostyle.cxx
@@ -3832,18 +3832,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 2ac14cf4e70b9384b33872cc4eb8d022a1fc3e11
Author:     Noel Grandin <[email protected]>
AuthorDate: Tue Feb 3 16:51:26 2026 +0200
Commit:     Noel Grandin <[email protected]>
CommitDate: Fri Feb 6 15:46:13 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/+/198610
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <[email protected]>

diff --git a/sw/inc/unoxstyle.hxx b/sw/inc/unoxstyle.hxx
index d11a761974a1..020fc793487c 100644
--- a/sw/inc/unoxstyle.hxx
+++ b/sw/inc/unoxstyle.hxx
@@ -35,6 +35,7 @@
 #include "coreframestyle.hxx"
 #include "unobasestyle.hxx"
 #include "names.hxx"
+#include <span>
 
 class StyleFamilyEntry;
 class SwStyleBase_Impl;
@@ -81,9 +82,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>
@@ -224,6 +224,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 77d6a35949d7..39c8a33f5cf5 100644
--- a/sw/source/core/unocore/unostyle.cxx
+++ b/sw/source/core/unocore/unostyle.cxx
@@ -558,11 +558,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);
     }
 };
 
@@ -2043,14 +2049,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
@@ -2065,22 +2076,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();
     }
 
@@ -2094,7 +2103,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)
     {

Reply via email to