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 /ucb/source/ucp | |
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 'ucb/source/ucp')
-rw-r--r-- | ucb/source/ucp/file/filcmd.cxx | 12 | ||||
-rw-r--r-- | ucb/source/ucp/file/filprp.cxx | 6 | ||||
-rw-r--r-- | ucb/source/ucp/file/filrset.cxx | 6 | ||||
-rw-r--r-- | ucb/source/ucp/file/prov.cxx | 6 | ||||
-rw-r--r-- | ucb/source/ucp/ftp/ftpcontent.cxx | 2 | ||||
-rw-r--r-- | ucb/source/ucp/ftp/ftpresultsetbase.cxx | 6 | ||||
-rw-r--r-- | ucb/source/ucp/webdav-neon/webdavcontent.cxx | 2 |
7 files changed, 20 insertions, 20 deletions
diff --git a/ucb/source/ucp/file/filcmd.cxx b/ucb/source/ucp/file/filcmd.cxx index 6742f693d0e7..7bbfca94e080 100644 --- a/ucb/source/ucp/file/filcmd.cxx +++ b/ucb/source/ucp/file/filcmd.cxx @@ -81,9 +81,9 @@ CommandInfo SAL_CALL XCommandInfo_impl::getCommandInfoByName( const OUString& aName ) { - auto pCommand = std::find_if(m_pMyShell->m_sCommandInfo.begin(), m_pMyShell->m_sCommandInfo.end(), + auto pCommand = std::find_if(std::cbegin(m_pMyShell->m_sCommandInfo), std::cend(m_pMyShell->m_sCommandInfo), [&aName](const CommandInfo& rCommand) { return rCommand.Name == aName; }); - if (pCommand != m_pMyShell->m_sCommandInfo.end()) + if (pCommand != std::cend(m_pMyShell->m_sCommandInfo)) return *pCommand; throw UnsupportedCommandException( THROW_WHERE ); @@ -94,9 +94,9 @@ CommandInfo SAL_CALL XCommandInfo_impl::getCommandInfoByHandle( sal_Int32 Handle ) { - auto pCommand = std::find_if(m_pMyShell->m_sCommandInfo.begin(), m_pMyShell->m_sCommandInfo.end(), + auto pCommand = std::find_if(std::cbegin(m_pMyShell->m_sCommandInfo), std::cend(m_pMyShell->m_sCommandInfo), [&Handle](const CommandInfo& rCommand) { return rCommand.Handle == Handle; }); - if (pCommand != m_pMyShell->m_sCommandInfo.end()) + if (pCommand != std::cend(m_pMyShell->m_sCommandInfo)) return *pCommand; throw UnsupportedCommandException( THROW_WHERE ); @@ -107,7 +107,7 @@ sal_Bool SAL_CALL XCommandInfo_impl::hasCommandByName( const OUString& aName ) { - return std::any_of(m_pMyShell->m_sCommandInfo.begin(), m_pMyShell->m_sCommandInfo.end(), + return std::any_of(std::cbegin(m_pMyShell->m_sCommandInfo), std::cend(m_pMyShell->m_sCommandInfo), [&aName](const CommandInfo& rCommand) { return rCommand.Name == aName; }); } @@ -116,7 +116,7 @@ sal_Bool SAL_CALL XCommandInfo_impl::hasCommandByHandle( sal_Int32 Handle ) { - return std::any_of(m_pMyShell->m_sCommandInfo.begin(), m_pMyShell->m_sCommandInfo.end(), + return std::any_of(std::cbegin(m_pMyShell->m_sCommandInfo), std::cend(m_pMyShell->m_sCommandInfo), [&Handle](const CommandInfo& rCommand) { return rCommand.Handle == Handle; }); } diff --git a/ucb/source/ucp/file/filprp.cxx b/ucb/source/ucp/file/filprp.cxx index 7f64caa145e0..3cab28c70ddf 100644 --- a/ucb/source/ucp/file/filprp.cxx +++ b/ucb/source/ucp/file/filprp.cxx @@ -68,9 +68,9 @@ XPropertySetInfo_impl::~XPropertySetInfo_impl() beans::Property SAL_CALL XPropertySetInfo_impl::getPropertyByName( const OUString& aName ) { - auto pProp = std::find_if(m_seq.begin(), m_seq.end(), + auto pProp = std::find_if(std::cbegin(m_seq), std::cend(m_seq), [&aName](const beans::Property& rProp) { return rProp.Name == aName; }); - if (pProp != m_seq.end()) + if (pProp != std::cend(m_seq)) return *pProp; throw beans::UnknownPropertyException( aName ); @@ -87,7 +87,7 @@ XPropertySetInfo_impl::getProperties() sal_Bool SAL_CALL XPropertySetInfo_impl::hasPropertyByName( const OUString& aName ) { - return std::any_of(m_seq.begin(), m_seq.end(), + return std::any_of(std::cbegin(m_seq), std::cend(m_seq), [&aName](const beans::Property& rProp) { return rProp.Name == aName; }); } diff --git a/ucb/source/ucp/file/filrset.cxx b/ucb/source/ucp/file/filrset.cxx index 74531e226a23..2d954a8c6d7f 100644 --- a/ucb/source/ucp/file/filrset.cxx +++ b/ucb/source/ucp/file/filrset.cxx @@ -590,13 +590,13 @@ XResultSet_impl::getCapabilities() uno::Reference< sdbc::XResultSetMetaData > SAL_CALL XResultSet_impl::getMetaData() { - auto pProp = std::find_if(m_sProperty.begin(), m_sProperty.end(), + auto pProp = std::find_if(std::cbegin(m_sProperty), std::cend(m_sProperty), [](const beans::Property& rProp) { return rProp.Name == "Title"; }); - if (pProp != m_sProperty.end()) + if (pProp != std::cend(m_sProperty)) { std::vector< ::ucbhelper::ResultSetColumnData > aColumnData( m_sProperty.getLength() ); - auto n = std::distance(m_sProperty.begin(), pProp); + auto n = std::distance(std::cbegin(m_sProperty), pProp); // @@@ #82177# - Determine correct value! aColumnData[ n ].isCaseSensitive = false; diff --git a/ucb/source/ucp/file/prov.cxx b/ucb/source/ucp/file/prov.cxx index dfc4e373d7b8..f3ed2e84ca70 100644 --- a/ucb/source/ucp/file/prov.cxx +++ b/ucb/source/ucp/file/prov.cxx @@ -280,9 +280,9 @@ XPropertySetInfoImpl2::queryInterface( const Type& rType ) Property SAL_CALL XPropertySetInfoImpl2::getPropertyByName( const OUString& aName ) { - auto pProp = std::find_if(m_seq.begin(), m_seq.end(), + auto pProp = std::find_if(std::cbegin(m_seq), std::cend(m_seq), [&aName](const Property& rProp) { return rProp.Name == aName; }); - if (pProp != m_seq.end()) + if (pProp != std::cend(m_seq)) return *pProp; throw UnknownPropertyException( aName ); @@ -300,7 +300,7 @@ sal_Bool SAL_CALL XPropertySetInfoImpl2::hasPropertyByName( const OUString& aName ) { - return std::any_of(m_seq.begin(), m_seq.end(), + return std::any_of(std::cbegin(m_seq), std::cend(m_seq), [&aName](const Property& rProp) { return rProp.Name == aName; }); } diff --git a/ucb/source/ucp/ftp/ftpcontent.cxx b/ucb/source/ucp/ftp/ftpcontent.cxx index eb9219b9a5c1..ec74d7aeca8b 100644 --- a/ucb/source/ucp/ftp/ftpcontent.cxx +++ b/ucb/source/ucp/ftp/ftpcontent.cxx @@ -807,7 +807,7 @@ Sequence<Any> FTPContent::setPropertyValues( ret[i] <<= excep; } } else { - Sequence<Property> props = + const Sequence<Property> props = getProperties(Reference<XCommandEnvironment>(nullptr)); // either unknown or read-only diff --git a/ucb/source/ucp/ftp/ftpresultsetbase.cxx b/ucb/source/ucp/ftp/ftpresultsetbase.cxx index 66af1c4a8479..5a9a3326062d 100644 --- a/ucb/source/ucp/ftp/ftpresultsetbase.cxx +++ b/ucb/source/ucp/ftp/ftpresultsetbase.cxx @@ -374,16 +374,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/ucb/source/ucp/webdav-neon/webdavcontent.cxx b/ucb/source/ucp/webdav-neon/webdavcontent.cxx index 0ef3028b6be9..c613926e445d 100644 --- a/ucb/source/ucp/webdav-neon/webdavcontent.cxx +++ b/ucb/source/ucp/webdav-neon/webdavcontent.cxx @@ -3025,7 +3025,7 @@ Content::ResourceType Content::resourceTypeForLocks( uno::Sequence< ucb::LockEntry > aSupportedLocks; if ( rProp.Value >>= aSupportedLocks ) { - bool isSupported = std::any_of(aSupportedLocks.begin(), aSupportedLocks.end(), + bool isSupported = std::any_of(std::cbegin(aSupportedLocks), std::cend(aSupportedLocks), [](const ucb::LockEntry& rLock) { // TODO: if the lock type is changed from 'exclusive write' to 'shared write' // e.g. to implement 'Calc shared file feature', the ucb::LockScope_EXCLUSIVE |