summaryrefslogtreecommitdiff
path: root/sd/source
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 /sd/source
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 'sd/source')
-rw-r--r--sd/source/core/CustomAnimationEffect.cxx45
-rw-r--r--sd/source/core/CustomAnimationPreset.cxx2
-rw-r--r--sd/source/core/TransitionPreset.cxx2
-rw-r--r--sd/source/core/stlsheet.cxx2
-rw-r--r--sd/source/filter/eppt/pptexanimations.cxx2
-rw-r--r--sd/source/filter/html/HtmlOptionsDialog.cxx13
-rw-r--r--sd/source/ui/framework/configuration/ResourceId.cxx2
-rw-r--r--sd/source/ui/remotecontrol/Server.cxx2
-rw-r--r--sd/source/ui/view/ViewShellBase.cxx4
9 files changed, 41 insertions, 33 deletions
diff --git a/sd/source/core/CustomAnimationEffect.cxx b/sd/source/core/CustomAnimationEffect.cxx
index d82a89e65da3..83a3e674e710 100644
--- a/sd/source/core/CustomAnimationEffect.cxx
+++ b/sd/source/core/CustomAnimationEffect.cxx
@@ -387,7 +387,7 @@ sal_Int32 CustomAnimationEffect::get_node_type( const Reference< XAnimationNode
if( xNode.is() )
{
- Sequence< NamedValue > aUserData( xNode->getUserData() );
+ const Sequence< NamedValue > aUserData( xNode->getUserData() );
if( aUserData.hasElements() )
{
const NamedValue* pProp = std::find_if(aUserData.begin(), aUserData.end(),
@@ -418,17 +418,18 @@ void CustomAnimationEffect::setPresetClassAndId( sal_Int16 nPresetClass, const O
bool bFoundPresetId = false;
if( nLength )
{
- NamedValue* pProp = std::find_if(aUserData.begin(), aUserData.end(),
+ auto [begin, end] = toNonConstRange(aUserData);
+ NamedValue* pProp = std::find_if(begin, end,
[](const NamedValue& rProp) { return rProp.Name == "preset-class"; });
- if (pProp != aUserData.end())
+ if (pProp != end)
{
pProp->Value <<= mnPresetClass;
bFoundPresetClass = true;
}
- pProp = std::find_if(aUserData.begin(), aUserData.end(),
+ pProp = std::find_if(begin, end,
[](const NamedValue& rProp) { return rProp.Name == "preset-id"; });
- if (pProp != aUserData.end())
+ if (pProp != end)
{
pProp->Value <<= mnPresetClass;
bFoundPresetId = true;
@@ -439,16 +440,18 @@ void CustomAnimationEffect::setPresetClassAndId( sal_Int16 nPresetClass, const O
if( !bFoundPresetClass )
{
aUserData.realloc( nLength + 1);
- aUserData[nLength].Name = "preset-class";
- aUserData[nLength].Value <<= mnPresetClass;
+ auto& el = aUserData[nLength];
+ el.Name = "preset-class";
+ el.Value <<= mnPresetClass;
++nLength;
}
if( !bFoundPresetId && maPresetId.getLength() > 0 )
{
aUserData.realloc( nLength + 1);
- aUserData[nLength].Name = "preset-id";
- aUserData[nLength].Value <<= maPresetId;
+ auto& el = aUserData[nLength];
+ el.Name = "preset-id";
+ el.Value <<= maPresetId;
}
mxNode->setUserData( aUserData );
@@ -470,9 +473,10 @@ void CustomAnimationEffect::setNodeType( sal_Int16 nNodeType )
bool bFound = false;
if( nLength )
{
- NamedValue* pProp = std::find_if(aUserData.begin(), aUserData.end(),
+ auto [begin, end] = toNonConstRange(aUserData);
+ NamedValue* pProp = std::find_if(begin, end,
[](const NamedValue& rProp) { return rProp.Name == "node-type"; });
- if (pProp != aUserData.end())
+ if (pProp != end)
{
pProp->Value <<= mnNodeType;
bFound = true;
@@ -483,8 +487,9 @@ void CustomAnimationEffect::setNodeType( sal_Int16 nNodeType )
if( !bFound )
{
aUserData.realloc( nLength + 1);
- aUserData[nLength].Name = "node-type";
- aUserData[nLength].Value <<= mnNodeType;
+ auto& el = aUserData[nLength];
+ el.Name = "node-type";
+ el.Value <<= mnNodeType;
}
mxNode->setUserData( aUserData );
@@ -503,9 +508,10 @@ void CustomAnimationEffect::setGroupId( sal_Int32 nGroupId )
bool bFound = false;
if( nLength )
{
- NamedValue* pProp = std::find_if(aUserData.begin(), aUserData.end(),
+ auto [begin, end] = toNonConstRange(aUserData);
+ NamedValue* pProp = std::find_if(begin, end,
[](const NamedValue& rProp) { return rProp.Name == "group-id"; });
- if (pProp != aUserData.end())
+ if (pProp != end)
{
pProp->Value <<= mnGroupId;
bFound = true;
@@ -516,8 +522,9 @@ void CustomAnimationEffect::setGroupId( sal_Int32 nGroupId )
if( !bFound )
{
aUserData.realloc( nLength + 1);
- aUserData[nLength].Name = "group-id";
- aUserData[nLength].Value <<= mnGroupId;
+ auto& el = aUserData[nLength];
+ el.Name = "group-id";
+ el.Value <<= mnGroupId;
}
mxNode->setUserData( aUserData );
@@ -1677,7 +1684,7 @@ CustomAnimationEffectPtr EffectSequenceHelper::append( const CustomAnimationPres
std::vector< NamedValue > aNewUserData;
Sequence< NamedValue > aUserData( xNode->getUserData() );
- std::copy_if(aUserData.begin(), aUserData.end(), std::back_inserter(aNewUserData),
+ std::copy_if(std::cbegin(aUserData), std::cend(aUserData), std::back_inserter(aNewUserData),
[](const NamedValue& rProp) { return rProp.Name != "text-only" && rProp.Name != "preset-property"; });
if( !aNewUserData.empty() )
@@ -2972,7 +2979,7 @@ void EffectSequenceHelper::processAfterEffect( const Reference< XAnimationNode >
{
Reference< XAnimationNode > xMaster;
- Sequence< NamedValue > aUserData( xNode->getUserData() );
+ const Sequence< NamedValue > aUserData( xNode->getUserData() );
const NamedValue* pProp = std::find_if(aUserData.begin(), aUserData.end(),
[](const NamedValue& rProp) { return rProp.Name == "master-element"; });
diff --git a/sd/source/core/CustomAnimationPreset.cxx b/sd/source/core/CustomAnimationPreset.cxx
index 5147cb3cf0e0..0bb74770b732 100644
--- a/sd/source/core/CustomAnimationPreset.cxx
+++ b/sd/source/core/CustomAnimationPreset.cxx
@@ -123,7 +123,7 @@ CustomAnimationPreset::CustomAnimationPreset( const CustomAnimationEffectPtr& pE
mfDuration = pEffect->getDuration();
maDefaultSubTyp = pEffect->getPresetSubType();
- Sequence< NamedValue > aUserData( pEffect->getNode()->getUserData() );
+ const Sequence< NamedValue > aUserData( pEffect->getNode()->getUserData() );
mbIsTextOnly = std::any_of(aUserData.begin(), aUserData.end(),
[](const NamedValue& rProp) { return rProp.Name == "text-only"; });
diff --git a/sd/source/core/TransitionPreset.cxx b/sd/source/core/TransitionPreset.cxx
index 19914e3498e4..992c5a1e0b7e 100644
--- a/sd/source/core/TransitionPreset.cxx
+++ b/sd/source/core/TransitionPreset.cxx
@@ -61,7 +61,7 @@ namespace sd {
TransitionPreset::TransitionPreset( const css::uno::Reference< css::animations::XAnimationNode >& xNode )
{
// first locate preset id
- Sequence< NamedValue > aUserData( xNode->getUserData() );
+ const Sequence< NamedValue > aUserData( xNode->getUserData() );
const NamedValue* pProp = std::find_if(aUserData.begin(), aUserData.end(),
[](const NamedValue& rProp) { return rProp.Name == "preset-id"; });
if (pProp != aUserData.end())
diff --git a/sd/source/core/stlsheet.cxx b/sd/source/core/stlsheet.cxx
index 67c0758ec4d6..72298f94d951 100644
--- a/sd/source/core/stlsheet.cxx
+++ b/sd/source/core/stlsheet.cxx
@@ -305,7 +305,7 @@ bool SdStyleSheet::IsUsed() const
cppu::OInterfaceContainerHelper * pContainer = mrBHelper.getContainer( cppu::UnoType<XModifyListener>::get() );
if( pContainer )
{
- Sequence< Reference< XInterface > > aModifyListeners( pContainer->getElements() );
+ const Sequence< Reference< XInterface > > aModifyListeners( pContainer->getElements() );
bResult = std::any_of(aModifyListeners.begin(), aModifyListeners.end(),
[](const Reference<XInterface>& rListener) {
Reference< XStyle > xStyle( rListener, UNO_QUERY );
diff --git a/sd/source/filter/eppt/pptexanimations.cxx b/sd/source/filter/eppt/pptexanimations.cxx
index 1b8f314dff38..1b455036b766 100644
--- a/sd/source/filter/eppt/pptexanimations.cxx
+++ b/sd/source/filter/eppt/pptexanimations.cxx
@@ -374,7 +374,7 @@ void AnimationExporter::processAfterEffectNodes( const Reference< XAnimationNode
{
Reference< XAnimationNode > xMaster;
- Sequence< NamedValue > aUserData( xChildNode3->getUserData() );
+ const Sequence< NamedValue > aUserData( xChildNode3->getUserData() );
const NamedValue* p = std::find_if(aUserData.begin(), aUserData.end(),
[](const NamedValue& rProp) { return rProp.Name == "master-element"; });
diff --git a/sd/source/filter/html/HtmlOptionsDialog.cxx b/sd/source/filter/html/HtmlOptionsDialog.cxx
index c7d2f7a8eb09..daa5e7362a39 100644
--- a/sd/source/filter/html/HtmlOptionsDialog.cxx
+++ b/sd/source/filter/html/HtmlOptionsDialog.cxx
@@ -123,16 +123,17 @@ Sequence< OUString > SAL_CALL SdHtmlOptionsDialog::getSupportedServiceNames()
// XPropertyAccess
Sequence< PropertyValue > SdHtmlOptionsDialog::getPropertyValues()
{
- auto pProp = std::find_if(maMediaDescriptor.begin(), maMediaDescriptor.end(),
+ auto pProp = std::find_if(std::cbegin(maMediaDescriptor), std::cend(maMediaDescriptor),
[](const PropertyValue& rProp) { return rProp.Name == "FilterData"; });
- auto i = static_cast<sal_Int32>(std::distance(maMediaDescriptor.begin(), pProp));
+ auto i = static_cast<sal_Int32>(std::distance(std::cbegin(maMediaDescriptor), pProp));
sal_Int32 nCount = maMediaDescriptor.getLength();
if ( i == nCount )
maMediaDescriptor.realloc( ++nCount );
// the "FilterData" Property is an Any that will contain our PropertySequence of Values
- maMediaDescriptor[ i ].Name = "FilterData";
- maMediaDescriptor[ i ].Value <<= maFilterDataSequence;
+ auto& el = maMediaDescriptor[ i ];
+ el.Name = "FilterData";
+ el.Value <<= maFilterDataSequence;
return maMediaDescriptor;
}
@@ -140,9 +141,9 @@ void SdHtmlOptionsDialog::setPropertyValues( const Sequence< PropertyValue > & a
{
maMediaDescriptor = aProps;
- auto pProp = std::find_if(maMediaDescriptor.begin(), maMediaDescriptor.end(),
+ auto pProp = std::find_if(std::cbegin(maMediaDescriptor), std::cend(maMediaDescriptor),
[](const PropertyValue& rProp) { return rProp.Name == "FilterData"; });
- if (pProp != maMediaDescriptor.end())
+ if (pProp != std::cend(maMediaDescriptor))
pProp->Value >>= maFilterDataSequence;
}
diff --git a/sd/source/ui/framework/configuration/ResourceId.cxx b/sd/source/ui/framework/configuration/ResourceId.cxx
index 48a6d360f5f2..9afc594cd7e9 100644
--- a/sd/source/ui/framework/configuration/ResourceId.cxx
+++ b/sd/source/ui/framework/configuration/ResourceId.cxx
@@ -362,7 +362,7 @@ void SAL_CALL ResourceId::initialize (const Sequence<Any>& aArguments)
if (xAnchor.is())
{
maResourceURLs.push_back(xAnchor->getResourceURL());
- Sequence<OUString> aAnchorURLs (xAnchor->getAnchorURLs());
+ const Sequence<OUString> aAnchorURLs (xAnchor->getAnchorURLs());
maResourceURLs.insert( maResourceURLs.end(), aAnchorURLs.begin(), aAnchorURLs.end() );
}
}
diff --git a/sd/source/ui/remotecontrol/Server.cxx b/sd/source/ui/remotecontrol/Server.cxx
index 1a53e682eca6..d1942df124c8 100644
--- a/sd/source/ui/remotecontrol/Server.cxx
+++ b/sd/source/ui/remotecontrol/Server.cxx
@@ -247,7 +247,7 @@ std::vector< std::shared_ptr< ClientInfo > > RemoteServer::getClients()
// TODO: we should probably add some sort of extra labelling to mark
// authorised AND connected client.
Reference< XNameAccess > const xConfig = officecfg::Office::Impress::Misc::AuthorisedRemotes::get();
- Sequence< OUString > aNames = xConfig->getElementNames();
+ const Sequence< OUString > aNames = xConfig->getElementNames();
std::transform(aNames.begin(), aNames.end(), std::back_inserter(aClients),
[](const OUString& rName) -> std::shared_ptr<ClientInfo> {
return std::make_shared<ClientInfo>(rName, true); });
diff --git a/sd/source/ui/view/ViewShellBase.cxx b/sd/source/ui/view/ViewShellBase.cxx
index 897aed6f1524..7cc5a58b8da5 100644
--- a/sd/source/ui/view/ViewShellBase.cxx
+++ b/sd/source/ui/view/ViewShellBase.cxx
@@ -873,9 +873,9 @@ OUString ViewShellBase::GetInitialViewShellType() const
// Search the properties for the one that tells us what page kind to
// use.
- auto pProperty = std::find_if(aProperties.begin(), aProperties.end(),
+ auto pProperty = std::find_if(std::cbegin(aProperties), std::cend(aProperties),
[](const beans::PropertyValue& rProperty) { return rProperty.Name == sUNO_View_PageKind; });
- if (pProperty != aProperties.end())
+ if (pProperty != std::cend(aProperties))
{
sal_Int16 nPageKind = 0;
pProperty->Value >>= nPageKind;