chart2/source/view/inc/VDataSeries.hxx | 27 +++++----- chart2/source/view/main/VDataSeries.cxx | 82 ++++++++++++++++---------------- 2 files changed, 55 insertions(+), 54 deletions(-)
New commits: commit 4def1399b17792e14882152c58b7f1f8d46aedfd Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Wed Mar 1 12:00:29 2023 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Wed Mar 1 13:11:32 2023 +0000 allocate cached values inline in VDataSeries to reduce pointer chasing - these values are all small Change-Id: I96782494f26666657bf35c06136b4b87f29fdd2a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148039 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/chart2/source/view/inc/VDataSeries.hxx b/chart2/source/view/inc/VDataSeries.hxx index 29a71918b549..0ab4fffe0e93 100644 --- a/chart2/source/view/inc/VDataSeries.hxx +++ b/chart2/source/view/inc/VDataSeries.hxx @@ -20,7 +20,9 @@ #include "PropertyMapper.hxx" +#include <com/sun/star/chart2/DataPointLabel.hpp> #include <com/sun/star/chart2/StackingDirection.hpp> +#include <com/sun/star/chart2/Symbol.hpp> #include <com/sun/star/drawing/Position3D.hpp> #include <com/sun/star/awt/Size.hpp> #include <com/sun/star/awt/Point.hpp> @@ -34,8 +36,6 @@ namespace com::sun::star::beans { class XPropertySet; } namespace com::sun::star::chart2 { class XChartType; } namespace com::sun::star::chart2 { class XDataSeries; } namespace com::sun::star::chart2::data { class XDataSequence; } -namespace com::sun::star::chart2 { struct DataPointLabel; } -namespace com::sun::star::chart2 { struct Symbol; } namespace com::sun::star::drawing { class XShapes; } namespace chart @@ -238,20 +238,19 @@ private: //member sal_Int32 m_nGlobalSeriesIndex; //some cached values for data labels as they are very expensive - mutable std::unique_ptr<css::chart2::DataPointLabel> - m_apLabel_Series; - mutable std::unique_ptr<tNameSequence> m_apLabelPropNames_Series; - mutable std::unique_ptr<tAnySequence> m_apLabelPropValues_Series; - mutable std::unique_ptr<css::chart2::Symbol> m_apSymbolProperties_Series; - - mutable std::unique_ptr<css::chart2::DataPointLabel> - m_apLabel_AttributedPoint; + mutable std::optional<css::chart2::DataPointLabel> + m_oLabel_Series; + mutable std::optional<tNameSequence> m_oLabelPropNames_Series; + mutable std::optional<tAnySequence> m_oLabelPropValues_Series; + mutable std::optional<css::chart2::Symbol> m_oSymbolProperties_Series; + + mutable std::optional<css::chart2::DataPointLabel> + m_oLabel_AttributedPoint; mutable std::unique_ptr<tNameSequence> m_apLabelPropNames_AttributedPoint; mutable std::unique_ptr<tAnySequence> m_apLabelPropValues_AttributedPoint; - mutable std::unique_ptr<css::chart2::Symbol> m_apSymbolProperties_AttributedPoint; - mutable std::unique_ptr<css::chart2::Symbol> - m_apSymbolProperties_InvisibleSymbolForSelection; - mutable sal_Int32 m_nCurrentAttributedPoint; + mutable std::optional<css::chart2::Symbol> m_oSymbolProperties_AttributedPoint; + mutable std::optional<css::chart2::Symbol> m_oSymbolProperties_InvisibleSymbolForSelection; + mutable sal_Int32 m_nCurrentAttributedPoint; css::awt::Size m_aReferenceSize; sal_Int32 m_nMissingValueTreatment; diff --git a/chart2/source/view/main/VDataSeries.cxx b/chart2/source/view/main/VDataSeries.cxx index 81a975496d8e..d1dc3db8a09c 100644 --- a/chart2/source/view/main/VDataSeries.cxx +++ b/chart2/source/view/main/VDataSeries.cxx @@ -765,26 +765,26 @@ double VDataSeries::getYMeanValue() const return m_fYMeanValue; } -static std::unique_ptr<Symbol> getSymbolPropertiesFromPropertySet( const uno::Reference< beans::XPropertySet >& xProp ) +static std::optional<Symbol> getSymbolPropertiesFromPropertySet( const uno::Reference< beans::XPropertySet >& xProp ) { - std::unique_ptr< Symbol > apSymbolProps( new Symbol() ); + Symbol aSymbolProps; try { - if( xProp->getPropertyValue("Symbol") >>= *apSymbolProps ) + if( xProp->getPropertyValue("Symbol") >>= aSymbolProps ) { //use main color to fill symbols - xProp->getPropertyValue("Color") >>= apSymbolProps->FillColor; + xProp->getPropertyValue("Color") >>= aSymbolProps.FillColor; // border of symbols always same as fill color - apSymbolProps->BorderColor = apSymbolProps->FillColor; + aSymbolProps.BorderColor = aSymbolProps.FillColor; } else - apSymbolProps.reset(); + return std::nullopt; } catch(const uno::Exception &) { TOOLS_WARN_EXCEPTION("chart2", "" ); } - return apSymbolProps; + return aSymbolProps; } Symbol* VDataSeries::getSymbolProperties( sal_Int32 index ) const @@ -793,38 +793,38 @@ Symbol* VDataSeries::getSymbolProperties( sal_Int32 index ) const if( isAttributedDataPoint( index ) ) { adaptPointCache( index ); - if (!m_apSymbolProperties_AttributedPoint) - m_apSymbolProperties_AttributedPoint + if (!m_oSymbolProperties_AttributedPoint) + m_oSymbolProperties_AttributedPoint = getSymbolPropertiesFromPropertySet(getPropertiesOfPoint(index)); - pRet = m_apSymbolProperties_AttributedPoint.get(); + pRet = &*m_oSymbolProperties_AttributedPoint; //if a single data point does not have symbols but the dataseries itself has symbols //we create an invisible symbol shape to enable selection of that point if( !pRet || pRet->Style == SymbolStyle_NONE ) { - if (!m_apSymbolProperties_Series) - m_apSymbolProperties_Series + if (!m_oSymbolProperties_Series) + m_oSymbolProperties_Series = getSymbolPropertiesFromPropertySet(getPropertiesOfSeries()); - if( m_apSymbolProperties_Series && m_apSymbolProperties_Series->Style != SymbolStyle_NONE ) + if( m_oSymbolProperties_Series && m_oSymbolProperties_Series->Style != SymbolStyle_NONE ) { - if (!m_apSymbolProperties_InvisibleSymbolForSelection) + if (!m_oSymbolProperties_InvisibleSymbolForSelection) { - m_apSymbolProperties_InvisibleSymbolForSelection.reset(new Symbol); - m_apSymbolProperties_InvisibleSymbolForSelection->Style = SymbolStyle_STANDARD; - m_apSymbolProperties_InvisibleSymbolForSelection->StandardSymbol = 0;//square - m_apSymbolProperties_InvisibleSymbolForSelection->Size = com::sun::star::awt::Size(0, 0);//tdf#126033 - m_apSymbolProperties_InvisibleSymbolForSelection->BorderColor = 0xff000000;//invisible - m_apSymbolProperties_InvisibleSymbolForSelection->FillColor = 0xff000000;//invisible + m_oSymbolProperties_InvisibleSymbolForSelection.emplace(); + m_oSymbolProperties_InvisibleSymbolForSelection->Style = SymbolStyle_STANDARD; + m_oSymbolProperties_InvisibleSymbolForSelection->StandardSymbol = 0;//square + m_oSymbolProperties_InvisibleSymbolForSelection->Size = com::sun::star::awt::Size(0, 0);//tdf#126033 + m_oSymbolProperties_InvisibleSymbolForSelection->BorderColor = 0xff000000;//invisible + m_oSymbolProperties_InvisibleSymbolForSelection->FillColor = 0xff000000;//invisible } - pRet = m_apSymbolProperties_InvisibleSymbolForSelection.get(); + pRet = &*m_oSymbolProperties_InvisibleSymbolForSelection; } } } else { - if (!m_apSymbolProperties_Series) - m_apSymbolProperties_Series + if (!m_oSymbolProperties_Series) + m_oSymbolProperties_Series = getSymbolPropertiesFromPropertySet(getPropertiesOfSeries()); - pRet = m_apSymbolProperties_Series.get(); + pRet = &*m_oSymbolProperties_Series; } if( pRet && pRet->Style == SymbolStyle_AUTO ) @@ -911,9 +911,9 @@ const uno::Reference<beans::XPropertySet> & VDataSeries::getPropertiesOfSeries() return m_xDataSeriesProps; } -static std::unique_ptr<DataPointLabel> getDataPointLabelFromPropertySet( const uno::Reference< beans::XPropertySet >& xProp ) +static std::optional<DataPointLabel> getDataPointLabelFromPropertySet( const uno::Reference< beans::XPropertySet >& xProp ) { - std::unique_ptr< DataPointLabel > apLabel( new DataPointLabel() ); + std::optional< DataPointLabel > apLabel( std::in_place ); try { if( !(xProp->getPropertyValue(CHART_UNONAME_LABEL) >>= *apLabel) ) @@ -930,10 +930,10 @@ void VDataSeries::adaptPointCache( sal_Int32 nNewPointIndex ) const { if( m_nCurrentAttributedPoint != nNewPointIndex ) { - m_apLabel_AttributedPoint.reset(); + m_oLabel_AttributedPoint.reset(); m_apLabelPropNames_AttributedPoint.reset(); m_apLabelPropValues_AttributedPoint.reset(); - m_apSymbolProperties_AttributedPoint.reset(); + m_oSymbolProperties_AttributedPoint.reset(); m_nCurrentAttributedPoint = nNewPointIndex; } } @@ -944,17 +944,19 @@ DataPointLabel* VDataSeries::getDataPointLabel( sal_Int32 index ) const if( isAttributedDataPoint( index ) ) { adaptPointCache( index ); - if (!m_apLabel_AttributedPoint) - m_apLabel_AttributedPoint + if (!m_oLabel_AttributedPoint) + m_oLabel_AttributedPoint = getDataPointLabelFromPropertySet(getPropertiesOfPoint(index)); - pRet = m_apLabel_AttributedPoint.get(); + if (m_oLabel_AttributedPoint) + pRet = &*m_oLabel_AttributedPoint; } else { - if (!m_apLabel_Series) - m_apLabel_Series + if (!m_oLabel_Series) + m_oLabel_Series = getDataPointLabelFromPropertySet(getPropertiesOfPoint(index)); - pRet = m_apLabel_Series.get(); + if (m_oLabel_Series) + pRet = &*m_oLabel_Series; } if( !m_bAllowPercentValueInDataLabel ) { @@ -998,18 +1000,18 @@ bool VDataSeries::getTextLabelMultiPropertyLists( sal_Int32 index } else { - if (!m_apLabelPropValues_Series) + if (!m_oLabelPropValues_Series) { // Cache these properties for the whole series. - m_apLabelPropNames_Series.reset(new tNameSequence); - m_apLabelPropValues_Series.reset(new tAnySequence); + m_oLabelPropNames_Series.emplace(); + m_oLabelPropValues_Series.emplace(); xTextProp.set( getPropertiesOfPoint( index )); PropertyMapper::getTextLabelMultiPropertyLists( - xTextProp, *m_apLabelPropNames_Series, *m_apLabelPropValues_Series); + xTextProp, *m_oLabelPropNames_Series, *m_oLabelPropValues_Series); bDoDynamicFontResize = true; } - pPropNames = m_apLabelPropNames_Series.get(); - pPropValues = m_apLabelPropValues_Series.get(); + pPropNames = &*m_oLabelPropNames_Series; + pPropValues = &*m_oLabelPropValues_Series; } if( bDoDynamicFontResize &&