summaryrefslogtreecommitdiff
path: root/xmlhelp
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 /xmlhelp
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 'xmlhelp')
-rw-r--r--xmlhelp/source/cxxhelp/provider/content.cxx4
-rw-r--r--xmlhelp/source/cxxhelp/provider/databases.cxx2
-rw-r--r--xmlhelp/source/cxxhelp/provider/resultsetbase.cxx6
-rw-r--r--xmlhelp/source/treeview/tvread.cxx2
4 files changed, 7 insertions, 7 deletions
diff --git a/xmlhelp/source/cxxhelp/provider/content.cxx b/xmlhelp/source/cxxhelp/provider/content.cxx
index 1dc5347f2d1e..c1dd7486f4dc 100644
--- a/xmlhelp/source/cxxhelp/provider/content.cxx
+++ b/xmlhelp/source/cxxhelp/provider/content.cxx
@@ -230,9 +230,9 @@ uno::Any SAL_CALL Content::execute(
}
uno::Sequence< uno::Any > ret(propertyValues.getLength());
- uno::Sequence< beans::Property > props(getProperties(Environment));
+ const uno::Sequence< beans::Property > props(getProperties(Environment));
// No properties can be set
- std::transform(propertyValues.begin(), propertyValues.end(), ret.begin(),
+ std::transform(std::cbegin(propertyValues), std::cend(propertyValues), ret.begin(),
[&props](const beans::PropertyValue& rPropVal) {
if (std::any_of(props.begin(), props.end(),
[&rPropVal](const beans::Property& rProp) { return rProp.Name == rPropVal.Name; }))
diff --git a/xmlhelp/source/cxxhelp/provider/databases.cxx b/xmlhelp/source/cxxhelp/provider/databases.cxx
index 37eb36b78d43..b5ca5ade2d11 100644
--- a/xmlhelp/source/cxxhelp/provider/databases.cxx
+++ b/xmlhelp/source/cxxhelp/provider/databases.cxx
@@ -1156,7 +1156,7 @@ Reference< deployment::XPackage > ExtensionIteratorBase::implGetHelpPackageFromP
OUString aHelpMediaType( "application/vnd.sun.star.help" );
if( xPackage->isBundle() )
{
- Sequence< Reference< deployment::XPackage > > aPkgSeq = xPackage->getBundle
+ const Sequence< Reference< deployment::XPackage > > aPkgSeq = xPackage->getBundle
( Reference<task::XAbortChannel>(), Reference<ucb::XCommandEnvironment>() );
auto pSubPkg = std::find_if(aPkgSeq.begin(), aPkgSeq.end(),
[&aHelpMediaType](const Reference< deployment::XPackage >& xSubPkg) {
diff --git a/xmlhelp/source/cxxhelp/provider/resultsetbase.cxx b/xmlhelp/source/cxxhelp/provider/resultsetbase.cxx
index ddb982985c65..b1f6219af4b7 100644
--- a/xmlhelp/source/cxxhelp/provider/resultsetbase.cxx
+++ b/xmlhelp/source/cxxhelp/provider/resultsetbase.cxx
@@ -368,16 +368,16 @@ public:
beans::Property SAL_CALL getPropertyByName( const OUString& aName ) override
{
- auto pProp = std::find_if(m_aSeq.begin(), m_aSeq.end(),
+ auto pProp = std::find_if(std::cbegin(m_aSeq), std::cend(m_aSeq),
[&aName](const beans::Property& rProp) { return aName == rProp.Name; });
- if (pProp != m_aSeq.end())
+ if (pProp != std::cend(m_aSeq))
return *pProp;
throw beans::UnknownPropertyException(aName);
}
sal_Bool SAL_CALL hasPropertyByName( const OUString& Name ) override
{
- return std::any_of(m_aSeq.begin(), m_aSeq.end(),
+ return std::any_of(std::cbegin(m_aSeq), std::cend(m_aSeq),
[&Name](const beans::Property& rProp) { return Name == rProp.Name; });
}
diff --git a/xmlhelp/source/treeview/tvread.cxx b/xmlhelp/source/treeview/tvread.cxx
index 852101bb52ad..a2e3afd50769 100644
--- a/xmlhelp/source/treeview/tvread.cxx
+++ b/xmlhelp/source/treeview/tvread.cxx
@@ -877,7 +877,7 @@ Reference< deployment::XPackage > TreeFileIterator::implGetHelpPackageFromPackag
if( xPackage->isBundle() )
{
- Sequence< Reference< deployment::XPackage > > aPkgSeq = xPackage->getBundle
+ const Sequence< Reference< deployment::XPackage > > aPkgSeq = xPackage->getBundle
( Reference<task::XAbortChannel>(), Reference<ucb::XCommandEnvironment>() );
auto pSubPkg = std::find_if(aPkgSeq.begin(), aPkgSeq.end(),
[](const Reference< deployment::XPackage >& xSubPkg) {