chart2/source/controller/chartapiwrapper/ChartDataWrapper.cxx |    3 +
 chart2/source/controller/chartapiwrapper/DiagramWrapper.cxx   |   21 ++++++----
 sc/inc/chart2uno.hxx                                          |    4 +
 sc/source/ui/unoobj/chart2uno.cxx                             |   21 +++++++---
 4 files changed, 36 insertions(+), 13 deletions(-)

New commits:
commit fd2ca9607431fc6ca49e37ab6fef228aa72da5f9
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Tue Apr 19 14:24:46 2022 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Tue Apr 19 18:13:10 2022 +0200

    tdf#148635 cache some chart stuff
    
    cache some intermediate stuff that it does a handful of times when
    finishing a chart - halves the time taken
    
    Change-Id: I75c5621844d4309b64e64219a7c9e2bcd344ce36
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133173
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/chart2/source/controller/chartapiwrapper/DiagramWrapper.cxx 
b/chart2/source/controller/chartapiwrapper/DiagramWrapper.cxx
index 4327297360d4..9c7a2b5342f7 100644
--- a/chart2/source/controller/chartapiwrapper/DiagramWrapper.cxx
+++ b/chart2/source/controller/chartapiwrapper/DiagramWrapper.cxx
@@ -1118,7 +1118,8 @@ public:
 
 private: //member
     std::shared_ptr< Chart2ModelContact >   m_spChart2ModelContact;
-    mutable Any                                 m_aOuterValue;
+    mutable Any                             m_aOuterValue;
+    mutable bool                            m_bDetectedRangeSegmentation { 
false };
 };
 
 }
@@ -1172,15 +1173,19 @@ Any WrappedDataRowSourceProperty::getPropertyValue( 
const Reference< beans::XPro
     bool bHasCategories = true;
     uno::Sequence< sal_Int32 > aSequenceMapping;
 
-    if( DataSourceHelper::detectRangeSegmentation(
-            m_spChart2ModelContact->getDocumentModel(), aRangeString, 
aSequenceMapping, bUseColumns
-            , bFirstCellAsLabel, bHasCategories ) )
+    if (!m_bDetectedRangeSegmentation)
     {
-        css::chart::ChartDataRowSource eChartDataRowSource = 
css::chart::ChartDataRowSource_ROWS;
-        if(bUseColumns)
-            eChartDataRowSource = css::chart::ChartDataRowSource_COLUMNS;
+        if( DataSourceHelper::detectRangeSegmentation(
+                m_spChart2ModelContact->getDocumentModel(), aRangeString, 
aSequenceMapping, bUseColumns
+                , bFirstCellAsLabel, bHasCategories ) )
+        {
+            css::chart::ChartDataRowSource eChartDataRowSource = 
css::chart::ChartDataRowSource_ROWS;
+            if(bUseColumns)
+                eChartDataRowSource = css::chart::ChartDataRowSource_COLUMNS;
 
-        m_aOuterValue <<= eChartDataRowSource;
+            m_aOuterValue <<= eChartDataRowSource;
+        }
+        m_bDetectedRangeSegmentation = true;
     }
 
     return m_aOuterValue;
diff --git a/sc/inc/chart2uno.hxx b/sc/inc/chart2uno.hxx
index a5e4f53b032f..72a6374be739 100644
--- a/sc/inc/chart2uno.hxx
+++ b/sc/inc/chart2uno.hxx
@@ -147,6 +147,10 @@ private:
     ScDocument*                 m_pDocument;
     SfxItemPropertySet          m_aPropSet;
     bool                        m_bIncludeHiddenCells;
+    css::uno::Reference< css::chart2::data::XDataSource > mxCachedDataSource;
+    css::uno::Sequence< css::beans::PropertyValue > maCachedArguments;
+    css::uno::Sequence< css::beans::PropertyValue > 
maCreateDataSourceArguments;
+    css::uno::Reference< css::chart2::data::XDataSource > mxCreatedDataSource;
 };
 
 // DataSource
diff --git a/sc/source/ui/unoobj/chart2uno.cxx 
b/sc/source/ui/unoobj/chart2uno.cxx
index adc244bacc78..9ca2e73bd4ec 100644
--- a/sc/source/ui/unoobj/chart2uno.cxx
+++ b/sc/source/ui/unoobj/chart2uno.cxx
@@ -1403,7 +1403,11 @@ ScChart2DataProvider::createDataSource(
     if ( ! m_pDocument )
         throw uno::RuntimeException();
 
-    uno::Reference< chart2::data::XDataSource> xResult;
+    // This is expensive to compute and we get called more than once, so cache
+    if (maCreateDataSourceArguments == aArguments)
+        return mxCreatedDataSource;
+    maCreateDataSourceArguments = aArguments;
+
     bool bLabel = true;
     bool bCategories = false;
     bool bOrientCol = true;
@@ -1490,7 +1494,7 @@ ScChart2DataProvider::createDataSource(
     const Chart2PositionMap* pChartMap = aChPositioner.getPositionMap();
     if (!pChartMap)
         // No chart position map instance.  Bail out.
-        return xResult;
+        return mxCreatedDataSource;
 
     rtl::Reference<ScChart2DataSource> pDS;
     ::std::vector< uno::Reference< chart2::data::XLabeledDataSequence > > 
aSeqs;
@@ -1568,8 +1572,8 @@ ScChart2DataProvider::createDataSource(
         }
     }
 
-    xResult.set( pDS );
-    return xResult;
+    mxCreatedDataSource.set(pDS);
+    return mxCreatedDataSource;
 }
 
 namespace
@@ -1761,6 +1765,10 @@ std::pair<OUString, OUString> constructKey(const 
uno::Reference< chart2::data::X
 uno::Sequence< beans::PropertyValue > SAL_CALL 
ScChart2DataProvider::detectArguments(
     const uno::Reference< chart2::data::XDataSource >& xDataSource )
 {
+    // Cache these because this is expensive to compute and we get called more 
than once
+    if (xDataSource == mxCachedDataSource)
+        return maCachedArguments;
+
     ::std::vector< beans::PropertyValue > aResult;
     bool bRowSourceDetected = false;
     bool bFirstCellAsLabel = false;
@@ -2026,7 +2034,10 @@ uno::Sequence< beans::PropertyValue > SAL_CALL 
ScChart2DataProvider::detectArgum
         }
     }
 
-    return comphelper::containerToSequence( aResult );
+    mxCachedDataSource = xDataSource;
+    maCachedArguments = comphelper::containerToSequence( aResult );
+
+    return maCachedArguments;
 }
 
 sal_Bool SAL_CALL 
ScChart2DataProvider::createDataSequenceByRangeRepresentationPossible( const 
OUString& aRangeRepresentation )
commit 6500106dff0f0cd86f509ffd01542aab77c21596
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Tue Apr 19 13:48:55 2022 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Tue Apr 19 18:12:55 2022 +0200

    tdf#148635 no need to init ChartDataWrapper more than once
    
    halves the time to finish a chart2
    
    Change-Id: Ib7f066672878f7630c2d1c90b9487a14f2048029
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133172
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/chart2/source/controller/chartapiwrapper/ChartDataWrapper.cxx 
b/chart2/source/controller/chartapiwrapper/ChartDataWrapper.cxx
index 3afac39a2ce8..6050af15319f 100644
--- a/chart2/source/controller/chartapiwrapper/ChartDataWrapper.cxx
+++ b/chart2/source/controller/chartapiwrapper/ChartDataWrapper.cxx
@@ -577,11 +577,14 @@ void ChartDataWrapper::switchToInternalDataProvider()
     rtl::Reference< ChartModel > xChartDoc( 
m_spChart2ModelContact->getDocumentModel() );
     if( xChartDoc.is() )
         xChartDoc->createInternalDataProvider( true /*bCloneExistingData*/ );
+    m_xDataAccess.clear();
     initDataAccess();
 }
 
 void ChartDataWrapper::initDataAccess()
 {
+    if (m_xDataAccess)
+        return;
     rtl::Reference< ChartModel > xChartDoc( 
m_spChart2ModelContact->getDocumentModel() );
     if( !xChartDoc.is() )
         return;

Reply via email to