summaryrefslogtreecommitdiff
path: root/sw/source/core
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 /sw/source/core
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 'sw/source/core')
-rw-r--r--sw/source/core/access/accselectionhelper.cxx2
-rw-r--r--sw/source/core/edit/edlingu.cxx10
-rw-r--r--sw/source/core/unocore/unochart.cxx9
-rw-r--r--sw/source/core/unocore/unocoll.cxx2
-rw-r--r--sw/source/core/unocore/unoframe.cxx4
-rw-r--r--sw/source/core/unocore/unoparagraph.cxx2
-rw-r--r--sw/source/core/unocore/unoport.cxx2
7 files changed, 16 insertions, 15 deletions
diff --git a/sw/source/core/access/accselectionhelper.cxx b/sw/source/core/access/accselectionhelper.cxx
index 9bcec4e19cd5..08a4886044c1 100644
--- a/sw/source/core/access/accselectionhelper.cxx
+++ b/sw/source/core/access/accselectionhelper.cxx
@@ -124,7 +124,7 @@ static bool lcl_getSelectedState(const SwAccessibleChild& aChild,
Reference<XAccessibleStateSet> pRStateSet = pRContext->getAccessibleStateSet();
if( pRStateSet.is() )
{
- Sequence<short> aStates = pRStateSet->getStates();
+ const Sequence<short> aStates = pRStateSet->getStates();
if (std::find(aStates.begin(), aStates.end(), AccessibleStateType::SELECTED) != aStates.end())
return true;
}
diff --git a/sw/source/core/edit/edlingu.cxx b/sw/source/core/edit/edlingu.cxx
index 76d9e8899934..a393afdb225c 100644
--- a/sw/source/core/edit/edlingu.cxx
+++ b/sw/source/core/edit/edlingu.cxx
@@ -1020,14 +1020,14 @@ bool SwEditShell::GetGrammarCorrection(
// get suggestions to use for the specific error position
rSuggestions.realloc( 0 );
// return suggestions for first error that includes the given error position
- auto pError = std::find_if(rResult.aErrors.begin(), rResult.aErrors.end(),
+ auto pError = std::find_if(std::cbegin(rResult.aErrors), std::cend(rResult.aErrors),
[rErrorPosInText, nLen](const linguistic2::SingleProofreadingError &rError) {
return rError.nErrorStart <= rErrorPosInText
&& rErrorPosInText + nLen <= rError.nErrorStart + rError.nErrorLength; });
- if (pError != rResult.aErrors.end())
+ if (pError != std::cend(rResult.aErrors))
{
rSuggestions = pError->aSuggestions;
- rErrorIndexInResult = static_cast<sal_Int32>(std::distance(rResult.aErrors.begin(), pError));
+ rErrorIndexInResult = static_cast<sal_Int32>(std::distance(std::cbegin(rResult.aErrors), pError));
}
}
@@ -1544,9 +1544,9 @@ void SwSpellIter::CreatePortion(uno::Reference< XSpellAlternatives > const & xAl
aPortion.aGrammarError = pGrammarResult->aErrors[0];
aPortion.sText = pGrammarResult->aText.copy( aPortion.aGrammarError.nErrorStart, aPortion.aGrammarError.nErrorLength );
aPortion.xGrammarChecker = pGrammarResult->xProofreader;
- auto pProperty = std::find_if(pGrammarResult->aProperties.begin(), pGrammarResult->aProperties.end(),
+ auto pProperty = std::find_if(std::cbegin(pGrammarResult->aProperties), std::cend(pGrammarResult->aProperties),
[](const beans::PropertyValue& rProperty) { return rProperty.Name == "DialogTitle"; });
- if (pProperty != pGrammarResult->aProperties.end())
+ if (pProperty != std::cend(pGrammarResult->aProperties))
pProperty->Value >>= aPortion.sDialogTitle;
}
}
diff --git a/sw/source/core/unocore/unochart.cxx b/sw/source/core/unocore/unochart.cxx
index b40a42a49a41..1e04b4d8848d 100644
--- a/sw/source/core/unocore/unochart.cxx
+++ b/sw/source/core/unocore/unochart.cxx
@@ -1233,15 +1233,16 @@ uno::Sequence< beans::PropertyValue > SAL_CALL SwChartDataProvider::detectArgume
// build value for 'SequenceMapping'
uno::Sequence< sal_Int32 > aSortedMapping( aSequenceMapping );
- std::sort( aSortedMapping.begin(), aSortedMapping.end() );
+ auto [begin, end] = toNonConstRange(aSortedMapping);
+ std::sort(begin, end);
bool bNeedSequenceMapping = false;
for (sal_Int32 i = 0; i < aSequenceMapping.getLength(); ++i)
{
- auto it = std::find( aSortedMapping.begin(), aSortedMapping.end(),
+ auto it = std::find( std::cbegin(aSortedMapping), std::cend(aSortedMapping),
aSequenceMapping[i] );
- aSequenceMapping[i] = std::distance(aSortedMapping.begin(), it);
+ aSequenceMapping[i] = std::distance(std::cbegin(aSortedMapping), it);
- if (i != aSequenceMapping[i])
+ if (i != std::as_const(aSequenceMapping)[i])
bNeedSequenceMapping = true;
}
diff --git a/sw/source/core/unocore/unocoll.cxx b/sw/source/core/unocore/unocoll.cxx
index b54f1779e3f8..10cff85a4a34 100644
--- a/sw/source/core/unocore/unocoll.cxx
+++ b/sw/source/core/unocore/unocoll.cxx
@@ -112,7 +112,7 @@ public:
sProjectName = mpDocShell->GetBasicManager()->GetName();
}
uno::Reference< container::XNameAccess > xLib( xLibContainer->getByName( sProjectName ), uno::UNO_QUERY_THROW );
- uno::Sequence< OUString > sModuleNames = xLib->getElementNames();
+ const uno::Sequence< OUString > sModuleNames = xLib->getElementNames();
uno::Reference< script::vba::XVBAModuleInfo > xVBAModuleInfo( xLib, uno::UNO_QUERY );
auto pModuleName = std::find_if(sModuleNames.begin(), sModuleNames.end(), [&xVBAModuleInfo](const OUString& rName) {
diff --git a/sw/source/core/unocore/unoframe.cxx b/sw/source/core/unocore/unoframe.cxx
index 85b38f9053e5..dd540870d8c3 100644
--- a/sw/source/core/unocore/unoframe.cxx
+++ b/sw/source/core/unocore/unoframe.cxx
@@ -2385,7 +2385,7 @@ uno::Sequence< beans::PropertyState > SwXFrame::getPropertyStates(
{
SolarMutexGuard aGuard;
uno::Sequence< beans::PropertyState > aStates(aPropertyNames.getLength());
- beans::PropertyState* pStates = aStates.getArray();
+ auto [pStates, end] = toNonConstRange(aStates);
SwFrameFormat* pFormat = GetFrameFormat();
if(pFormat)
{
@@ -2458,7 +2458,7 @@ uno::Sequence< beans::PropertyState > SwXFrame::getPropertyStates(
}
else if(IsDescriptor())
{
- std::fill(aStates.begin(), aStates.end(), beans::PropertyState_DIRECT_VALUE);
+ std::fill(pStates, end, beans::PropertyState_DIRECT_VALUE);
}
else
throw uno::RuntimeException();
diff --git a/sw/source/core/unocore/unoparagraph.cxx b/sw/source/core/unocore/unoparagraph.cxx
index 9f74a4f7daa1..326f8cc2a6ea 100644
--- a/sw/source/core/unocore/unoparagraph.cxx
+++ b/sw/source/core/unocore/unoparagraph.cxx
@@ -705,7 +705,7 @@ SwXParagraph::getPropertyValuesTolerant(
{
SolarMutexGuard aGuard;
- uno::Sequence< beans::GetDirectPropertyTolerantResult > aTmpRes(
+ const uno::Sequence< beans::GetDirectPropertyTolerantResult > aTmpRes(
m_pImpl->GetPropertyValuesTolerant_Impl( rPropertyNames, false ) );
// copy temporary result to final result type
diff --git a/sw/source/core/unocore/unoport.cxx b/sw/source/core/unocore/unoport.cxx
index fea1e27749ef..a76af4e240fc 100644
--- a/sw/source/core/unocore/unoport.cxx
+++ b/sw/source/core/unocore/unoport.cxx
@@ -548,7 +548,7 @@ uno::Sequence< beans::GetPropertyTolerantResult > SAL_CALL SwXTextPortion::getPr
{
SolarMutexGuard aGuard;
- uno::Sequence< beans::GetDirectPropertyTolerantResult > aTmpRes(
+ const uno::Sequence< beans::GetDirectPropertyTolerantResult > aTmpRes(
GetPropertyValuesTolerant_Impl( rPropertyNames, false ) );
// copy temporary result to final result type