summaryrefslogtreecommitdiff
path: root/svtools
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 /svtools
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 'svtools')
-rw-r--r--svtools/source/dialogs/addresstemplate.cxx4
-rw-r--r--svtools/source/filter/SvFilterOptionsDialog.cxx9
-rw-r--r--svtools/source/uno/unocontroltablemodel.cxx2
3 files changed, 8 insertions, 7 deletions
diff --git a/svtools/source/dialogs/addresstemplate.cxx b/svtools/source/dialogs/addresstemplate.cxx
index e95d127f2147..b7d787b53aae 100644
--- a/svtools/source/dialogs/addresstemplate.cxx
+++ b/svtools/source/dialogs/addresstemplate.cxx
@@ -288,7 +288,7 @@ void AssignmentPersistentData::ImplCommit()
AssignmentPersistentData::AssignmentPersistentData()
:ConfigItem("Office.DataAccess/AddressBook")
{
- Sequence< OUString > aStoredNames = GetNodeNames("Fields");
+ const Sequence< OUString > aStoredNames = GetNodeNames("Fields");
m_aStoredFields.insert(aStoredNames.begin(), aStoredNames.end());
}
@@ -846,7 +846,7 @@ void AssignmentPersistentData::ImplCommit()
// for quicker access
- ::std::set< OUString > aColumnNameSet(aColumnNames.begin(), aColumnNames.end());
+ ::std::set< OUString > aColumnNameSet(std::cbegin(aColumnNames), std::cend(aColumnNames));
std::vector<OUString>::iterator aInitialSelection = m_pImpl->aFieldAssignments.begin() + m_pImpl->nFieldScrollPos;
diff --git a/svtools/source/filter/SvFilterOptionsDialog.cxx b/svtools/source/filter/SvFilterOptionsDialog.cxx
index ada6aafecbd3..698e49e0725a 100644
--- a/svtools/source/filter/SvFilterOptionsDialog.cxx
+++ b/svtools/source/filter/SvFilterOptionsDialog.cxx
@@ -148,16 +148,17 @@ uno::Sequence< OUString > SAL_CALL SvFilterOptionsDialog::getSupportedServiceNam
// XPropertyAccess
uno::Sequence< beans::PropertyValue > SvFilterOptionsDialog::getPropertyValues()
{
- auto pProp = std::find_if(maMediaDescriptor.begin(), maMediaDescriptor.end(),
+ auto pProp = std::find_if(std::cbegin(maMediaDescriptor), std::cend(maMediaDescriptor),
[](const beans::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& item = maMediaDescriptor[ i ];
+ item.Name = "FilterData";
+ item.Value <<= maFilterDataSequence;
return maMediaDescriptor;
}
diff --git a/svtools/source/uno/unocontroltablemodel.cxx b/svtools/source/uno/unocontroltablemodel.cxx
index 96f3722b994c..14f9c6977fca 100644
--- a/svtools/source/uno/unocontroltablemodel.cxx
+++ b/svtools/source/uno/unocontroltablemodel.cxx
@@ -652,7 +652,7 @@ namespace svt::table
else
{
::std::vector< ::Color > aColors( aAPIColors.getLength() );
- std::transform(aAPIColors.begin(), aAPIColors.end(), aColors.begin(),
+ std::transform(std::cbegin(aAPIColors), std::cend(aAPIColors), aColors.begin(),
[](const css::util::Color& rAPIColor) -> ::Color { return Color(ColorTransparency, rAPIColor); });
m_aRowColors = aColors;
}