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 /svx | |
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 'svx')
-rw-r--r-- | svx/source/accessibility/AccessibleShape.cxx | 4 | ||||
-rw-r--r-- | svx/source/fmcomp/fmgridcl.cxx | 8 | ||||
-rw-r--r-- | svx/source/fmcomp/fmgridif.cxx | 2 | ||||
-rw-r--r-- | svx/source/form/fmshimp.cxx | 2 | ||||
-rw-r--r-- | svx/source/form/fmsrcimp.cxx | 2 | ||||
-rw-r--r-- | svx/source/form/fmtextcontrolshell.cxx | 2 | ||||
-rw-r--r-- | svx/source/form/formcontrolfactory.cxx | 2 | ||||
-rw-r--r-- | svx/source/form/formcontroller.cxx | 18 | ||||
-rw-r--r-- | svx/source/items/customshapeitem.cxx | 6 | ||||
-rw-r--r-- | svx/source/table/accessiblecell.cxx | 2 |
10 files changed, 23 insertions, 25 deletions
diff --git a/svx/source/accessibility/AccessibleShape.cxx b/svx/source/accessibility/AccessibleShape.cxx index 5fbf4f4ebdec..0ed06acab198 100644 --- a/svx/source/accessibility/AccessibleShape.cxx +++ b/svx/source/accessibility/AccessibleShape.cxx @@ -418,7 +418,7 @@ uno::Reference<XAccessibleStateSet> SAL_CALL xTempAccContext->getAccessibleStateSet(); if (rState.is()) { - css::uno::Sequence<short> aStates = rState->getStates(); + const css::uno::Sequence<short> aStates = rState->getStates(); if (std::find(aStates.begin(), aStates.end(), AccessibleStateType::EDITABLE) != aStates.end()) { pStateSet->AddState (AccessibleStateType::EDITABLE); @@ -787,7 +787,7 @@ sal_Bool SAL_CALL AccessibleShape::isAccessibleChildSelected( sal_Int32 nChildIn if( !pRState.is() ) return false; - uno::Sequence<short> aStates = pRState->getStates(); + const uno::Sequence<short> aStates = pRState->getStates(); return std::find(aStates.begin(), aStates.end(), AccessibleStateType::SELECTED) != aStates.end(); } } diff --git a/svx/source/fmcomp/fmgridcl.cxx b/svx/source/fmcomp/fmgridcl.cxx index 43fa3c399725..d7f5ee2e0a64 100644 --- a/svx/source/fmcomp/fmgridcl.cxx +++ b/svx/source/fmcomp/fmgridcl.cxx @@ -1296,7 +1296,7 @@ void FmGridControl::DeleteSelectedRows() SetUpdateMode( true ); // how many rows are deleted? - sal_Int32 nDeletedRows = static_cast<sal_Int32>(std::count_if(aDeletedRows.begin(), aDeletedRows.end(), + sal_Int32 nDeletedRows = static_cast<sal_Int32>(std::count_if(std::cbegin(aDeletedRows), std::cend(aDeletedRows), [](const sal_Int32 nRow) { return nRow != 0; })); // have rows been deleted? @@ -1344,10 +1344,10 @@ void FmGridControl::DeleteSelectedRows() // not all the rows where deleted, so move to the first row which remained in the resultset else { - auto pRow = std::find(aDeletedRows.begin(), aDeletedRows.end(), 0); - if (pRow != aDeletedRows.end()) + auto pRow = std::find(std::cbegin(aDeletedRows), std::cend(aDeletedRows), 0); + if (pRow != std::cend(aDeletedRows)) { - auto i = static_cast<sal_Int32>(std::distance(aDeletedRows.begin(), pRow)); + auto i = static_cast<sal_Int32>(std::distance(std::cbegin(aDeletedRows), pRow)); getDataSource()->moveToBookmark(aBookmarks[i]); } } diff --git a/svx/source/fmcomp/fmgridif.cxx b/svx/source/fmcomp/fmgridif.cxx index 3134c0ce67a9..ab52cb90864a 100644 --- a/svx/source/fmcomp/fmgridif.cxx +++ b/svx/source/fmcomp/fmgridif.cxx @@ -2535,7 +2535,7 @@ void FmXGridPeer::statusChanged(const css::frame::FeatureStateEvent& Event) DBG_ASSERT(m_pStateCache, "FmXGridPeer::statusChanged : invalid call !"); DBG_ASSERT(m_pDispatchers, "FmXGridPeer::statusChanged : invalid call !"); - Sequence< css::util::URL>& aUrls = getSupportedURLs(); + const Sequence< css::util::URL>& aUrls = getSupportedURLs(); const std::vector<DbGridControlNavigationBarState>& aSlots = getSupportedGridSlots(); diff --git a/svx/source/form/fmshimp.cxx b/svx/source/form/fmshimp.cxx index 3b5a070e4dee..3571e2e71f05 100644 --- a/svx/source/form/fmshimp.cxx +++ b/svx/source/form/fmshimp.cxx @@ -1184,7 +1184,7 @@ bool FmXFormShell::executeControlConversionSlot_Lock(const Reference<XFormCompon // find the control for the model Reference<XControlContainer> xControlContainer(getControlContainerForView_Lock()); - Sequence< Reference< XControl> > aControls( xControlContainer->getControls() ); + const Sequence< Reference< XControl> > aControls( xControlContainer->getControls() ); Reference< XControl> xControl; auto pControl = std::find_if(aControls.begin(), aControls.end(), diff --git a/svx/source/form/fmsrcimp.cxx b/svx/source/form/fmsrcimp.cxx index eb292abd8ce4..ed6899c6fa9c 100644 --- a/svx/source/form/fmsrcimp.cxx +++ b/svx/source/form/fmsrcimp.cxx @@ -674,7 +674,7 @@ void FmSearchEngine::Init(const OUString& sVisibleFields) Reference< css::sdbcx::XColumnsSupplier > xSupplyCols(IFACECAST(m_xSearchCursor), UNO_QUERY); DBG_ASSERT(xSupplyCols.is(), "FmSearchEngine::Init : invalid cursor (no columns supplier) !"); Reference< css::container::XNameAccess > xAllFieldNames = xSupplyCols->getColumns(); - Sequence< OUString > seqFieldNames = xAllFieldNames->getElementNames(); + const Sequence< OUString > seqFieldNames = xAllFieldNames->getElementNames(); OUString sCurrentField; sal_Int32 nIndex = 0; diff --git a/svx/source/form/fmtextcontrolshell.cxx b/svx/source/form/fmtextcontrolshell.cxx index 67d43d734b7f..eb13c53a4848 100644 --- a/svx/source/form/fmtextcontrolshell.cxx +++ b/svx/source/form/fmtextcontrolshell.cxx @@ -1068,7 +1068,7 @@ namespace svx try { - Sequence< Reference< css::awt::XControl > > aControls( _rxController->getControls() ); + const Sequence< Reference< css::awt::XControl > > aControls( _rxController->getControls() ); m_aControlObservers.resize( 0 ); m_aControlObservers.reserve( aControls.getLength() ); diff --git a/svx/source/form/formcontrolfactory.cxx b/svx/source/form/formcontrolfactory.cxx index 678e00052de3..513c0cc0d751 100644 --- a/svx/source/form/formcontrolfactory.cxx +++ b/svx/source/form/formcontrolfactory.cxx @@ -514,7 +514,7 @@ namespace svxform // let's see if the data source which the form belongs to (if any) // has a setting for the preferred line end format bool bDosLineEnds = false; - Sequence< PropertyValue > aInfo = lcl_getDataSourceIndirectProperties( _rxModel, m_xContext ); + const Sequence< PropertyValue > aInfo = lcl_getDataSourceIndirectProperties( _rxModel, m_xContext ); const PropertyValue* pInfo = std::find_if(aInfo.begin(), aInfo.end(), [](const PropertyValue& rInfo) { return rInfo.Name == "PreferDosLikeLineEnds"; }); if (pInfo != aInfo.end()) diff --git a/svx/source/form/formcontroller.cxx b/svx/source/form/formcontroller.cxx index ebaa1cc86939..e84ac41a33d0 100644 --- a/svx/source/form/formcontroller.cxx +++ b/svx/source/form/formcontroller.cxx @@ -1275,7 +1275,7 @@ bool FormController::replaceControl( const Reference< XControl >& _rxExistentCon if ( xContainer.is() ) { // look up the ID of _rxExistentControl - Sequence< sal_Int32 > aIdentifiers( xContainer->getIdentifiers() ); + const Sequence< sal_Int32 > aIdentifiers( xContainer->getIdentifiers() ); const sal_Int32* pIdentifiers = std::find_if(aIdentifiers.begin(), aIdentifiers.end(), [&xContainer, &_rxExistentControl](const sal_Int32 nId) { Reference< XControl > xCheck( xContainer->getByIdentifier( nId ), UNO_QUERY ); @@ -2320,19 +2320,17 @@ Reference< XControl > FormController::findControl(Sequence< Reference< XControl OSL_ENSURE( !impl_isDisposed_nofail(), "FormController: already disposed!" ); DBG_ASSERT( xCtrlModel.is(), "findControl - which ?!" ); - Reference< XControl >* pControls = std::find_if(_rControls.begin(), _rControls.end(), + const Reference< XControl >* pControls = std::find_if(std::cbegin(_rControls), std::cend(_rControls), [&xCtrlModel](const Reference< XControl >& rControl) { return rControl.is() && rControl->getModel().get() == xCtrlModel.get(); }); - if (pControls != _rControls.end()) + if (pControls != std::cend(_rControls)) { Reference< XControl > xControl( *pControls ); + auto i = static_cast<sal_Int32>(std::distance(std::cbegin(_rControls), pControls)); if ( _bRemove ) - { - auto i = static_cast<sal_Int32>(std::distance(_rControls.begin(), pControls)); ::comphelper::removeElementAt( _rControls, i ); - } else if ( _bOverWrite ) - pControls->clear(); + _rControls[i].clear(); return xControl; } return Reference< XControl > (); @@ -2449,11 +2447,11 @@ void FormController::insertControl(const Reference< XControl > & xControl) void FormController::removeControl(const Reference< XControl > & xControl) { OSL_ENSURE( !impl_isDisposed_nofail(), "FormController: already disposed!" ); - auto pControl = std::find_if(m_aControls.begin(), m_aControls.end(), + auto pControl = std::find_if(std::cbegin(m_aControls), std::cend(m_aControls), [&xControl](const Reference< XControl >& rControl) { return xControl.get() == rControl.get(); }); - if (pControl != m_aControls.end()) + if (pControl != std::cend(m_aControls)) { - auto nIndex = static_cast<sal_Int32>(std::distance(m_aControls.begin(), pControl)); + auto nIndex = static_cast<sal_Int32>(std::distance(std::cbegin(m_aControls), pControl)); ::comphelper::removeElementAt( m_aControls, nIndex ); } diff --git a/svx/source/items/customshapeitem.cxx b/svx/source/items/customshapeitem.cxx index 9a86a3bdb4aa..a2cd8c8d32b2 100644 --- a/svx/source/items/customshapeitem.cxx +++ b/svx/source/items/customshapeitem.cxx @@ -141,7 +141,7 @@ void SdrCustomShapeGeometryItem::SetPropertyValue( const css::beans::PropertyVal } else { // it's a new property - assert(std::none_of(aPropSeq.begin(), aPropSeq.end(), + assert(std::none_of(std::cbegin(aPropSeq), std::cend(aPropSeq), [&rPropVal](beans::PropertyValue const& rVal) { return rVal.Name == rPropVal.Name; } )); sal_uInt32 nIndex = aPropSeq.getLength(); @@ -167,7 +167,7 @@ void SdrCustomShapeGeometryItem::SetPropertyValue( const OUString& rSequenceName aValue.Name = rSequenceName; aValue.Value <<= aSeq; - assert(std::none_of(aPropSeq.begin(), aPropSeq.end(), + assert(std::none_of(std::cbegin(aPropSeq), std::cend(aPropSeq), [&rSequenceName](beans::PropertyValue const& rV) { return rV.Name == rSequenceName; } )); sal_uInt32 nIndex = aPropSeq.getLength(); @@ -279,7 +279,7 @@ bool SdrCustomShapeGeometryItem::PutValue( const uno::Any& rVal, sal_uInt8 /*nMe for (sal_Int32 i = 0; i < aPropSeq.getLength(); ++i) { const auto& rName = aPropSeq[i].Name; - bool isDuplicated = std::any_of(std::next(aPropSeq.begin(), i + 1), aPropSeq.end(), + bool isDuplicated = std::any_of(std::next(std::cbegin(aPropSeq), i + 1), std::cend(aPropSeq), [&rName](const css::beans::PropertyValue& rProp) { return rProp.Name == rName; }); if (isDuplicated) { diff --git a/svx/source/table/accessiblecell.cxx b/svx/source/table/accessiblecell.cxx index 71d0bdf59555..d298555734ba 100644 --- a/svx/source/table/accessiblecell.cxx +++ b/svx/source/table/accessiblecell.cxx @@ -222,7 +222,7 @@ Reference<XAccessibleStateSet> SAL_CALL AccessibleCell::getAccessibleStateSet() xTempAccContext->getAccessibleStateSet(); if( rState.is() ) { - css::uno::Sequence<short> aStates = rState->getStates(); + const css::uno::Sequence<short> aStates = rState->getStates(); if (std::find(aStates.begin(), aStates.end(), AccessibleStateType::EDITABLE) != aStates.end()) { pStateSet->AddState (AccessibleStateType::EDITABLE); |