summaryrefslogtreecommitdiff
path: root/extensions
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 /extensions
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 'extensions')
-rw-r--r--extensions/source/bibliography/formcontrolcontainer.cxx17
-rw-r--r--extensions/source/propctrlr/cellbindinghelper.cxx15
-rw-r--r--extensions/source/propctrlr/eformshelper.cxx6
-rw-r--r--extensions/source/propctrlr/eventhandler.cxx4
-rw-r--r--extensions/source/propctrlr/formcomponenthandler.cxx2
-rw-r--r--extensions/source/propctrlr/genericpropertyhandler.cxx4
-rw-r--r--extensions/source/propctrlr/stringrepresentation.cxx3
-rw-r--r--extensions/source/propctrlr/xsdvalidationhelper.cxx9
8 files changed, 32 insertions, 28 deletions
diff --git a/extensions/source/bibliography/formcontrolcontainer.cxx b/extensions/source/bibliography/formcontrolcontainer.cxx
index 5e9f7d37aa35..c6ec73700656 100644
--- a/extensions/source/bibliography/formcontrolcontainer.cxx
+++ b/extensions/source/bibliography/formcontrolcontainer.cxx
@@ -92,15 +92,16 @@ namespace bib
try
{
Reference< XControlContainer > xControlCont = getControlContainer();
- Sequence< Reference< XControl > > aControls;
if ( xControlCont.is() )
- aControls = xControlCont->getControls();
-
- std::for_each(
- aControls.begin(),
- aControls.end(),
- ControlModeSwitch( _bDesign )
- );
+ {
+ const Sequence<Reference<XControl>> aControls = xControlCont->getControls();
+
+ std::for_each(
+ aControls.begin(),
+ aControls.end(),
+ ControlModeSwitch( _bDesign )
+ );
+ }
}
catch( const Exception&)
{
diff --git a/extensions/source/propctrlr/cellbindinghelper.cxx b/extensions/source/propctrlr/cellbindinghelper.cxx
index e27345e7fee7..90dd8b77277b 100644
--- a/extensions/source/propctrlr/cellbindinghelper.cxx
+++ b/extensions/source/propctrlr/cellbindinghelper.cxx
@@ -375,15 +375,16 @@ namespace pcr
Reference< XMultiServiceFactory > xDocumentFactory( m_xDocument, UNO_QUERY );
OSL_ENSURE( xDocumentFactory.is(), "CellBindingHelper::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 )
+ );
+ }
}
return bYesItIs;
diff --git a/extensions/source/propctrlr/eformshelper.cxx b/extensions/source/propctrlr/eformshelper.cxx
index 36f5f2a2b44d..ff0a91e0e518 100644
--- a/extensions/source/propctrlr/eformshelper.cxx
+++ b/extensions/source/propctrlr/eformshelper.cxx
@@ -305,7 +305,7 @@ namespace pcr
OSL_ENSURE( xForms.is(), "EFormsHelper::getFormModelNames: invalid forms container!" );
if ( xForms.is() )
{
- Sequence< OUString > aModelNames = xForms->getElementNames();
+ const Sequence< OUString > aModelNames = xForms->getElementNames();
_rModelNames.resize( aModelNames.getLength() );
std::copy( aModelNames.begin(), aModelNames.end(), _rModelNames.begin() );
}
@@ -329,7 +329,7 @@ namespace pcr
OSL_ENSURE( xBindings.is(), "EFormsHelper::getBindingNames: invalid bindings container obtained from the model!" );
if ( xBindings.is() )
{
- Sequence< OUString > aNames = xBindings->getElementNames();
+ const Sequence< OUString > aNames = xBindings->getElementNames();
_rBindingNames.resize( aNames.getLength() );
std::copy( aNames.begin(), aNames.end(), _rBindingNames.begin() );
}
@@ -590,7 +590,7 @@ namespace pcr
xInfo = _rxProps->getPropertySetInfo();
if ( xInfo.is() )
{
- Sequence< Property > aProperties = xInfo->getProperties();
+ const Sequence< Property > aProperties = xInfo->getProperties();
std::for_each( aProperties.begin(), aProperties.end(),
PropertyBagInserter( _rBag )
);
diff --git a/extensions/source/propctrlr/eventhandler.cxx b/extensions/source/propctrlr/eventhandler.cxx
index 940d7d48f379..b920a4262650 100644
--- a/extensions/source/propctrlr/eventhandler.cxx
+++ b/extensions/source/propctrlr/eventhandler.cxx
@@ -276,7 +276,7 @@ namespace pcr
Reference< XIntrospectionAccess > xIntrospectionAccess(
_rxIntrospection->inspect( makeAny( _rxComponent ) ), UNO_SET_THROW );
- Sequence< Type > aListeners( xIntrospectionAccess->getSupportedListeners() );
+ const Sequence< Type > aListeners( xIntrospectionAccess->getSupportedListeners() );
std::copy( aListeners.begin(), aListeners.end(),
std::insert_iterator< TypeBag >( _out_rTypes, _out_rTypes.begin() ) );
@@ -770,7 +770,7 @@ namespace pcr
}
// the initial selection in the dialog
- Sequence< OUString > aNames( pEventHolder->getElementNames() );
+ const Sequence< OUString > aNames( pEventHolder->getElementNames() );
const OUString* pChosenEvent = std::find( aNames.begin(), aNames.end(), rForEvent.sListenerMethodName );
sal_uInt16 nInitialSelection = static_cast<sal_uInt16>( pChosenEvent - aNames.begin() );
diff --git a/extensions/source/propctrlr/formcomponenthandler.cxx b/extensions/source/propctrlr/formcomponenthandler.cxx
index 1bea9150f14f..92c03d54e17c 100644
--- a/extensions/source/propctrlr/formcomponenthandler.cxx
+++ b/extensions/source/propctrlr/formcomponenthandler.cxx
@@ -1329,7 +1329,7 @@ namespace pcr
std::vector< OUString > aListEntries;
Reference< XDatabaseContext > xDatabaseContext = sdb::DatabaseContext::create( m_xContext );
- Sequence< OUString > aDatasources = xDatabaseContext->getElementNames();
+ const Sequence< OUString > aDatasources = xDatabaseContext->getElementNames();
aListEntries.resize( aDatasources.getLength() );
std::copy( aDatasources.begin(), aDatasources.end(), aListEntries.begin() );
aDescriptor.Control = PropertyHandlerHelper::createComboBoxControl(
diff --git a/extensions/source/propctrlr/genericpropertyhandler.cxx b/extensions/source/propctrlr/genericpropertyhandler.cxx
index 984f951dfd58..485c6937c2f6 100644
--- a/extensions/source/propctrlr/genericpropertyhandler.cxx
+++ b/extensions/source/propctrlr/genericpropertyhandler.cxx
@@ -116,7 +116,7 @@ namespace pcr
TOOLS_WARN_EXCEPTION( "extensions.propctrlr", "EnumRepresentation::getDescriptions" );
}
- return std::vector< OUString >( aNames.begin(), aNames.end() );
+ return std::vector< OUString >( std::cbegin(aNames), std::cend(aNames) );
}
void EnumRepresentation::impl_getValues( Sequence< sal_Int32 >& _out_rValues ) const
@@ -162,7 +162,7 @@ namespace pcr
Sequence< sal_Int32 > aValues;
impl_getValues( aValues );
- sal_Int32 index = std::find( aValues.begin(), aValues.end(), nAsInt ) - aValues.begin();
+ sal_Int32 index = std::find( std::cbegin(aValues), std::cend(aValues), nAsInt ) - std::cbegin(aValues);
std::vector< OUString > aDescriptions( getDescriptions() );
if ( ( index >= 0 ) && ( index < static_cast<sal_Int32>(aDescriptions.size()) ) )
diff --git a/extensions/source/propctrlr/stringrepresentation.cxx b/extensions/source/propctrlr/stringrepresentation.cxx
index 3e28295d7348..073cbbedd130 100644
--- a/extensions/source/propctrlr/stringrepresentation.cxx
+++ b/extensions/source/propctrlr/stringrepresentation.cxx
@@ -255,7 +255,8 @@ void SAL_CALL StringRepresentation::initialize(const uno::Sequence< uno::Any > &
uno::Sequence<
uno::Reference< reflection::XConstantTypeDescription > >
cs(m_xTypeDescription->getConstants());
- std::sort(cs.begin(), cs.end(), CompareConstants());
+ auto [begin, end] = toNonConstRange(cs);
+ std::sort(begin, end, CompareConstants());
m_aConstants = cs;
}
diff --git a/extensions/source/propctrlr/xsdvalidationhelper.cxx b/extensions/source/propctrlr/xsdvalidationhelper.cxx
index 12197e87d0b3..390993de6aca 100644
--- a/extensions/source/propctrlr/xsdvalidationhelper.cxx
+++ b/extensions/source/propctrlr/xsdvalidationhelper.cxx
@@ -83,12 +83,13 @@ namespace pcr
try
{
Reference< XDataTypeRepository > xRepository = getDataTypeRepository();
- Sequence< OUString > aElements;
if ( xRepository.is() )
- aElements = xRepository->getElementNames();
+ {
+ const Sequence<OUString> aElements = xRepository->getElementNames();
- _rNames.resize( aElements.getLength() );
- std::copy( aElements.begin(), aElements.end(), _rNames.begin() );
+ _rNames.resize( aElements.getLength() );
+ std::copy( aElements.begin(), aElements.end(), _rNames.begin() );
+ }
}
catch( const Exception& )
{