diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2021-10-13 09:02:48 +0300 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2021-10-14 06:00:49 +0200 |
commit | 8a017d25a62e878fdd32f189f0663b05d2ffb9cf (patch) | |
tree | c91ee53b5d9276ae30df785b52579a1b77a057df /sw | |
parent | 17d3cacfb9675268e709cfc95771ad4ce8bde75a (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')
29 files changed, 87 insertions, 78 deletions
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx index b364d1314278..be18f7b47d86 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx @@ -940,7 +940,7 @@ DECLARE_OOXMLEXPORT_TEST(testTdf89702, "tdf89702.docx") auto xLevels = getProperty< uno::Reference<container::XIndexAccess> >(xParagraph, "NumberingRules"); uno::Sequence<beans::PropertyValue> aLevel; xLevels->getByIndex(1) >>= aLevel; // 2nd level - OUString aCharStyleName = std::find_if(aLevel.begin(), aLevel.end(), [](const beans::PropertyValue& rValue) { return rValue.Name == "CharStyleName"; })->Value.get<OUString>(); + OUString aCharStyleName = std::find_if(std::cbegin(aLevel), std::cend(aLevel), [](const beans::PropertyValue& rValue) { return rValue.Name == "CharStyleName"; })->Value.get<OUString>(); // Make sure that the font name is Arial, this was Verdana. uno::Reference<beans::XPropertySet> xStyle(getStyles("CharacterStyles")->getByName(aCharStyleName), uno::UNO_QUERY); @@ -1052,7 +1052,7 @@ DECLARE_OOXMLEXPORT_TEST(testTdf92124, "tdf92124.docx") auto xLevels = getProperty< uno::Reference<container::XIndexAccess> >(xParagraph, "NumberingRules"); uno::Sequence<beans::PropertyValue> aLevel; xLevels->getByIndex(0) >>= aLevel; // 1st level - OUString aSuffix = std::find_if(aLevel.begin(), aLevel.end(), [](const beans::PropertyValue& rValue) { return rValue.Name == "Suffix"; })->Value.get<OUString>(); + OUString aSuffix = std::find_if(std::cbegin(aLevel), std::cend(aLevel), [](const beans::PropertyValue& rValue) { return rValue.Name == "Suffix"; })->Value.get<OUString>(); // Make sure it's empty as the source document contains <w:suff w:val="nothing"/>. CPPUNIT_ASSERT(aSuffix.isEmpty()); } @@ -1165,7 +1165,7 @@ DECLARE_OOXMLEXPORT_TEST(testTdf95213, "tdf95213.docx") auto xLevels = getProperty< uno::Reference<container::XIndexAccess> >(xParagraph, "NumberingRules"); uno::Sequence<beans::PropertyValue> aLevel; xLevels->getByIndex(1) >>= aLevel; // 2nd level - OUString aName = std::find_if(aLevel.begin(), aLevel.end(), [](const beans::PropertyValue& rValue) { return rValue.Name == "CharStyleName"; })->Value.get<OUString>(); + OUString aName = std::find_if(std::cbegin(aLevel), std::cend(aLevel), [](const beans::PropertyValue& rValue) { return rValue.Name == "CharStyleName"; })->Value.get<OUString>(); uno::Reference<beans::XPropertySet> xStyle(getStyles("CharacterStyles")->getByName(aName), uno::UNO_QUERY); // This was awt::FontWeight::BOLD. diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport12.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport12.cxx index d485c094ce15..102c50e95d30 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport12.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport12.cxx @@ -993,7 +993,7 @@ DECLARE_OOXMLEXPORT_EXPORTONLY_TEST(testTdf94628, "tdf94628.docx") uno::Sequence<beans::PropertyValue> aProps; xLevels->getByIndex(0) >>= aProps; // 1st level - OUString sBulletChar = std::find_if(aProps.begin(), aProps.end(), + OUString sBulletChar = std::find_if(std::cbegin(aProps), std::cend(aProps), [](const beans::PropertyValue& rValue) { return rValue.Name == "BulletChar"; }) diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx index 3e7b38f8df75..1eeb60366093 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx @@ -174,7 +174,7 @@ DECLARE_OOXMLEXPORT_TEST(testTdf95848_2, "tdf95848_2.docx") auto xLevels = getProperty<uno::Reference<container::XIndexAccess>>(xPara, "NumberingRules"); uno::Sequence<beans::PropertyValue> aLevel; xLevels->getByIndex(0) >>= aLevel; // top level - sal_Int32 nIndent = std::find_if(aLevel.begin(), aLevel.end(), [](const beans::PropertyValue& rValue) { return rValue.Name == "FirstLineIndent"; })->Value.get<sal_Int32>(); + sal_Int32 nIndent = std::find_if(std::cbegin(aLevel), std::cend(aLevel), [](const beans::PropertyValue& rValue) { return rValue.Name == "FirstLineIndent"; })->Value.get<sal_Int32>(); CPPUNIT_ASSERT_EQUAL(sal_Int32(-635), nIndent); } { @@ -192,7 +192,7 @@ DECLARE_OOXMLEXPORT_TEST(testTdf95848_2, "tdf95848_2.docx") auto xLevels = getProperty<uno::Reference<container::XIndexAccess>>(xPara, "NumberingRules"); uno::Sequence<beans::PropertyValue> aLevel; xLevels->getByIndex(0) >>= aLevel; // top level - sal_Int32 nIndent = std::find_if(aLevel.begin(), aLevel.end(), [](const beans::PropertyValue& rValue) { return rValue.Name == "FirstLineIndent"; })->Value.get<sal_Int32>(); + sal_Int32 nIndent = std::find_if(std::cbegin(aLevel), std::cend(aLevel), [](const beans::PropertyValue& rValue) { return rValue.Name == "FirstLineIndent"; })->Value.get<sal_Int32>(); CPPUNIT_ASSERT_EQUAL(sal_Int32(9366), nIndent); } { diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport16.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport16.cxx index cf5ad5e41fc8..608a4a7bc9f0 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport16.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport16.cxx @@ -482,7 +482,7 @@ DECLARE_OOXMLEXPORT_EXPORTONLY_TEST(testTdf134619_numberingProps, "tdf134619_num auto xLevels = getProperty< uno::Reference<container::XIndexAccess> >(xParagraph, "NumberingRules"); uno::Sequence<beans::PropertyValue> aLevel; xLevels->getByIndex(0) >>= aLevel; // 1st level - OUString aCharStyleName = std::find_if(aLevel.begin(), aLevel.end(), [](const beans::PropertyValue& rValue) { return rValue.Name == "CharStyleName"; })->Value.get<OUString>(); + OUString aCharStyleName = std::find_if(std::cbegin(aLevel), std::cend(aLevel), [](const beans::PropertyValue& rValue) { return rValue.Name == "CharStyleName"; })->Value.get<OUString>(); // Make sure that the blue bullet's font size is 72 points, not 12 points. uno::Reference<beans::XPropertySet> xStyle(getStyles("CharacterStyles")->getByName(aCharStyleName), uno::UNO_QUERY); diff --git a/sw/qa/unit/swmodeltestbase.cxx b/sw/qa/unit/swmodeltestbase.cxx index 1cadbdd7aa44..8336f6bad8ca 100644 --- a/sw/qa/unit/swmodeltestbase.cxx +++ b/sw/qa/unit/swmodeltestbase.cxx @@ -357,9 +357,9 @@ sal_Int16 SwModelTestBase::getNumberingTypeOfParagraph(int nPara) uno::Sequence<beans::PropertyValue> aPropertyValue; xLevels->getByIndex(nNumberingLevel) >>= aPropertyValue; auto pProp = std::find_if( - aPropertyValue.begin(), aPropertyValue.end(), + std::cbegin(aPropertyValue), std::cend(aPropertyValue), [](const beans::PropertyValue& rProp) { return rProp.Name == "NumberingType"; }); - if (pProp != aPropertyValue.end()) + if (pProp != std::cend(aPropertyValue)) nNumberingType = pProp->Value.get<sal_Int16>(); } } 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 diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx index 868196d654e0..f94baf8806a7 100644 --- a/sw/source/filter/ww8/docxattributeoutput.cxx +++ b/sw/source/filter/ww8/docxattributeoutput.cxx @@ -651,9 +651,9 @@ bool DocxAttributeOutput::TextBoxIsFramePr(const SwFrameFormat& rFrameFormat) { uno::Sequence< beans::PropertyValue > propList; xPropertySet->getPropertyValue("FrameInteropGrabBag") >>= propList; - auto pProp = std::find_if(propList.begin(), propList.end(), + auto pProp = std::find_if(std::cbegin(propList), std::cend(propList), [](const beans::PropertyValue& rProp) { return rProp.Name == "ParaFrameProperties"; }); - if (pProp != propList.end()) + if (pProp != std::cend(propList)) aFrameProperties = pProp->Value; } bool bFrameProperties = false; @@ -2820,10 +2820,10 @@ void DocxAttributeOutput::GetSdtEndBefore(const SdrObject* pSdrObj) xPropSet->getPropertyValue("InteropGrabBag") >>= aGrabBag; } - auto pProp = std::find_if(aGrabBag.begin(), aGrabBag.end(), + auto pProp = std::find_if(std::cbegin(aGrabBag), std::cend(aGrabBag), [this](const beans::PropertyValue& rProp) { return "SdtEndBefore" == rProp.Name && m_bStartedCharSdt && !m_bEndCharSdt; }); - if (pProp != aGrabBag.end()) + if (pProp != std::cend(aGrabBag)) pProp->Value >>= m_bEndCharSdt; } @@ -4701,9 +4701,9 @@ void DocxAttributeOutput::LatentStyles() uno::Sequence<beans::PropertyValue> aInteropGrabBag; xPropertySet->getPropertyValue("InteropGrabBag") >>= aInteropGrabBag; uno::Sequence<beans::PropertyValue> aLatentStyles; - auto pProp = std::find_if(aInteropGrabBag.begin(), aInteropGrabBag.end(), + auto pProp = std::find_if(std::cbegin(aInteropGrabBag), std::cend(aInteropGrabBag), [](const beans::PropertyValue& rProp) { return rProp.Name == "latentStyles"; }); - if (pProp != aInteropGrabBag.end()) + if (pProp != std::cend(aInteropGrabBag)) pProp->Value >>= aLatentStyles; if (!aLatentStyles.hasElements()) return; @@ -5736,9 +5736,9 @@ void DocxAttributeOutput::WriteOLE( SwOLENode& rNode, const Size& rSize, const S uno::Reference< beans::XPropertySet > xPropSet( m_rExport.m_rDoc.GetDocShell()->GetBaseModel(), uno::UNO_QUERY_THROW ); uno::Sequence< beans::PropertyValue > aGrabBag, aObjectsInteropList,aObjectInteropAttributes; xPropSet->getPropertyValue( UNO_NAME_MISC_OBJ_INTEROPGRABBAG ) >>= aGrabBag; - auto pProp = std::find_if(aGrabBag.begin(), aGrabBag.end(), + auto pProp = std::find_if(std::cbegin(aGrabBag), std::cend(aGrabBag), [](const beans::PropertyValue& rProp) { return rProp.Name == "EmbeddedObjects"; }); - if (pProp != aGrabBag.end()) + if (pProp != std::cend(aGrabBag)) pProp->Value >>= aObjectsInteropList; SwOLEObj& aObject = rNode.GetOLEObj(); @@ -5757,9 +5757,9 @@ void DocxAttributeOutput::WriteOLE( SwOLENode& rNode, const Size& rSize, const S default: SAL_WARN("sw.ww8", "DocxAttributeOutput::WriteOLE: invalid aspect value"); } - auto pObjectsInterop = std::find_if(aObjectsInteropList.begin(), aObjectsInteropList.end(), + auto pObjectsInterop = std::find_if(std::cbegin(aObjectsInteropList), std::cend(aObjectsInteropList), [&sObjectName](const beans::PropertyValue& rProp) { return rProp.Name == sObjectName; }); - if (pObjectsInterop != aObjectsInteropList.end()) + if (pObjectsInterop != std::cend(aObjectsInteropList)) pObjectsInterop->Value >>= aObjectInteropAttributes; for( const auto& rObjectInteropAttribute : std::as_const(aObjectInteropAttributes) ) diff --git a/sw/source/filter/ww8/docxexport.cxx b/sw/source/filter/ww8/docxexport.cxx index e4531e421796..b610adf30f7d 100644 --- a/sw/source/filter/ww8/docxexport.cxx +++ b/sw/source/filter/ww8/docxexport.cxx @@ -1369,9 +1369,9 @@ void DocxExport::WriteTheme() uno::Reference<xml::dom::XDocument> themeDom; uno::Sequence< beans::PropertyValue > propList; xPropSet->getPropertyValue( aName ) >>= propList; - auto pProp = std::find_if(propList.begin(), propList.end(), + auto pProp = std::find_if(std::cbegin(propList), std::cend(propList), [](const beans::PropertyValue& rProp) { return rProp.Name == "OOXTheme"; }); - if (pProp != propList.end()) + if (pProp != std::cend(propList)) pProp->Value >>= themeDom; // no theme dom to write @@ -1472,14 +1472,14 @@ void DocxExport::WriteCustomXml() uno::Sequence<uno::Reference<xml::dom::XDocument> > customXmlDomPropslist; uno::Sequence< beans::PropertyValue > propList; xPropSet->getPropertyValue( aName ) >>= propList; - auto pProp = std::find_if(propList.begin(), propList.end(), + auto pProp = std::find_if(std::cbegin(propList), std::cend(propList), [](const beans::PropertyValue& rProp) { return rProp.Name == "OOXCustomXml"; }); - if (pProp != propList.end()) + if (pProp != std::cend(propList)) pProp->Value >>= customXmlDomlist; - pProp = std::find_if(propList.begin(), propList.end(), + pProp = std::find_if(std::cbegin(propList), std::cend(propList), [](const beans::PropertyValue& rProp) { return rProp.Name == "OOXCustomXmlProps"; }); - if (pProp != propList.end()) + if (pProp != std::cend(propList)) pProp->Value >>= customXmlDomPropslist; for (sal_Int32 j = 0; j < customXmlDomlist.getLength(); j++) @@ -1589,9 +1589,9 @@ void DocxExport::WriteEmbeddings() uno::Sequence< beans::PropertyValue > embeddingsList; uno::Sequence< beans::PropertyValue > propList; xPropSet->getPropertyValue( aName ) >>= propList; - auto pProp = std::find_if(propList.begin(), propList.end(), + auto pProp = std::find_if(std::cbegin(propList), std::cend(propList), [](const beans::PropertyValue& rProp) { return rProp.Name == "OOXEmbeddings"; }); - if (pProp != propList.end()) + if (pProp != std::cend(propList)) pProp->Value >>= embeddingsList; for (const auto& rEmbedding : std::as_const(embeddingsList)) { diff --git a/sw/source/filter/ww8/docxsdrexport.cxx b/sw/source/filter/ww8/docxsdrexport.cxx index 1e1ac6bd66c3..ae5b7ca94fb1 100644 --- a/sw/source/filter/ww8/docxsdrexport.cxx +++ b/sw/source/filter/ww8/docxsdrexport.cxx @@ -83,7 +83,7 @@ OUString lclGetAnchorIdFromGrabBag(const SdrObject* pObj) aGrabBagName = "FrameInteropGrabBag"; else aGrabBagName = "InteropGrabBag"; - uno::Sequence<beans::PropertyValue> propList = lclGetProperty(xShape, aGrabBagName); + const uno::Sequence<beans::PropertyValue> propList = lclGetProperty(xShape, aGrabBagName); auto pProp = std::find_if(propList.begin(), propList.end(), [](const beans::PropertyValue& rProp) { return rProp.Name == "AnchorId"; }); @@ -1385,7 +1385,7 @@ void DocxSdrExport::writeVMLDrawing(const SdrObject* sdrObj, const SwFrameFormat static bool lcl_isLockedCanvas(const uno::Reference<drawing::XShape>& xShape) { - uno::Sequence<beans::PropertyValue> propList = lclGetProperty(xShape, "InteropGrabBag"); + const uno::Sequence<beans::PropertyValue> propList = lclGetProperty(xShape, "InteropGrabBag"); /* * Export as Locked Canvas only if the property * is in the PropertySet @@ -1835,11 +1835,11 @@ void DocxSdrExport::writeDMLTextFrame(ww8::Frame const* pParentFrame, int nAncho { uno::Sequence<beans::PropertyValue> propList; xPropertySet->getPropertyValue("FrameInteropGrabBag") >>= propList; - auto pProp = std::find_if(propList.begin(), propList.end(), + auto pProp = std::find_if(std::cbegin(propList), std::cend(propList), [](const beans::PropertyValue& rProp) { return rProp.Name == "mso-rotation-angle"; }); - if (pProp != propList.end()) + if (pProp != std::cend(propList)) aRotation = pProp->Value; } sal_Int32 nTmp; @@ -1867,11 +1867,11 @@ void DocxSdrExport::writeDMLTextFrame(ww8::Frame const* pParentFrame, int nAncho { uno::Sequence<beans::PropertyValue> propList; xPropertySet->getPropertyValue("FrameInteropGrabBag") >>= propList; - auto pProp = std::find_if(propList.begin(), propList.end(), + auto pProp = std::find_if(std::cbegin(propList), std::cend(propList), [](const beans::PropertyValue& rProp) { return rProp.Name == "mso-orig-shape-type"; }); - if (pProp != propList.end()) + if (pProp != std::cend(propList)) pProp->Value >>= shapeType; } //Empty shapeType will lead to corruption so to avoid that shapeType is set to default i.e. "rect" diff --git a/sw/source/filter/ww8/docxtablestyleexport.cxx b/sw/source/filter/ww8/docxtablestyleexport.cxx index 4ad89587eda1..570c43130778 100644 --- a/sw/source/filter/ww8/docxtablestyleexport.cxx +++ b/sw/source/filter/ww8/docxtablestyleexport.cxx @@ -130,9 +130,9 @@ void DocxTableStyleExport::TableStyles(sal_Int32 nCountStylesToWrite) xPropertySet->getPropertyValue("InteropGrabBag") >>= aInteropGrabBag; uno::Sequence<beans::PropertyValue> aTableStyles; auto pProp = std::find_if( - aInteropGrabBag.begin(), aInteropGrabBag.end(), + std::cbegin(aInteropGrabBag), std::cend(aInteropGrabBag), [](const beans::PropertyValue& rProp) { return rProp.Name == "tableStyles"; }); - if (pProp != aInteropGrabBag.end()) + if (pProp != std::cend(aInteropGrabBag)) pProp->Value >>= aTableStyles; if (!aTableStyles.hasElements()) return; diff --git a/sw/source/filter/ww8/wrtww8.cxx b/sw/source/filter/ww8/wrtww8.cxx index 0ba034aa6564..6e6ed96981f7 100644 --- a/sw/source/filter/ww8/wrtww8.cxx +++ b/sw/source/filter/ww8/wrtww8.cxx @@ -4253,7 +4253,8 @@ void WW8Export::WriteFormData( const ::sw::mark::IFieldmark& rFieldmark ) { uno::Sequence< OUString > vListEntries; pListEntries->second >>= vListEntries; - copy(vListEntries.begin(), vListEntries.end(), back_inserter(aListItems)); + aListItems.reserve(vListEntries.getLength()); + copy(std::cbegin(vListEntries), std::cend(vListEntries), back_inserter(aListItems)); } } diff --git a/sw/source/ui/dbui/mmaddressblockpage.cxx b/sw/source/ui/dbui/mmaddressblockpage.cxx index efe108b2d5dc..2a902d85a2b0 100644 --- a/sw/source/ui/dbui/mmaddressblockpage.cxx +++ b/sw/source/ui/dbui/mmaddressblockpage.cxx @@ -361,10 +361,11 @@ const uno::Sequence< OUString >& SwSelectAddressBlockDialog::GetAddressBlocks const sal_Int32 nSelect = static_cast<sal_Int32>(m_xPreview->GetSelectedAddress()); if(nSelect) { - uno::Sequence< OUString >aTemp = m_aAddressBlocks; - aTemp[0] = m_aAddressBlocks[nSelect]; - std::copy(m_aAddressBlocks.begin(), std::next(m_aAddressBlocks.begin(), nSelect), std::next(aTemp.begin())); - std::copy(std::next(m_aAddressBlocks.begin(), nSelect + 1), m_aAddressBlocks.end(), std::next(aTemp.begin(), nSelect + 1)); + uno::Sequence< OUString >aTemp(m_aAddressBlocks.getLength()); + auto it = aTemp.begin(); + *it = std::as_const(m_aAddressBlocks)[nSelect]; + it = std::copy_n(std::cbegin(m_aAddressBlocks), nSelect - 1, std::next(it)); + std::copy(std::next(std::cbegin(m_aAddressBlocks), nSelect + 1), std::cend(m_aAddressBlocks), it); m_aAddressBlocks = aTemp; } return m_aAddressBlocks; diff --git a/sw/source/ui/envelp/mailmrge.cxx b/sw/source/ui/envelp/mailmrge.cxx index 27621d74e0ef..63a05e81bd7b 100644 --- a/sw/source/ui/envelp/mailmrge.cxx +++ b/sw/source/ui/envelp/mailmrge.cxx @@ -326,9 +326,9 @@ SwMailMergeDlg::SwMailMergeDlg(weld::Window* pParent, SwWrtShell& rShell, uno::Sequence< beans::PropertyValue > aFilterProperties; aProps >>= aFilterProperties; OUString sUIName2; - auto pProp = std::find_if(aFilterProperties.begin(), aFilterProperties.end(), + auto pProp = std::find_if(std::cbegin(aFilterProperties), std::cend(aFilterProperties), [](const beans::PropertyValue& rProp) { return rProp.Name == "UIName"; }); - if (pProp != aFilterProperties.end()) + if (pProp != std::cend(aFilterProperties)) pProp->Value >>= sUIName2; if( !sUIName2.isEmpty() ) { if( sFilter == "writer8" ) diff --git a/sw/source/ui/vba/vbadocumentproperties.cxx b/sw/source/ui/vba/vbadocumentproperties.cxx index 78f553ed0365..846c8c999304 100644 --- a/sw/source/ui/vba/vbadocumentproperties.cxx +++ b/sw/source/ui/vba/vbadocumentproperties.cxx @@ -338,9 +338,10 @@ public: uno::Sequence< beans::NamedValue > stats( m_xDocProps->getDocumentStatistics()); - auto pStat = std::find_if(stats.begin(), stats.end(), + auto [begin, end] = toNonConstRange(stats); + auto pStat = std::find_if(begin, end, [&rPropName](const beans::NamedValue& rStat) { return rPropName == rStat.Name; }); - if (pStat != stats.end()) + if (pStat != end) { pStat->Value = aValue; m_xDocProps->setDocumentStatistics(stats); @@ -838,7 +839,7 @@ public: virtual uno::Sequence< OUString > SAL_CALL getElementNames( ) override { - uno::Sequence< beans::Property > aProps = mxUserDefinedProp->getPropertySetInfo()->getProperties(); + const uno::Sequence< beans::Property > aProps = mxUserDefinedProp->getPropertySetInfo()->getProperties(); uno::Sequence< OUString > aNames( aProps.getLength() ); std::transform(aProps.begin(), aProps.end(), aNames.begin(), [](const beans::Property& rProp) -> OUString { return rProp.Name; }); diff --git a/sw/source/ui/vba/vbafilterpropsfromformat.hxx b/sw/source/ui/vba/vbafilterpropsfromformat.hxx index 01fd93be5555..dbf07b155955 100644 --- a/sw/source/ui/vba/vbafilterpropsfromformat.hxx +++ b/sw/source/ui/vba/vbafilterpropsfromformat.hxx @@ -31,11 +31,11 @@ namespace inline bool setFilterPropsFromFormat(sal_Int32 nFormat, css::uno::Sequence<css::beans::PropertyValue>& rProps) { - auto pProp - = std::find_if(rProps.begin(), rProps.end(), [](const css::beans::PropertyValue& rProp) { - return rProp.Name == "FilterName"; - }); - if (pProp != rProps.end()) + auto[begin, end] = toNonConstRange(rProps); + auto pProp = std::find_if(begin, end, [](const css::beans::PropertyValue& rProp) { + return rProp.Name == "FilterName"; + }); + if (pProp != end) { switch (nFormat) { diff --git a/sw/source/ui/vba/vbastyles.cxx b/sw/source/ui/vba/vbastyles.cxx index a65f2750f95a..f14758eb8810 100644 --- a/sw/source/ui/vba/vbastyles.cxx +++ b/sw/source/ui/vba/vbastyles.cxx @@ -222,7 +222,7 @@ public: } else { - uno::Sequence< OUString > sElementNames = mxParaStyles->getElementNames(); + const uno::Sequence< OUString > sElementNames = mxParaStyles->getElementNames(); auto pStyleName = std::find_if(sElementNames.begin(), sElementNames.end(), [&aName](const OUString& rStyleName) { return rStyleName.equalsIgnoreAsciiCase( aName ); }); if (pStyleName != sElementNames.end()) diff --git a/sw/source/ui/vba/vbatabstops.cxx b/sw/source/ui/vba/vbatabstops.cxx index c7e6655b5b8d..0046814305d9 100644 --- a/sw/source/ui/vba/vbatabstops.cxx +++ b/sw/source/ui/vba/vbatabstops.cxx @@ -202,10 +202,11 @@ uno::Reference< word::XTabStop > SAL_CALL SwVbaTabStops::Add( float Position, co aTab.FillChar = cLeader; uno::Sequence< style::TabStop > aOldTabs = lcl_getTabStops( mxParaProps ); + auto [begin, end] = toNonConstRange(aOldTabs); - style::TabStop* pOldTab = std::find_if(aOldTabs.begin(), aOldTabs.end(), + style::TabStop* pOldTab = std::find_if(begin, end, [nPosition](const style::TabStop& rTab) { return rTab.Position == nPosition; }); - bool bOverWriter = pOldTab != aOldTabs.end(); + bool bOverWriter = pOldTab != end; if( bOverWriter ) { *pOldTab = aTab; @@ -216,8 +217,9 @@ uno::Reference< word::XTabStop > SAL_CALL SwVbaTabStops::Add( float Position, co sal_Int32 nTabs = aOldTabs.getLength(); uno::Sequence< style::TabStop > aNewTabs( nTabs + 1 ); - aNewTabs[0] = aTab; - std::copy(aOldTabs.begin(), aOldTabs.end(), std::next(aNewTabs.begin())); + auto it = aNewTabs.begin(); + *it = aTab; + std::copy(begin, end, std::next(it)); lcl_setTabStops( mxParaProps, aNewTabs ); } diff --git a/sw/source/uibase/dbui/dbmgr.cxx b/sw/source/uibase/dbui/dbmgr.cxx index 532a142ca809..81acb18b3e15 100644 --- a/sw/source/uibase/dbui/dbmgr.cxx +++ b/sw/source/uibase/dbui/dbmgr.cxx @@ -2044,7 +2044,7 @@ bool SwDBManager::GetColumnCnt(const OUString& rSourceName, const OUString& rTab if(pFound->aSelection.hasElements()) { //the destination has to be an element of the selection - bool bFound = std::any_of(pFound->aSelection.begin(), pFound->aSelection.end(), + bool bFound = std::any_of(std::cbegin(pFound->aSelection), std::cend(pFound->aSelection), [nAbsRecordId](const uno::Any& rSelection) { sal_Int32 nSelection = 0; rSelection >>= nSelection; diff --git a/sw/source/uibase/dbui/dbtree.cxx b/sw/source/uibase/dbui/dbtree.cxx index 8b3692f8da31..0af160098e08 100644 --- a/sw/source/uibase/dbui/dbtree.cxx +++ b/sw/source/uibase/dbui/dbtree.cxx @@ -150,8 +150,9 @@ void SwDBTreeList::InitTreeList() auto const sort = comphelper::string::NaturalStringSorter( comphelper::getProcessComponentContext(), Application::GetSettings().GetUILanguageTag().getLocale()); + auto [begin, end] = toNonConstRange(aDBNames); std::sort( - aDBNames.begin(), aDBNames.end(), + begin, end, [&sort](OUString const & x, OUString const & y) { return sort.compare(x, y) < 0; }); diff --git a/sw/source/uibase/dbui/mmconfigitem.cxx b/sw/source/uibase/dbui/mmconfigitem.cxx index 744373edefc3..4dd6d7e0a5c4 100644 --- a/sw/source/uibase/dbui/mmconfigitem.cxx +++ b/sw/source/uibase/dbui/mmconfigitem.cxx @@ -333,12 +333,13 @@ SwMailMergeConfigItem_Impl::SwMailMergeConfigItem_Impl() : if(m_aSavedDocuments.hasElements()) { uno::Sequence< OUString > aTempDocuments(m_aSavedDocuments.getLength()); - OUString* pTempDocuments = std::copy_if(m_aSavedDocuments.begin(), m_aSavedDocuments.end(), aTempDocuments.begin(), + auto begin = aTempDocuments.begin(); + OUString* pTempDocuments = std::copy_if(std::cbegin(m_aSavedDocuments), std::cend(m_aSavedDocuments), begin, [](const OUString& rDoc) { return SWUnoHelper::UCB_IsFile( rDoc ); }); - sal_Int32 nIndex = static_cast<sal_Int32>(std::distance(aTempDocuments.begin(), pTempDocuments)); + sal_Int32 nIndex = static_cast<sal_Int32>(std::distance(begin, pTempDocuments)); if(nIndex < m_aSavedDocuments.getLength()) { - m_aSavedDocuments = aTempDocuments; + m_aSavedDocuments.swap(aTempDocuments); m_aSavedDocuments.realloc(nIndex); } } diff --git a/sw/source/uibase/fldui/fldmgr.cxx b/sw/source/uibase/fldui/fldmgr.cxx index 9996117b9488..634bedb8c1c0 100644 --- a/sw/source/uibase/fldui/fldmgr.cxx +++ b/sw/source/uibase/fldui/fldmgr.cxx @@ -701,7 +701,7 @@ sal_uInt16 SwFieldMgr::GetFormatCount(SwFieldTypesEnum nTypeId, bool bHtmlMode) GetNumberingInfo(); if(m_xNumberingInfo.is()) { - Sequence<sal_Int16> aTypes = m_xNumberingInfo->getSupportedNumberingTypes(); + const Sequence<sal_Int16> aTypes = m_xNumberingInfo->getSupportedNumberingTypes(); // #i28073# it's not necessarily a sorted sequence //skip all values below or equal to CHARS_LOWER_LETTER_N nCount += std::count_if(aTypes.begin(), aTypes.end(), diff --git a/sw/source/uibase/misc/numberingtypelistbox.cxx b/sw/source/uibase/misc/numberingtypelistbox.cxx index 5136bed3d4c1..5f4c45bb8dfc 100644 --- a/sw/source/uibase/misc/numberingtypelistbox.cxx +++ b/sw/source/uibase/misc/numberingtypelistbox.cxx @@ -88,7 +88,8 @@ void SwNumberingTypeListBox::Reload(SwInsertNumTypes nTypeFlags) if (nValue > style::NumberingType::CHARS_LOWER_LETTER_N) { // Insert only if offered by i18n framework per configuration. - bInsert = std::find(aTypes.begin(), aTypes.end(), nValue) != aTypes.end(); + bInsert = std::find(std::cbegin(aTypes), std::cend(aTypes), nValue) + != std::cend(aTypes); } } if (bInsert) diff --git a/sw/source/uibase/uno/unotxdoc.cxx b/sw/source/uibase/uno/unotxdoc.cxx index 39bea8b26d89..2f2189456f3e 100644 --- a/sw/source/uibase/uno/unotxdoc.cxx +++ b/sw/source/uibase/uno/unotxdoc.cxx @@ -4101,7 +4101,7 @@ Sequence< OUString > SwXLinkNameAccessWrapper::getElementNames() } else { - Sequence< OUString > aOrg = m_xRealAccess->getElementNames(); + const Sequence< OUString > aOrg = m_xRealAccess->getElementNames(); aRet.realloc(aOrg.getLength()); std::transform(aOrg.begin(), aOrg.end(), aRet.begin(), [this](const OUString& rOrg) -> OUString { return rOrg + m_sLinkSuffix; }); |