summaryrefslogtreecommitdiff
path: root/xmloff
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 /xmloff
parent17d3cacfb9675268e709cfc95771ad4ce8bde75a (diff)
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 'xmloff')
-rw-r--r--xmloff/source/chart/SchXMLChartContext.cxx2
-rw-r--r--xmloff/source/chart/SchXMLExport.cxx23
-rw-r--r--xmloff/source/chart/SchXMLImport.cxx2
-rw-r--r--xmloff/source/chart/SchXMLSeries2Context.cxx2
-rw-r--r--xmloff/source/chart/SchXMLSeriesHelper.cxx4
-rw-r--r--xmloff/source/draw/SignatureLineContext.cxx2
-rw-r--r--xmloff/source/forms/elementimport.cxx2
-rw-r--r--xmloff/source/forms/formcellbinding.cxx7
-rw-r--r--xmloff/source/script/XMLEventExport.cxx2
-rw-r--r--xmloff/source/style/tabsthdl.cxx2
-rw-r--r--xmloff/source/style/xmlnumfe.cxx2
-rw-r--r--xmloff/source/table/XMLTableExport.cxx2
-rw-r--r--xmloff/source/text/XMLSectionExport.cxx4
-rw-r--r--xmloff/source/text/XMLTextNumRuleInfo.cxx4
-rw-r--r--xmloff/source/text/txtimp.cxx4
-rw-r--r--xmloff/source/text/txtprhdl.cxx4
16 files changed, 35 insertions, 33 deletions
diff --git a/xmloff/source/chart/SchXMLChartContext.cxx b/xmloff/source/chart/SchXMLChartContext.cxx
index 54a2879d4f2d..d8a91ff49659 100644
--- a/xmloff/source/chart/SchXMLChartContext.cxx
+++ b/xmloff/source/chart/SchXMLChartContext.cxx
@@ -958,7 +958,7 @@ void SchXMLChartContext::MergeSeriesForStockChart()
for( const auto& rCooSys : aCooSysSeq )
{
uno::Reference< chart2::XChartTypeContainer > xCTCnt( rCooSys, uno::UNO_QUERY_THROW );
- uno::Sequence< uno::Reference< chart2::XChartType > > aChartTypes( xCTCnt->getChartTypes());
+ const uno::Sequence< uno::Reference< chart2::XChartType > > aChartTypes( xCTCnt->getChartTypes());
auto pChartType = std::find_if(aChartTypes.begin(), aChartTypes.end(),
[](const auto& rChartType) { return rChartType->getChartType() == "com.sun.star.chart2.CandleStickChartType"; });
if (pChartType != aChartTypes.end())
diff --git a/xmloff/source/chart/SchXMLExport.cxx b/xmloff/source/chart/SchXMLExport.cxx
index b230a924472c..372cd9cdaf9a 100644
--- a/xmloff/source/chart/SchXMLExport.cxx
+++ b/xmloff/source/chart/SchXMLExport.cxx
@@ -458,7 +458,7 @@ Sequence< Reference< chart2::data::XLabeledDataSequence > > lcl_getAllSeriesSequ
Reference< chart2::data::XDataSource > xDataSource( rSeries, uno::UNO_QUERY );
if( !xDataSource.is() )
continue;
- uno::Sequence< Reference< chart2::data::XLabeledDataSequence > > aDataSequences( xDataSource->getDataSequences() );
+ const uno::Sequence< Reference< chart2::data::XLabeledDataSequence > > aDataSequences( xDataSource->getDataSequences() );
aContainer.insert( aContainer.end(), aDataSequences.begin(), aDataSequences.end() );
}
}
@@ -495,7 +495,7 @@ Reference< chart2::data::XDataSource > lcl_pressUsedDataIntoRectangularFormat( c
aLabeledSeqVector.push_back( xCategories );
rOutSourceHasCategoryLabels = xCategories.is();
- Sequence< Reference< chart2::data::XLabeledDataSequence > > aSeriesSeqVector(
+ const Sequence< Reference< chart2::data::XLabeledDataSequence > > aSeriesSeqVector(
lcl_getAllSeriesSequences( xChartDoc ) );
//the first x-values is always the next sequence //todo ... other x-values get lost for old format
@@ -690,24 +690,25 @@ uno::Sequence< OUString > lcl_DataSequenceToStringSequence(
if( aRole.match("values-x") )
{
//lcl_clearIfNoValuesButTextIsContained - replace by indices if the values are not appropriate
- bool bHasValue = std::any_of(aValuesSequence.begin(), aValuesSequence.end(),
+ bool bHasValue = std::any_of(std::cbegin(aValuesSequence), std::cend(aValuesSequence),
[](double fValue) { return !std::isnan( fValue ); });
if(!bHasValue)
{
//no double value is contained
//is there any text?
- uno::Sequence< OUString > aStrings( lcl_DataSequenceToStringSequence( xSeq ) );
+ const uno::Sequence< OUString > aStrings( lcl_DataSequenceToStringSequence( xSeq ) );
bool bHasText = std::any_of(aStrings.begin(), aStrings.end(),
[](const OUString& rString) { return !rString.isEmpty(); });
if( bHasText )
{
- std::iota(aValuesSequence.begin(), aValuesSequence.end(), 1);
+ auto [begin, end] = toNonConstRange(aValuesSequence);
+ std::iota(begin, end, 1);
}
}
}
}
- aResult.insert( aResult.end(), aValuesSequence.begin(), aValuesSequence.end() );
+ aResult.insert( aResult.end(), std::cbegin(aValuesSequence), std::cend(aValuesSequence) );
return aResult;
}
@@ -855,7 +856,7 @@ lcl_TableData lcl_getDataForLocalTable(
//categories
rCategories.clear();
- rCategories.insert( rCategories.begin(), aSimpleCategories.begin(), aSimpleCategories.end() );
+ rCategories.insert( rCategories.begin(), std::cbegin(aSimpleCategories), std::cend(aSimpleCategories) );
if( !rCategoriesRange.isEmpty() )
{
OUString aRange(rCategoriesRange);
@@ -2553,7 +2554,7 @@ namespace
Reference< chart2::data::XNumericalDataSequence > xNumericalDataSequence( xDataSequence, uno::UNO_QUERY );
if( xNumericalDataSequence.is() )
{
- Sequence< double > aDoubles( xNumericalDataSequence->getNumericalData() );
+ const Sequence< double > aDoubles( xNumericalDataSequence->getNumericalData() );
if (std::any_of(aDoubles.begin(), aDoubles.end(), [](double fDouble) { return !std::isnan( fDouble ); }))
return false;//have double value
}
@@ -2561,7 +2562,7 @@ namespace
{
aData = xDataSequence->getData();
double fDouble = 0.0;
- bool bHaveDouble = std::any_of(aData.begin(), aData.end(),
+ bool bHaveDouble = std::any_of(std::cbegin(aData), std::cend(aData),
[&fDouble](const uno::Any& rData) { return (rData >>= fDouble) && !std::isnan( fDouble ); });
if (bHaveDouble)
return false;//have double value
@@ -2571,7 +2572,7 @@ namespace
Reference< chart2::data::XTextualDataSequence > xTextualDataSequence( xDataSequence, uno::UNO_QUERY );
if( xTextualDataSequence.is() )
{
- uno::Sequence< OUString > aStrings( xTextualDataSequence->getTextualData() );
+ const uno::Sequence< OUString > aStrings( xTextualDataSequence->getTextualData() );
if (std::any_of(aStrings.begin(), aStrings.end(), [](const OUString& rString) { return !rString.isEmpty(); }))
return true;//have text
}
@@ -2580,7 +2581,7 @@ namespace
if( !aData.hasElements() )
aData = xDataSequence->getData();
OUString aString;
- bool bHaveText = std::any_of(aData.begin(), aData.end(),
+ bool bHaveText = std::any_of(std::cbegin(aData), std::cend(aData),
[&aString](const uno::Any& rData) { return (rData >>= aString) && !aString.isEmpty(); });
if (bHaveText)
return true;//have text
diff --git a/xmloff/source/chart/SchXMLImport.cxx b/xmloff/source/chart/SchXMLImport.cxx
index d0523a39dc02..e1a19dc1b71a 100644
--- a/xmloff/source/chart/SchXMLImport.cxx
+++ b/xmloff/source/chart/SchXMLImport.cxx
@@ -143,7 +143,7 @@ void SchXMLImportHelper::DeleteDataSeries(
for( const auto& rChartType : aChartTypes )
{
Reference< chart2::XDataSeriesContainer > xSeriesCnt( rChartType, uno::UNO_QUERY_THROW );
- Sequence< Reference< chart2::XDataSeries > > aSeriesSeq( xSeriesCnt->getDataSeries());
+ const Sequence< Reference< chart2::XDataSeries > > aSeriesSeq( xSeriesCnt->getDataSeries());
if (std::find(aSeriesSeq.begin(), aSeriesSeq.end(), xSeries) != aSeriesSeq.end())
{
diff --git a/xmloff/source/chart/SchXMLSeries2Context.cxx b/xmloff/source/chart/SchXMLSeries2Context.cxx
index 1d91af151317..6739bab69197 100644
--- a/xmloff/source/chart/SchXMLSeries2Context.cxx
+++ b/xmloff/source/chart/SchXMLSeries2Context.cxx
@@ -230,7 +230,7 @@ Reference< chart2::data::XLabeledDataSequence2 > lcl_createAndAddSequenceToSerie
xLabeledSeq->setValues( xSeq );
// add new sequence to data series / push to front to have the correct sequence order if charttype is changed afterwards
- Sequence< Reference< chart2::data::XLabeledDataSequence > > aOldSeq( xSeriesSource->getDataSequences());
+ const Sequence< Reference< chart2::data::XLabeledDataSequence > > aOldSeq( xSeriesSource->getDataSequences());
sal_Int32 nOldCount = aOldSeq.getLength();
Sequence< Reference< chart2::data::XLabeledDataSequence > > aNewSeq( nOldCount + 1 );
aNewSeq[0].set(xLabeledSeq, uno::UNO_QUERY_THROW);
diff --git a/xmloff/source/chart/SchXMLSeriesHelper.cxx b/xmloff/source/chart/SchXMLSeriesHelper.cxx
index 9bccc3f83950..31a197596607 100644
--- a/xmloff/source/chart/SchXMLSeriesHelper.cxx
+++ b/xmloff/source/chart/SchXMLSeriesHelper.cxx
@@ -52,7 +52,7 @@ using ::com::sun::star::uno::Sequence;
for( const auto& rChartType : aChartTypeSeq )
{
Reference< chart2::XDataSeriesContainer > xDSCnt( rChartType, uno::UNO_QUERY_THROW );
- Sequence< Reference< chart2::XDataSeries > > aSeriesSeq( xDSCnt->getDataSeries() );
+ const Sequence< Reference< chart2::XDataSeries > > aSeriesSeq( xDSCnt->getDataSeries() );
aResult.insert( aResult.end(), aSeriesSeq.begin(), aSeriesSeq.end() );
}
}
@@ -118,7 +118,7 @@ uno::Reference< chart2::XChartType > lcl_getChartTypeOfSeries(
if( !xDataSeriesContainer.is() )
continue;
- uno::Sequence< uno::Reference< chart2::XDataSeries > > aSeriesList( xDataSeriesContainer->getDataSeries() );
+ const uno::Sequence< uno::Reference< chart2::XDataSeries > > aSeriesList( xDataSeriesContainer->getDataSeries() );
if (std::find(aSeriesList.begin(), aSeriesList.end(), xSeries) != aSeriesList.end())
return xChartType;
}
diff --git a/xmloff/source/draw/SignatureLineContext.cxx b/xmloff/source/draw/SignatureLineContext.cxx
index d85acded8226..0217156e35fb 100644
--- a/xmloff/source/draw/SignatureLineContext.cxx
+++ b/xmloff/source/draw/SignatureLineContext.cxx
@@ -92,7 +92,7 @@ SignatureLineContext::SignatureLineContext(SvXMLImport& rImport, sal_Int32 /*nEl
security::DocumentDigitalSignatures::createWithVersion(
comphelper::getProcessComponentContext(), aODFVersion));
- Sequence<DocumentSignatureInformation> xSignatureInfo
+ const Sequence<DocumentSignatureInformation> xSignatureInfo
= xSignatures->verifyDocumentContentSignatures(xStorage, Reference<XInputStream>());
// Try to find matching signature line image - if none exists that is fine,
diff --git a/xmloff/source/forms/elementimport.cxx b/xmloff/source/forms/elementimport.cxx
index 8c94cd738c65..e4f4f6aed753 100644
--- a/xmloff/source/forms/elementimport.cxx
+++ b/xmloff/source/forms/elementimport.cxx
@@ -371,7 +371,7 @@ namespace xmloff
"OElementImport::implApplyGenericProperties: conversion to sequences other than 'sequence< short >' not implemented, yet!" );
- std::transform(aXMLValueList.begin(), aXMLValueList.end(), aPropertyValueList.begin(),
+ std::transform(std::cbegin(aXMLValueList), std::cend(aXMLValueList), aPropertyValueList.begin(),
[](const Any& rXMLValue) -> sal_Int16 {
// only value sequences of numeric types implemented so far.
double nVal( 0 );
diff --git a/xmloff/source/forms/formcellbinding.cxx b/xmloff/source/forms/formcellbinding.cxx
index 21b09fc6b1cd..31c8e19c4d53 100644
--- a/xmloff/source/forms/formcellbinding.cxx
+++ b/xmloff/source/forms/formcellbinding.cxx
@@ -243,11 +243,12 @@ bool FormCellBindingHelper::isSpreadsheetDocumentWhichSupplies( const Reference<
Reference< XMultiServiceFactory > xDocumentFactory( _rxDocument, UNO_QUERY );
OSL_ENSURE( xDocumentFactory.is(), "FormCellBindingHelper::isSpreadsheetDocumentWhichSupplies: spreadsheet document, but no factory?" );
- Sequence< OUString > aAvailableServices;
if ( xDocumentFactory.is() )
- aAvailableServices = xDocumentFactory->getAvailableServiceNames( );
+ {
+ const Sequence<OUString> aAvailableServices = xDocumentFactory->getAvailableServiceNames( );
- bYesItIs = std::any_of( aAvailableServices.begin(), aAvailableServices.end(), StringCompare( _rService ) );
+ bYesItIs = std::any_of( aAvailableServices.begin(), aAvailableServices.end(), StringCompare( _rService ) );
+ }
}
}
catch( const Exception& )
diff --git a/xmloff/source/script/XMLEventExport.cxx b/xmloff/source/script/XMLEventExport.cxx
index 877edf198ab9..285bd487c35b 100644
--- a/xmloff/source/script/XMLEventExport.cxx
+++ b/xmloff/source/script/XMLEventExport.cxx
@@ -180,7 +180,7 @@ void XMLEventExport::ExportSingleEvent(
/// export a single event
void XMLEventExport::ExportEvent(
- Sequence<PropertyValue>& rEventValues,
+ const Sequence<PropertyValue>& rEventValues,
const XMLEventName& rXmlEventName,
bool bUseWhitespace,
bool& rExported )
diff --git a/xmloff/source/style/tabsthdl.cxx b/xmloff/source/style/tabsthdl.cxx
index fc1edd5aa2b5..2e497f3eabaf 100644
--- a/xmloff/source/style/tabsthdl.cxx
+++ b/xmloff/source/style/tabsthdl.cxx
@@ -39,7 +39,7 @@ bool XMLTabStopPropHdl::equals( const uno::Any& r1, const uno::Any& r2 ) const
uno::Sequence< style::TabStop> aSeq2;
if( r2 >>= aSeq2 )
{
- return std::equal(aSeq1.begin(), aSeq1.end(), aSeq2.begin(), aSeq2.end(),
+ return std::equal(std::cbegin(aSeq1), std::cend(aSeq1), std::cbegin(aSeq2), std::cend(aSeq2),
[](const style::TabStop& a, const style::TabStop& b) {
return a.Position == b.Position
&& a.Alignment == b.Alignment
diff --git a/xmloff/source/style/xmlnumfe.cxx b/xmloff/source/style/xmlnumfe.cxx
index 1f0639febaa5..14400f04785a 100644
--- a/xmloff/source/style/xmlnumfe.cxx
+++ b/xmloff/source/style/xmlnumfe.cxx
@@ -930,7 +930,7 @@ static OUString lcl_GetDefaultCalendar( SvNumberFormatter const * pFormatter, La
{
lang::Locale aLocale( LanguageTag::convertToLocale( nLang ) );
- uno::Sequence<OUString> aCals = pCalendar->getAllCalendars( aLocale );
+ const uno::Sequence<OUString> aCals = pCalendar->getAllCalendars( aLocale );
auto pCal = std::find_if(aCals.begin(), aCals.end(),
[](const OUString& rCal) { return rCal != "gregorian"; });
if (pCal != aCals.end())
diff --git a/xmloff/source/table/XMLTableExport.cxx b/xmloff/source/table/XMLTableExport.cxx
index 81488ec62543..cac07330f7bf 100644
--- a/xmloff/source/table/XMLTableExport.cxx
+++ b/xmloff/source/table/XMLTableExport.cxx
@@ -167,7 +167,7 @@ XMLTableExport::XMLTableExport(SvXMLExport& rExp, const rtl::Reference< SvXMLExp
Reference< XMultiServiceFactory > xFac( rExp.GetModel(), UNO_QUERY );
if( xFac.is() ) try
{
- Sequence< OUString > sSNS( xFac->getAvailableServiceNames() );
+ const Sequence< OUString > sSNS( xFac->getAvailableServiceNames() );
const OUString* pSNS = std::find_if(sSNS.begin(), sSNS.end(),
[](const OUString& rSNS) {
return rSNS == "com.sun.star.drawing.TableShape"
diff --git a/xmloff/source/text/XMLSectionExport.cxx b/xmloff/source/text/XMLSectionExport.cxx
index ca9ab26a9d42..d97e30c0c6fa 100644
--- a/xmloff/source/text/XMLSectionExport.cxx
+++ b/xmloff/source/text/XMLSectionExport.cxx
@@ -1798,9 +1798,9 @@ void XMLSectionExport::ExportMasterDocHeadingDummies()
OUString sStyle;
Sequence<PropertyValue> aProperties;
xChapterNumbering->getByIndex( nLevel ) >>= aProperties;
- auto pProp = std::find_if(aProperties.begin(), aProperties.end(),
+ auto pProp = std::find_if(std::cbegin(aProperties), std::cend(aProperties),
[](const PropertyValue& rProp) { return rProp.Name == "HeadingStyleName"; });
- if (pProp != aProperties.end())
+ if (pProp != std::cend(aProperties))
pProp->Value >>= sStyle;
if( !sStyle.isEmpty() )
diff --git a/xmloff/source/text/XMLTextNumRuleInfo.cxx b/xmloff/source/text/XMLTextNumRuleInfo.cxx
index 07586ba53de6..c6889abbbc9e 100644
--- a/xmloff/source/text/XMLTextNumRuleInfo.cxx
+++ b/xmloff/source/text/XMLTextNumRuleInfo.cxx
@@ -175,9 +175,9 @@ void XMLTextNumRuleInfo::Set(
Sequence<PropertyValue> aProps;
mxNumRules->getByIndex( mnListLevel ) >>= aProps;
- auto pProp = std::find_if(aProps.begin(), aProps.end(),
+ auto pProp = std::find_if(std::cbegin(aProps), std::cend(aProps),
[](const PropertyValue& rProp) { return rProp.Name == "StartWith"; });
- if (pProp != aProps.end())
+ if (pProp != std::cend(aProps))
{
pProp->Value >>= mnListLevelStartValue;
}
diff --git a/xmloff/source/text/txtimp.cxx b/xmloff/source/text/txtimp.cxx
index 813e66ed8083..8d4a96058f40 100644
--- a/xmloff/source/text/txtimp.cxx
+++ b/xmloff/source/text/txtimp.cxx
@@ -1479,9 +1479,9 @@ void XMLTextImportHelper::FindOutlineStyleName( OUString& rStyleName,
Sequence<PropertyValue> aProperties;
m_xImpl->m_xChapterNumbering->getByIndex( nOutlineLevel )
>>= aProperties;
- auto pProp = std::find_if(aProperties.begin(), aProperties.end(),
+ auto pProp = std::find_if(std::cbegin(aProperties), std::cend(aProperties),
[](const PropertyValue& rProp) { return rProp.Name == "HeadingStyleName"; });
- if (pProp != aProperties.end())
+ if (pProp != std::cend(aProperties))
{
OUString aOutlineStyle;
pProp->Value >>= aOutlineStyle;
diff --git a/xmloff/source/text/txtprhdl.cxx b/xmloff/source/text/txtprhdl.cxx
index ef4766c696b2..2068c9b934a6 100644
--- a/xmloff/source/text/txtprhdl.cxx
+++ b/xmloff/source/text/txtprhdl.cxx
@@ -663,8 +663,8 @@ bool XMLTextColumnsPropertyHandler::equals(
xColumns1->getReferenceValue() != xColumns2->getReferenceValue() )
return false;
- Sequence < TextColumn > aColumns1 = xColumns1->getColumns();
- Sequence < TextColumn > aColumns2 = xColumns2->getColumns();
+ const Sequence < TextColumn > aColumns1 = xColumns1->getColumns();
+ const Sequence < TextColumn > aColumns2 = xColumns2->getColumns();
return std::equal(aColumns1.begin(), aColumns1.end(), aColumns2.begin(), aColumns2.end(),
[](const TextColumn& a, const TextColumn& b) {