summaryrefslogtreecommitdiff
path: root/oox
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 /oox
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 'oox')
-rw-r--r--oox/source/crypto/AgileEngine.cxx2
-rw-r--r--oox/source/export/chartexport.cxx4
-rw-r--r--oox/source/helper/zipstorage.cxx3
-rw-r--r--oox/source/ole/olestorage.cxx3
4 files changed, 5 insertions, 7 deletions
diff --git a/oox/source/crypto/AgileEngine.cxx b/oox/source/crypto/AgileEngine.cxx
index 63712d01b3ef..0fd655ced63c 100644
--- a/oox/source/crypto/AgileEngine.cxx
+++ b/oox/source/crypto/AgileEngine.cxx
@@ -504,7 +504,7 @@ bool AgileEngine::readEncryptionInfo(uno::Reference<io::XInputStream> & rxInputS
uno::Sequence<sal_Int8> aReadReservedBytes(sizeof(sal_uInt32));
rxInputStream->readBytes(aReadReservedBytes, aReadReservedBytes.getLength());
- if (!std::equal(aReadReservedBytes.begin(), aReadReservedBytes.end(), aExpectedReservedBytes.begin()))
+ if (!std::equal(std::cbegin(aReadReservedBytes), std::cend(aReadReservedBytes), aExpectedReservedBytes.begin()))
return false;
mInfo.spinCount = 0;
diff --git a/oox/source/export/chartexport.cxx b/oox/source/export/chartexport.cxx
index 452b5f5ef851..32736e67fad0 100644
--- a/oox/source/export/chartexport.cxx
+++ b/oox/source/export/chartexport.cxx
@@ -406,7 +406,7 @@ static void lcl_fillCategoriesIntoStringVector(
if( xTextualDataSequence.is())
{
rOutCategories.clear();
- Sequence< OUString > aTextData( xTextualDataSequence->getTextualData());
+ const Sequence< OUString > aTextData( xTextualDataSequence->getTextualData());
rOutCategories.insert( rOutCategories.end(), aTextData.begin(), aTextData.end() );
}
else
@@ -425,7 +425,7 @@ static ::std::vector< double > lcl_getAllValuesFromSequence( const Reference< ch
Reference< chart2::data::XNumericalDataSequence > xNumSeq( xSeq, uno::UNO_QUERY );
if( xNumSeq.is())
{
- Sequence< double > aValues( xNumSeq->getNumericalData());
+ const Sequence< double > aValues( xNumSeq->getNumericalData());
aResult.insert( aResult.end(), aValues.begin(), aValues.end() );
}
else if( xSeq.is())
diff --git a/oox/source/helper/zipstorage.cxx b/oox/source/helper/zipstorage.cxx
index 987ab3b809d1..d11d145bb764 100644
--- a/oox/source/helper/zipstorage.cxx
+++ b/oox/source/helper/zipstorage.cxx
@@ -110,10 +110,9 @@ Reference< XStorage > ZipStorage::implGetXStorage() const
void ZipStorage::implGetElementNames( ::std::vector< OUString >& orElementNames ) const
{
- Sequence< OUString > aNames;
if( mxStorage.is() ) try
{
- aNames = mxStorage->getElementNames();
+ const Sequence<OUString> aNames = mxStorage->getElementNames();
if( aNames.hasElements() )
orElementNames.insert( orElementNames.end(), aNames.begin(), aNames.end() );
}
diff --git a/oox/source/ole/olestorage.cxx b/oox/source/ole/olestorage.cxx
index 82aa1cd79fe8..32673fa699af 100644
--- a/oox/source/ole/olestorage.cxx
+++ b/oox/source/ole/olestorage.cxx
@@ -279,10 +279,9 @@ Reference< XStorage > OleStorage::implGetXStorage() const
void OleStorage::implGetElementNames( ::std::vector< OUString >& orElementNames ) const
{
- Sequence< OUString > aNames;
if( mxStorage.is() ) try
{
- aNames = mxStorage->getElementNames();
+ const Sequence<OUString> aNames = mxStorage->getElementNames();
if( aNames.hasElements() )
orElementNames.insert( orElementNames.end(), aNames.begin(), aNames.end() );
}