summaryrefslogtreecommitdiffstats
path: root/chart2
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2021-10-13 09:02:48 +0300
committerMike Kaganski <mike.kaganski@collabora.com>2021-10-14 06:00:49 +0200
commit8a017d25a62e878fdd32f189f0663b05d2ffb9cf (patch)
treec91ee53b5d9276ae30df785b52579a1b77a057df /chart2
parentsw: remove unused document (diff)
downloadcore-8a017d25a62e878fdd32f189f0663b05d2ffb9cf.tar.gz
core-8a017d25a62e878fdd32f189f0663b05d2ffb9cf.zip
Avoid COW overhead using css::uno::Sequence
The scenarios are: 1. Calling sequence's begin() and end() in pairs to pass to algorithms (both calls use getArray(), which does the COW checks) 2. In addition to #1, calling end() again when checking result of find algorithms, and/or begin() to calculate result's distance 3. Using non-const sequences in range-based for loops, which internally do #1 4. Assigning sequence to another sequence variable, and then modifying one of them In many cases, the sequences could be made const, or treated as const for the purposes of the algorithms (using std::as_const, std::cbegin, and std::cend). Where algorithm modifies the sequence, it was changed to only call getArray() once. For that, css::uno::toNonConstRange was introduced, which returns a struct (sublclass of std::pair) with two iterators [begin, end], that are calculated using one call to begin() and one call to getLength(). To handle #4, css::uno::Sequence::swap was introduced, that swaps the internal pointer to uno_Sequence. So when a local Sequence variable should be assigned to another variable, and the latter will be modified further, it's now possible to use swap instead, so the two sequences are kept independent. The modified places were found by temporarily removing non-const end(). Change-Id: I8fe2787f200eecb70744e8b77fbdf7a49653f628 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/123542 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'chart2')
-rw-r--r--chart2/qa/extras/chart2import.cxx2
-rw-r--r--chart2/qa/extras/charttest.hxx4
-rw-r--r--chart2/source/controller/dialogs/DialogModel.cxx2
-rw-r--r--chart2/source/controller/main/ObjectHierarchy.cxx2
-rw-r--r--chart2/source/model/template/ColumnLineChartTypeTemplate.cxx2
-rw-r--r--chart2/source/tools/DataSeriesHelper.cxx2
-rw-r--r--chart2/source/tools/DataSourceHelper.cxx4
-rw-r--r--chart2/source/tools/DiagramHelper.cxx4
-rw-r--r--chart2/source/tools/InternalDataProvider.cxx10
-rw-r--r--chart2/source/tools/UncachedDataSequence.cxx4
10 files changed, 17 insertions, 19 deletions
diff --git a/chart2/qa/extras/chart2import.cxx b/chart2/qa/extras/chart2import.cxx
index 682f24febca0..e908cfc57a71 100644
--- a/chart2/qa/extras/chart2import.cxx
+++ b/chart2/qa/extras/chart2import.cxx
@@ -2001,7 +2001,7 @@ void Chart2ImportTest::testTdf116163()
CPPUNIT_ASSERT(xTextualDataSequence.is());
std::vector<OUString> aCategories;
- Sequence<OUString> aTextData(xTextualDataSequence->getTextualData());
+ const Sequence<OUString> aTextData(xTextualDataSequence->getTextualData());
::std::copy(aTextData.begin(), aTextData.end(),
::std::back_inserter(aCategories));
diff --git a/chart2/qa/extras/charttest.hxx b/chart2/qa/extras/charttest.hxx
index 9094ab308afb..2aec79cfccb0 100644
--- a/chart2/qa/extras/charttest.hxx
+++ b/chart2/qa/extras/charttest.hxx
@@ -102,8 +102,8 @@ public:
OUString findChartFile(const OUString& rDir, uno::Reference< container::XNameAccess > const & xNames )
{
- uno::Sequence<OUString> aNames = xNames->getElementNames();
- OUString* pElement = std::find_if(aNames.begin(), aNames.end(), CheckForChartName(rDir));
+ const uno::Sequence<OUString> aNames = xNames->getElementNames();
+ const OUString* pElement = std::find_if(aNames.begin(), aNames.end(), CheckForChartName(rDir));
CPPUNIT_ASSERT(pElement != aNames.end());
return *pElement;
diff --git a/chart2/source/controller/dialogs/DialogModel.cxx b/chart2/source/controller/dialogs/DialogModel.cxx
index b88d1f205d5d..774e395e8951 100644
--- a/chart2/source/controller/dialogs/DialogModel.cxx
+++ b/chart2/source/controller/dialogs/DialogModel.cxx
@@ -473,7 +473,7 @@ std::vector< Reference< XDataSeriesContainer > >
for( Reference< XCoordinateSystem > const & coords : aCooSysSeq )
{
Reference< XChartTypeContainer > xCTCnt( coords, uno::UNO_QUERY_THROW );
- Sequence< Reference< XChartType > > aChartTypeSeq( xCTCnt->getChartTypes());
+ const Sequence< Reference< XChartType > > aChartTypeSeq( xCTCnt->getChartTypes());
std::transform(
aChartTypeSeq.begin(), aChartTypeSeq.end(),
std::back_inserter( aResult ),
diff --git a/chart2/source/controller/main/ObjectHierarchy.cxx b/chart2/source/controller/main/ObjectHierarchy.cxx
index 1383160e2c65..7934f58fc4d0 100644
--- a/chart2/source/controller/main/ObjectHierarchy.cxx
+++ b/chart2/source/controller/main/ObjectHierarchy.cxx
@@ -246,7 +246,7 @@ void ObjectHierarchy::createAxesTree(
Sequence< Reference< XAxis > > aAxes( AxisHelper::getAllAxesOfDiagram( xDiagram, /* bOnlyVisible = */ true ) );
if( !m_bOrderingForElementSelector )
- std::transform( aAxes.begin(), aAxes.end(),
+ std::transform( std::cbegin(aAxes), std::cend(aAxes),
std::back_inserter( rContainer ),
lcl_ObjectToOID( xChartDoc ));
diff --git a/chart2/source/model/template/ColumnLineChartTypeTemplate.cxx b/chart2/source/model/template/ColumnLineChartTypeTemplate.cxx
index 560332b81e98..889ca43f40e7 100644
--- a/chart2/source/model/template/ColumnLineChartTypeTemplate.cxx
+++ b/chart2/source/model/template/ColumnLineChartTypeTemplate.cxx
@@ -169,7 +169,7 @@ void ColumnLineChartTypeTemplate::createChartTypes(
{
Reference< lang::XMultiServiceFactory > xFact(
GetComponentContext()->getServiceManager(), uno::UNO_QUERY_THROW );
- Sequence< Reference< XDataSeries > > aFlatSeriesSeq( FlattenSequence( aSeriesSeq ));
+ const Sequence< Reference< XDataSeries > > aFlatSeriesSeq( FlattenSequence( aSeriesSeq ));
sal_Int32 nNumberOfSeries = aFlatSeriesSeq.getLength();
sal_Int32 nNumberOfLines = 0;
sal_Int32 nNumberOfColumns = 0;
diff --git a/chart2/source/tools/DataSeriesHelper.cxx b/chart2/source/tools/DataSeriesHelper.cxx
index 9f17273c1607..af3c16190633 100644
--- a/chart2/source/tools/DataSeriesHelper.cxx
+++ b/chart2/source/tools/DataSeriesHelper.cxx
@@ -246,7 +246,7 @@ getAllDataSequences( const uno::Sequence<uno::Reference<chart2::XDataSeries> >&
Reference< chart2::data::XDataSource > xSource( dataSeries, uno::UNO_QUERY );
if( xSource.is())
{
- Sequence< Reference< chart2::data::XLabeledDataSequence > > aSeq( xSource->getDataSequences());
+ const Sequence< Reference< chart2::data::XLabeledDataSequence > > aSeq( xSource->getDataSequences());
aSeqVec.insert( aSeqVec.end(), aSeq.begin(), aSeq.end() );
}
}
diff --git a/chart2/source/tools/DataSourceHelper.cxx b/chart2/source/tools/DataSourceHelper.cxx
index 7722da5e6e60..679b625948e0 100644
--- a/chart2/source/tools/DataSourceHelper.cxx
+++ b/chart2/source/tools/DataSourceHelper.cxx
@@ -301,7 +301,7 @@ uno::Reference< chart2::data::XDataSource > DataSourceHelper::getUsedData(
uno::Reference< data::XDataSource > xDataSource(series, uno::UNO_QUERY);
if( !xDataSource.is() )
continue;
- uno::Sequence< uno::Reference< data::XLabeledDataSequence > > aDataSequences( xDataSource->getDataSequences() );
+ const uno::Sequence< uno::Reference< data::XLabeledDataSequence > > aDataSequences( xDataSource->getDataSequences() );
aResult.insert( aResult.end(), aDataSequences.begin(), aDataSequences.end() );
}
@@ -325,7 +325,7 @@ uno::Reference< chart2::data::XDataSource > DataSourceHelper::getUsedData(
uno::Reference< data::XDataSource > xDataSource(series, uno::UNO_QUERY);
if( !xDataSource.is() )
continue;
- uno::Sequence< uno::Reference< data::XLabeledDataSequence > > aDataSequences( xDataSource->getDataSequences() );
+ const uno::Sequence< uno::Reference< data::XLabeledDataSequence > > aDataSequences( xDataSource->getDataSequences() );
aResult.insert( aResult.end(), aDataSequences.begin(), aDataSequences.end() );
}
diff --git a/chart2/source/tools/DiagramHelper.cxx b/chart2/source/tools/DiagramHelper.cxx
index ae6766aecaef..3a1d06bdcf24 100644
--- a/chart2/source/tools/DiagramHelper.cxx
+++ b/chart2/source/tools/DiagramHelper.cxx
@@ -672,7 +672,7 @@ std::vector< Reference< XDataSeries > >
for( Reference< XChartType> const & chartType : aChartTypeSeq )
{
Reference< XDataSeriesContainer > xDSCnt( chartType, uno::UNO_QUERY_THROW );
- Sequence< Reference< XDataSeries > > aSeriesSeq( xDSCnt->getDataSeries() );
+ const Sequence< Reference< XDataSeries > > aSeriesSeq( xDSCnt->getDataSeries() );
aResult.insert( aResult.end(), aSeriesSeq.begin(), aSeriesSeq.end() );
}
}
@@ -1201,7 +1201,7 @@ Sequence< Reference< XChartType > >
for( Reference< XCoordinateSystem > const & coords : aCooSysSeq )
{
Reference< XChartTypeContainer > xCTCnt( coords, uno::UNO_QUERY_THROW );
- Sequence< Reference< XChartType > > aChartTypeSeq( xCTCnt->getChartTypes());
+ const Sequence< Reference< XChartType > > aChartTypeSeq( xCTCnt->getChartTypes());
aResult.insert( aResult.end(), aChartTypeSeq.begin(), aChartTypeSeq.end() );
}
}
diff --git a/chart2/source/tools/InternalDataProvider.cxx b/chart2/source/tools/InternalDataProvider.cxx
index ccbf8697c638..0323043dbff2 100644
--- a/chart2/source/tools/InternalDataProvider.cxx
+++ b/chart2/source/tools/InternalDataProvider.cxx
@@ -920,7 +920,7 @@ Sequence< uno::Any > SAL_CALL InternalDataProvider::getDataByRangeRepresentation
else
{
// Maybe this 'else' part and the functions is not necessary anymore.
- Sequence< OUString > aLabels = m_bDataInColumns ? getRowDescriptions() : getColumnDescriptions();
+ const Sequence< OUString > aLabels = m_bDataInColumns ? getRowDescriptions() : getColumnDescriptions();
aResult.realloc( aLabels.getLength() );
transform( aLabels.begin(), aLabels.end(),
aResult.getArray(), CommonFunctors::makeAny< OUString >() );
@@ -931,11 +931,9 @@ Sequence< uno::Any > SAL_CALL InternalDataProvider::getDataByRangeRepresentation
sal_Int32 nIndex = aRange.toInt32();
if( nIndex >= 0 )
{
- Sequence< double > aData;
- if( m_bDataInColumns )
- aData = m_aInternalData.getColumnValues(nIndex);
- else
- aData = m_aInternalData.getRowValues(nIndex);
+ const Sequence< double > aData = m_bDataInColumns
+ ? m_aInternalData.getColumnValues(nIndex)
+ : m_aInternalData.getRowValues(nIndex);
if( aData.hasElements() )
{
aResult.realloc( aData.getLength());
diff --git a/chart2/source/tools/UncachedDataSequence.cxx b/chart2/source/tools/UncachedDataSequence.cxx
index d10fa7da3f37..1c7394d22400 100644
--- a/chart2/source/tools/UncachedDataSequence.cxx
+++ b/chart2/source/tools/UncachedDataSequence.cxx
@@ -170,7 +170,7 @@ Sequence< double > SAL_CALL UncachedDataSequence::getNumericalData()
MutexGuard aGuard( GetMutex() );
if( m_xDataProvider.is())
{
- Sequence< uno::Any > aValues( m_xDataProvider->getDataByRangeRepresentation( m_aSourceRepresentation ));
+ const Sequence< uno::Any > aValues( m_xDataProvider->getDataByRangeRepresentation( m_aSourceRepresentation ));
aResult.realloc( aValues.getLength());
std::transform( aValues.begin(), aValues.end(),
aResult.getArray(), CommonFunctors::AnyToDouble());
@@ -185,7 +185,7 @@ Sequence< OUString > SAL_CALL UncachedDataSequence::getTextualData()
MutexGuard aGuard( GetMutex() );
if( m_xDataProvider.is())
{
- Sequence< uno::Any > aValues( m_xDataProvider->getDataByRangeRepresentation( m_aSourceRepresentation ));
+ const Sequence< uno::Any > aValues( m_xDataProvider->getDataByRangeRepresentation( m_aSourceRepresentation ));
aResult.realloc( aValues.getLength());
std::transform( aValues.begin(), aValues.end(),
aResult.getArray(), CommonFunctors::AnyToString());