summaryrefslogtreecommitdiff
path: root/stoc
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 /stoc
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 'stoc')
-rw-r--r--stoc/source/implementationregistration/implreg.cxx21
-rw-r--r--stoc/source/inspect/introspection.cxx4
-rw-r--r--stoc/source/invocation/invocation.cxx2
-rw-r--r--stoc/source/servicemanager/servicemanager.cxx6
4 files changed, 17 insertions, 16 deletions
diff --git a/stoc/source/implementationregistration/implreg.cxx b/stoc/source/implementationregistration/implreg.cxx
index 90c9d462db71..bfd19ccd07e4 100644
--- a/stoc/source/implementationregistration/implreg.cxx
+++ b/stoc/source/implementationregistration/implreg.cxx
@@ -254,7 +254,7 @@ OUString searchLinkTargetForImpl(const Reference < XRegistryKey >& xRootKey,
if (xKey.is())
{
- Sequence< Reference < XRegistryKey > > subKeys = xKey->openKeys();
+ const Sequence< Reference < XRegistryKey > > subKeys = xKey->openKeys();
OUString qualifiedLinkName( slash_UNO + linkName );
@@ -283,7 +283,7 @@ void createUniqueSubEntry(const Reference < XRegistryKey > & xSuperKey,
if (xSuperKey->getValueType() == RegistryValueType_ASCIILIST)
{
- Sequence<OUString> implEntries = xSuperKey->getAsciiListValue();
+ const Sequence<OUString> implEntries = xSuperKey->getAsciiListValue();
sal_Int32 length = implEntries.getLength();
bool bReady = comphelper::findValue(implEntries, value) != -1;
@@ -320,7 +320,7 @@ bool deleteSubEntry(const Reference < XRegistryKey >& xSuperKey, const OUString&
{
if (xSuperKey->getValueType() == RegistryValueType_ASCIILIST)
{
- Sequence<OUString> implEntries = xSuperKey->getAsciiListValue();
+ const Sequence<OUString> implEntries = xSuperKey->getAsciiListValue();
sal_Int32 length = implEntries.getLength();
sal_Int32 equals = static_cast<sal_Int32>(std::count(implEntries.begin(), implEntries.end(), value));
bool hasNoImplementations = false;
@@ -423,7 +423,7 @@ void deleteUserLink(const Reference < XRegistryKey >& xRootKey,
{
if (xOldKey->getValueType() == RegistryValueType_ASCIILIST)
{
- Sequence<OUString> implEntries = xOldKey->getAsciiListValue();
+ const Sequence<OUString> implEntries = xOldKey->getAsciiListValue();
sal_Int32 length = implEntries.getLength();
sal_Int32 equals = static_cast<sal_Int32>(std::count(implEntries.begin(), implEntries.end(), implName));
bool hasNoImplementations = false;
@@ -438,20 +438,21 @@ void deleteUserLink(const Reference < XRegistryKey >& xRootKey,
if (length > equals + 1)
{
Sequence<OUString> implEntriesNew(length - equals - 1);
+ auto pNewArray = implEntriesNew.getArray();
sal_Int32 j = 0;
bool first = true;
for (sal_Int32 i = 0; i < length; i++)
{
- if (implEntries.getConstArray()[i] != implName)
+ if (implEntries[i] != implName)
{
if (first)
{
- oldImpl = implEntries.getConstArray()[i];
+ oldImpl = implEntries[i];
first = false;
} else
{
- implEntriesNew.getArray()[j++] = implEntries.getConstArray()[i];
+ pNewArray[j++] = implEntries[i];
}
}
}
@@ -459,7 +460,7 @@ void deleteUserLink(const Reference < XRegistryKey >& xRootKey,
xOldKey->setAsciiListValue(implEntriesNew);
} else
{
- oldImpl = implEntries.getConstArray()[0];
+ oldImpl = implEntries[0];
OUString path(xOldKey->getKeyName());
xOldKey->closeKey();
xRootKey->deleteKey(path);
@@ -727,7 +728,7 @@ void deleteAllServiceEntries( const Reference < XSimpleRegistry >& xReg,
{
if (xServiceKey->getValueType() == RegistryValueType_ASCIILIST)
{
- Sequence<OUString> implEntries = xServiceKey->getAsciiListValue();
+ const Sequence<OUString> implEntries = xServiceKey->getAsciiListValue();
sal_Int32 length = implEntries.getLength();
sal_Int32 equals = static_cast<sal_Int32>(std::count(implEntries.begin(), implEntries.end(), implName));
@@ -779,7 +780,7 @@ bool is_supported_service(
{
if (xService_td->getName() == service_name)
return true;
- Sequence< Reference< reflection::XServiceTypeDescription > > seq(
+ const Sequence< Reference< reflection::XServiceTypeDescription > > seq(
xService_td->getMandatoryServices() );
return std::any_of(seq.begin(), seq.end(), [&service_name](const auto& rService) {
return is_supported_service( service_name, rService ); });
diff --git a/stoc/source/inspect/introspection.cxx b/stoc/source/inspect/introspection.cxx
index d07cb9c906d5..aa1440bb4b7d 100644
--- a/stoc/source/inspect/introspection.cxx
+++ b/stoc/source/inspect/introspection.cxx
@@ -92,7 +92,7 @@ typedef WeakImplHelper< XIntrospectionAccess, XMaterialHolder, XExactName,
// Method to assert, if a class is derived from another class
bool isDerivedFrom( const Reference<XIdlClass>& xToTestClass, const Reference<XIdlClass>& xDerivedFromClass )
{
- Sequence< Reference<XIdlClass> > aClassesSeq = xToTestClass->getSuperclasses();
+ const Sequence< Reference<XIdlClass> > aClassesSeq = xToTestClass->getSuperclasses();
return std::any_of(aClassesSeq.begin(), aClassesSeq.end(),
[&xDerivedFromClass](const Reference<XIdlClass>& rxClass) {
@@ -2275,7 +2275,7 @@ css::uno::Reference<css::beans::XIntrospectionAccess> Implementation::inspect(
// Option 1: Search for parameters for a listener class
// Disadvantage: Superclasses should be searched recursively
- Sequence< Reference<XIdlClass> > aParams = rxMethod->getParameterTypes();
+ const Sequence< Reference<XIdlClass> > aParams = rxMethod->getParameterTypes();
css::uno::Reference<css::reflection::XIdlClass>
xEventListenerClass(
diff --git a/stoc/source/invocation/invocation.cxx b/stoc/source/invocation/invocation.cxx
index 4874c20750ce..6d4db16effe3 100644
--- a/stoc/source/invocation/invocation.cxx
+++ b/stoc/source/invocation/invocation.cxx
@@ -669,7 +669,7 @@ Any Invocation_Impl::invoke( const OUString& FunctionName, const Sequence<Any>&
OutIndices.realloc( nOutIndex );
OutParams.realloc( nOutIndex );
- std::transform(OutIndices.begin(), OutIndices.end(), OutParams.begin(),
+ std::transform(std::cbegin(OutIndices), std::cend(OutIndices), OutParams.begin(),
[&pInvokeParams](const sal_Int16 nIndex) -> Any { return pInvokeParams[nIndex]; });
return aRet;
diff --git a/stoc/source/servicemanager/servicemanager.cxx b/stoc/source/servicemanager/servicemanager.cxx
index e38b9db609ae..3e50aed3953a 100644
--- a/stoc/source/servicemanager/servicemanager.cxx
+++ b/stoc/source/servicemanager/servicemanager.cxx
@@ -81,7 +81,7 @@ Sequence< OUString > retrieveAsciiValueList(
xEnum->nextElement() >>= xTempReg;
if( xTempReg.is() )
{
- Sequence< OUString > seq2 = retrieveAsciiValueList( xTempReg, keyName );
+ const Sequence< OUString > seq2 = retrieveAsciiValueList( xTempReg, keyName );
if( seq2.hasElements() )
{
@@ -194,7 +194,7 @@ beans::Property PropertySetInfo_Impl::getPropertyByName( OUString const & name )
sal_Bool PropertySetInfo_Impl::hasPropertyByName( OUString const & name )
{
- return std::any_of(m_properties.begin(), m_properties.end(),
+ return std::any_of(std::cbegin(m_properties), std::cend(m_properties),
[&name](const beans::Property& rProp) { return rProp.Name == name; });
}
@@ -1327,7 +1327,7 @@ void ORegistryServiceManager::fillAllNamesFromRegistry( HashSet_OWString & rSet
if( xServicesKey.is() )
{
sal_Int32 nPrefix = xServicesKey->getKeyName().getLength() +1;
- Sequence<Reference<XRegistryKey > > aKeys = xServicesKey->openKeys();
+ const Sequence<Reference<XRegistryKey > > aKeys = xServicesKey->openKeys();
std::transform(aKeys.begin(), aKeys.end(), std::inserter(rSet, rSet.end()),
[nPrefix](const Reference<XRegistryKey>& rKey) -> OUString {
return rKey->getKeyName().copy( nPrefix ); });