chart2/source/view/inc/PropertyMapper.hxx  |    7 -
 chart2/source/view/main/PropertyMapper.cxx |  122 +++++++++++++++++++++++++----
 2 files changed, 106 insertions(+), 23 deletions(-)

New commits:
commit e951937950e68be7b93093879e943211ae7f1601
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Tue Jan 4 17:05:50 2022 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Tue Jan 4 17:49:22 2022 +0100

    speed up setting properties in chart2
    
    can skip the intermediate map
    
    Change-Id: I53b6e7f88c7ff1c4dd84b6e7f4f4ff8b066166b1
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127967
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/chart2/source/view/inc/PropertyMapper.hxx 
b/chart2/source/view/inc/PropertyMapper.hxx
index 0d208094ee8e..3f627aae3163 100644
--- a/chart2/source/view/inc/PropertyMapper.hxx
+++ b/chart2/source/view/inc/PropertyMapper.hxx
@@ -71,13 +71,6 @@ public:
         , const css::uno::Reference< css::beans::XPropertySet >& xSourceProp
         );
 
-    static void getMultiPropertyLists(
-                  tNameSequence& rNames
-                , tAnySequence&  rValues
-                , const css::uno::Reference< css::beans::XPropertySet >& xProp
-                , const tPropertyNameMap& rMap
-                );
-
     static void getMultiPropertyListsFromValueMap(
                   tNameSequence& rNames
                 , tAnySequence&  rValues
diff --git a/chart2/source/view/main/PropertyMapper.cxx 
b/chart2/source/view/main/PropertyMapper.cxx
index 6f78cad7815a..e9e46998af7a 100644
--- a/chart2/source/view/main/PropertyMapper.cxx
+++ b/chart2/source/view/main/PropertyMapper.cxx
@@ -44,8 +44,48 @@ void PropertyMapper::setMappedProperties(
 
     tNameSequence aNames;
     tAnySequence  aValues;
-    getMultiPropertyLists(aNames, aValues, xSource, rMap );
-    PropertyMapper::setMultiProperties( aNames, aValues, xTarget );
+    sal_Int32 nN=0;
+    sal_Int32 nPropertyCount = rMap.size();
+    aNames.realloc(nPropertyCount);
+    auto pNames = aNames.getArray();
+    aValues.realloc(nPropertyCount);
+    auto pValues = aValues.getArray();
+
+    for (auto const& elem : rMap)
+    {
+        const OUString & rTarget = elem.first;
+        const OUString & rSource = elem.second;
+        try
+        {
+            uno::Any aAny( xSource->getPropertyValue(rSource) );
+            if( aAny.hasValue() )
+            {
+                //do not set empty anys because of performance (otherwise 
SdrAttrObj::ItemChange will take much longer)
+                pNames[nN]  = rTarget;
+                pValues[nN] = aAny;
+                ++nN;
+            }
+        }
+        catch( const uno::Exception& )
+        {
+            TOOLS_WARN_EXCEPTION("chart2", "" );
+        }
+    }
+    if (nN == 0)
+        return;
+    //reduce to real property count
+    aNames.realloc(nN);
+    aValues.realloc(nN);
+
+    uno::Reference< beans::XMultiPropertySet > xShapeMultiProp( xTarget, 
uno::UNO_QUERY_THROW );
+    try
+    {
+        xShapeMultiProp->setPropertyValues( aNames, aValues );
+    }
+    catch( const uno::Exception& )
+    {
+        TOOLS_WARN_EXCEPTION("chart2", "" ); //if this occurs more often think 
of removing the XMultiPropertySet completely for better performance
+    }
 }
 
 void PropertyMapper::setMappedProperties(
@@ -58,8 +98,70 @@ void PropertyMapper::setMappedProperties(
 
     tNameSequence aNames;
     tAnySequence  aValues;
-    getMultiPropertyLists(aNames, aValues, xSource, rMap );
-    PropertyMapper::setMultiProperties( aNames, aValues, xTarget );
+    sal_Int32 nN=0;
+    sal_Int32 nPropertyCount = rMap.size();
+    aNames.realloc(nPropertyCount);
+    auto pNames = aNames.getArray();
+    aValues.realloc(nPropertyCount);
+    auto pValues = aValues.getArray();
+
+    for (auto const& elem : rMap)
+    {
+        const OUString & rTarget = elem.first;
+        const OUString & rSource = elem.second;
+        try
+        {
+            uno::Any aAny( xSource->getPropertyValue(rSource) );
+            if( aAny.hasValue() )
+            {
+                //do not set empty anys because of performance (otherwise 
SdrAttrObj::ItemChange will take much longer)
+                pNames[nN]  = rTarget;
+                pValues[nN] = aAny;
+                ++nN;
+            }
+        }
+        catch( const uno::Exception& )
+        {
+            TOOLS_WARN_EXCEPTION("chart2", "" );
+        }
+    }
+    if (nN == 0)
+        return;
+
+    uno::Reference< beans::XMultiPropertySet > xShapeMultiProp( xTarget, 
uno::UNO_QUERY );
+    if (xShapeMultiProp)
+        try
+        {
+            //reduce to real property count
+            aNames.realloc(nN);
+            aValues.realloc(nN);
+            xShapeMultiProp->setPropertyValues( aNames, aValues );
+            return; // successful
+        }
+        catch( const uno::Exception& )
+        {
+            TOOLS_WARN_EXCEPTION("chart2", "" ); //if this occurs more often 
think of removing the XMultiPropertySet completely for better performance
+        }
+
+    // fall back to one at a time
+    try
+    {
+        for( sal_Int32 i = 0; i < nN; i++ )
+        {
+            try
+            {
+                xTarget->setPropertyValue( aNames[i], aValues[i] );
+            }
+            catch( const uno::Exception& )
+            {
+                TOOLS_WARN_EXCEPTION("chart2", "" );
+            }
+        }
+    }
+    catch( const uno::Exception& )
+    {
+        TOOLS_WARN_EXCEPTION("chart2", "" );
+    }
 }
 
 void PropertyMapper::getValueMap(
@@ -111,18 +213,6 @@ void PropertyMapper::getValueMap(
     }
 }
 
-void PropertyMapper::getMultiPropertyLists(
-                  tNameSequence& rNames
-                , tAnySequence&  rValues
-                , const uno::Reference< beans::XPropertySet >& xSourceProp
-                , const tPropertyNameMap& rNameMap
-                )
-{
-    tPropertyNameValueMap aValueMap;
-    getValueMap( aValueMap, rNameMap, xSourceProp );
-    getMultiPropertyListsFromValueMap( rNames, rValues, aValueMap );
-}
-
 void PropertyMapper::getMultiPropertyListsFromValueMap(
                   tNameSequence& rNames
                 , tAnySequence&  rValues

Reply via email to