summaryrefslogtreecommitdiff
path: root/ucb
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 /ucb
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 'ucb')
-rw-r--r--ucb/source/cacher/cachedcontentresultset.cxx2
-rw-r--r--ucb/source/core/ucbcmds.cxx16
-rw-r--r--ucb/source/core/ucbprops.cxx4
-rw-r--r--ucb/source/ucp/file/filcmd.cxx12
-rw-r--r--ucb/source/ucp/file/filprp.cxx6
-rw-r--r--ucb/source/ucp/file/filrset.cxx6
-rw-r--r--ucb/source/ucp/file/prov.cxx6
-rw-r--r--ucb/source/ucp/ftp/ftpcontent.cxx2
-rw-r--r--ucb/source/ucp/ftp/ftpresultsetbase.cxx6
-rw-r--r--ucb/source/ucp/webdav-neon/webdavcontent.cxx2
10 files changed, 31 insertions, 31 deletions
diff --git a/ucb/source/cacher/cachedcontentresultset.cxx b/ucb/source/cacher/cachedcontentresultset.cxx
index bece903b57b3..8fbda792c435 100644
--- a/ucb/source/cacher/cachedcontentresultset.cxx
+++ b/ucb/source/cacher/cachedcontentresultset.cxx
@@ -249,7 +249,7 @@ Sequence< sal_Bool >& CachedContentResultSet::CCRS_Cache
{
sal_Int32 nCount = m_pResult->Rows.getLength();
m_pMappedReminder.emplace( nCount );
- std::fill(m_pMappedReminder->begin(), m_pMappedReminder->end(), false);
+ std::fill_n(m_pMappedReminder->begin(), m_pMappedReminder->getLength(), false);
}
return *m_pMappedReminder;
}
diff --git a/ucb/source/core/ucbcmds.cxx b/ucb/source/core/ucbcmds.cxx
index 7323cd78e94b..d3a08c695a6f 100644
--- a/ucb/source/core/ucbcmds.cxx
+++ b/ucb/source/core/ucbcmds.cxx
@@ -243,9 +243,9 @@ CommandProcessorInfo::getCommands()
ucb::CommandInfo SAL_CALL
CommandProcessorInfo::getCommandInfoByName( const OUString& Name )
{
- auto pInfo = std::find_if(m_xInfo->begin(), m_xInfo->end(),
+ auto pInfo = std::find_if(std::cbegin(*m_xInfo), std::cend(*m_xInfo),
[&Name](const ucb::CommandInfo& rInfo) { return rInfo.Name == Name; });
- if (pInfo != m_xInfo->end())
+ if (pInfo != std::cend(*m_xInfo))
return *pInfo;
throw ucb::UnsupportedCommandException();
@@ -256,9 +256,9 @@ CommandProcessorInfo::getCommandInfoByName( const OUString& Name )
ucb::CommandInfo SAL_CALL
CommandProcessorInfo::getCommandInfoByHandle( sal_Int32 Handle )
{
- auto pInfo = std::find_if(m_xInfo->begin(), m_xInfo->end(),
+ auto pInfo = std::find_if(std::cbegin(*m_xInfo), std::cend(*m_xInfo),
[&Handle](const ucb::CommandInfo& rInfo) { return rInfo.Handle == Handle; });
- if (pInfo != m_xInfo->end())
+ if (pInfo != std::cend(*m_xInfo))
return *pInfo;
throw ucb::UnsupportedCommandException();
@@ -269,7 +269,7 @@ CommandProcessorInfo::getCommandInfoByHandle( sal_Int32 Handle )
sal_Bool SAL_CALL CommandProcessorInfo::hasCommandByName(
const OUString& Name )
{
- return std::any_of(m_xInfo->begin(), m_xInfo->end(),
+ return std::any_of(std::cbegin(*m_xInfo), std::cend(*m_xInfo),
[&Name](const ucb::CommandInfo& rInfo) { return rInfo.Name == Name; });
}
@@ -277,7 +277,7 @@ sal_Bool SAL_CALL CommandProcessorInfo::hasCommandByName(
// virtual
sal_Bool SAL_CALL CommandProcessorInfo::hasCommandByHandle( sal_Int32 Handle )
{
- return std::any_of(m_xInfo->begin(), m_xInfo->end(),
+ return std::any_of(std::cbegin(*m_xInfo), std::cend(*m_xInfo),
[&Handle](const ucb::CommandInfo& rInfo) { return rInfo.Handle == Handle; });
}
@@ -604,9 +604,9 @@ uno::Reference< ucb::XContent > createNew(
}
uno::Reference< ucb::XContent > xNew;
- auto pTypeInfo = std::find_if(aTypesInfo.begin(), aTypesInfo.end(),
+ auto pTypeInfo = std::find_if(std::cbegin(aTypesInfo), std::cend(aTypesInfo),
[&lCompare](const ucb::ContentInfo& rTypeInfo) { return lCompare(rTypeInfo.Attributes); });
- if (pTypeInfo != aTypesInfo.end())
+ if (pTypeInfo != std::cend(aTypesInfo))
{
// (3) Create a new, empty object of matched type.
diff --git a/ucb/source/core/ucbprops.cxx b/ucb/source/core/ucbprops.cxx
index 604b8983bc42..1260e406c1e1 100644
--- a/ucb/source/core/ucbprops.cxx
+++ b/ucb/source/core/ucbprops.cxx
@@ -254,9 +254,9 @@ sal_Bool SAL_CALL UcbPropertiesManager::hasPropertyByName( const OUString& Name
bool UcbPropertiesManager::queryProperty(
const OUString& rName, Property& rProp )
{
- auto pProp = std::find_if(m_pProps.begin(), m_pProps.end(),
+ auto pProp = std::find_if(std::cbegin(m_pProps), std::cend(m_pProps),
[&rName](const Property& rCurrProp) { return rCurrProp.Name == rName; });
- if (pProp != m_pProps.end())
+ if (pProp != std::cend(m_pProps))
{
rProp = *pProp;
return true;
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