summaryrefslogtreecommitdiff
path: root/stoc
diff options
context:
space:
mode:
authorArkadiy Illarionov <qarkai@gmail.com>2019-07-20 20:03:15 +0300
committerArkadiy Illarionov <qarkai@gmail.com>2019-07-22 18:42:35 +0200
commit6ffdc88e79904882e319bdd0b901e7491abae0b3 (patch)
tree5cb0257a03987f962668655af536a05ad72f8882 /stoc
parent803a6ccb774ff6dc67ca697459d6679e4bc9604f (diff)
Simplify Sequence iterations in shell..svgio
Use range-based loops, STL and comphelper functions Change-Id: I612d36abcc09a91c60f7212de6747a1a1bdcfc69 Reviewed-on: https://gerrit.libreoffice.org/76056 Tested-by: Jenkins Reviewed-by: Arkadiy Illarionov <qarkai@gmail.com>
Diffstat (limited to 'stoc')
-rw-r--r--stoc/Library_bootstrap.mk1
-rw-r--r--stoc/source/corereflection/criface.cxx8
-rw-r--r--stoc/source/defaultregistry/defaultregistry.cxx96
-rw-r--r--stoc/source/implementationregistration/implreg.cxx215
-rw-r--r--stoc/source/inspect/introspection.cxx55
-rw-r--r--stoc/source/invocation/invocation.cxx8
-rw-r--r--stoc/source/servicemanager/servicemanager.cxx50
-rw-r--r--stoc/source/simpleregistry/simpleregistry.cxx18
8 files changed, 116 insertions, 335 deletions
diff --git a/stoc/Library_bootstrap.mk b/stoc/Library_bootstrap.mk
index b31359663de6..49fbafc12a09 100644
--- a/stoc/Library_bootstrap.mk
+++ b/stoc/Library_bootstrap.mk
@@ -26,6 +26,7 @@ $(eval $(call gb_Library_use_internal_bootstrap_api,bootstrap,\
))
$(eval $(call gb_Library_use_libraries,bootstrap,\
+ comphelper \
cppu \
cppuhelper \
reg \
diff --git a/stoc/source/corereflection/criface.cxx b/stoc/source/corereflection/criface.cxx
index 5c4bd80af019..d71fc12a8dbc 100644
--- a/stoc/source/corereflection/criface.cxx
+++ b/stoc/source/corereflection/criface.cxx
@@ -790,11 +790,9 @@ sal_Bool InterfaceIdlClassImpl::isAssignableFrom( const Reference< XIdlClass > &
else
{
const Sequence< Reference< XIdlClass > > & rSeq = xType->getSuperclasses();
- for (sal_Int32 i = 0; i < rSeq.getLength(); ++i) {
- if (isAssignableFrom(rSeq[i])) {
- return true;
- }
- }
+ if (std::any_of(rSeq.begin(), rSeq.end(),
+ [this](const Reference<XIdlClass>& rType){ return isAssignableFrom(rType); }))
+ return true;
}
}
return false;
diff --git a/stoc/source/defaultregistry/defaultregistry.cxx b/stoc/source/defaultregistry/defaultregistry.cxx
index 4e6aa42c6480..afa4d2ad6aa6 100644
--- a/stoc/source/defaultregistry/defaultregistry.cxx
+++ b/stoc/source/defaultregistry/defaultregistry.cxx
@@ -18,6 +18,7 @@
*/
#include <osl/mutex.hxx>
+#include <comphelper/sequence.hxx>
#include <cppuhelper/weak.hxx>
#include <cppuhelper/implbase.hxx>
#include <cppuhelper/implbase4.hxx>
@@ -756,54 +757,27 @@ Sequence< Reference< XRegistryKey > > SAL_CALL NestedKeyImpl::openKeys( )
sal_uInt32 local = localSeq.getLength();
sal_uInt32 def = defaultSeq.getLength();
- sal_uInt32 len = 0;
-
- sal_uInt32 i, j;
- for (i=0; i < local; i++)
- {
- for (j=0 ; j < def; j++)
- {
- if ( localSeq.getConstArray()[i] == defaultSeq.getConstArray()[j] )
- {
- len++;
- break;
- }
- }
- }
+ sal_uInt32 len = static_cast<sal_uInt32>(std::count_if(localSeq.begin(), localSeq.end(),
+ [&defaultSeq](const OUString& rLocal) { return comphelper::findValue(defaultSeq, rLocal) != -1; }));
Sequence< Reference<XRegistryKey> > retSeq(local + def - len);
- OUString name;
- sal_Int32 lastIndex;
- for (i=0; i < local; i++)
- {
- name = localSeq.getConstArray()[i];
- lastIndex = name.lastIndexOf('/');
- name = name.copy(lastIndex);
- retSeq.getArray()[i] = new NestedKeyImpl(name, this);
- }
+ auto lKeyNameToRegKey = [this](const OUString& rName) -> Reference<XRegistryKey> {
+ sal_Int32 lastIndex = rName.lastIndexOf('/');
+ OUString name = rName.copy(lastIndex);
+ return new NestedKeyImpl(name, this);
+ };
+ std::transform(localSeq.begin(), localSeq.end(), retSeq.begin(), lKeyNameToRegKey);
sal_uInt32 k = local;
- for (i=0; i < def; i++)
+ for (const auto& rDef : defaultSeq)
{
- bool insert = true;
-
- for (j=0 ; j < local; j++)
- {
- if ( retSeq.getConstArray()[j]->getKeyName()
- == defaultSeq.getConstArray()[i] )
- {
- insert = false;
- break;
- }
- }
+ bool insert = std::none_of(retSeq.begin(), std::next(retSeq.begin(), local),
+ [&rDef](const Reference<XRegistryKey>& rKey) { return rKey->getKeyName() == rDef; });
if ( insert )
{
- name = defaultSeq.getConstArray()[i];
- lastIndex = name.lastIndexOf('/');
- name = name.copy(lastIndex);
- retSeq.getArray()[k++] = new NestedKeyImpl(name, this);
+ retSeq.getArray()[k++] = lKeyNameToRegKey(rDef);
}
}
@@ -830,49 +804,7 @@ Sequence< OUString > SAL_CALL NestedKeyImpl::getKeyNames( )
defaultSeq = m_defaultKey->getKeyNames();
}
- sal_uInt32 local = localSeq.getLength();
- sal_uInt32 def = defaultSeq.getLength();
- sal_uInt32 len = 0;
-
- sal_uInt32 i, j;
- for (i=0; i < local; i++)
- {
- for (j=0 ; j < def; j++)
- {
- if ( localSeq.getConstArray()[i] == defaultSeq.getConstArray()[j] )
- {
- len++;
- break;
- }
- }
- }
-
- Sequence<OUString> retSeq(local + def - len);
-
- for (i=0; i < local; i++)
- {
- retSeq.getArray()[i] = localSeq.getConstArray()[i];
- }
-
- sal_uInt32 k = local;
- for (i=0; i < def; i++)
- {
- bool insert = true;
-
- for (j=0 ; j < local; j++)
- {
- if ( retSeq.getConstArray()[j] == defaultSeq.getConstArray()[i] )
- {
- insert = false;
- break;
- }
- }
-
- if ( insert )
- retSeq.getArray()[k++] = defaultSeq.getConstArray()[i];
- }
-
- return retSeq;
+ return comphelper::combineSequences(localSeq, defaultSeq);
}
diff --git a/stoc/source/implementationregistration/implreg.cxx b/stoc/source/implementationregistration/implreg.cxx
index 45c8f033f0db..5923e44a91c6 100644
--- a/stoc/source/implementationregistration/implreg.cxx
+++ b/stoc/source/implementationregistration/implreg.cxx
@@ -96,8 +96,6 @@ void deleteAllLinkReferences(const Reference < XSimpleRegistry >& xReg,
if (!linkNames.hasElements())
return;
- const OUString* pLinkNames = linkNames.getConstArray();
-
OUString aLinkName;
OUString aLinkParent;
Reference < XRegistryKey > xLinkParent;
@@ -105,9 +103,9 @@ void deleteAllLinkReferences(const Reference < XSimpleRegistry >& xReg,
const sal_Unicode* pShortName = nullptr;
sal_Int32 sEnd = 0;
- for (sal_Int32 i = 0; i < linkNames.getLength(); i++)
+ for (const OUString& rLinkName : linkNames)
{
- aLinkName = pLinkNames[i];
+ aLinkName = rLinkName;
pTmpName = aLinkName.getStr();
@@ -219,14 +217,12 @@ OUString searchImplForLink(
if (xKey.is())
{
Sequence< Reference < XRegistryKey > > subKeys( xKey->openKeys() );
- const Reference < XRegistryKey > * pSubKeys = subKeys.getConstArray();
OUString key_name( slash_UNO + linkName );
- for (sal_Int32 i = 0; i < subKeys.getLength(); i++)
+ for (const Reference < XRegistryKey >& xImplKey : subKeys)
{
try
{
- Reference < XRegistryKey > xImplKey( pSubKeys[i] );
if (xImplKey->getKeyType( key_name ) == RegistryKeyType_LINK)
{
OUString oldImplName = xImplKey->getKeyName().copy(strlen("/IMPLEMENTATIONS/"));
@@ -252,31 +248,25 @@ OUString searchLinkTargetForImpl(const Reference < XRegistryKey >& xRootKey,
const OUString& linkName,
const OUString& implName)
{
- Reference < XRegistryKey > xKey = xRootKey->openKey( slash_IMPLEMENTATIONS );
-
- if (xKey.is())
- {
- Sequence< Reference < XRegistryKey > > subKeys = xKey->openKeys();
-
- const Reference < XRegistryKey >* pSubKeys = subKeys.getConstArray();
- Reference < XRegistryKey > xImplKey;
-
- for (sal_Int32 i = 0; i < subKeys.getLength(); i++)
- {
- xImplKey = pSubKeys[i];
+ Reference < XRegistryKey > xKey = xRootKey->openKey( slash_IMPLEMENTATIONS );
- OUString tmpImplName = xImplKey->getKeyName().copy(strlen("/IMPLEMENTATIONS/"));
- OUString qualifiedLinkName( slash_UNO );
- qualifiedLinkName += linkName;
- if (tmpImplName == implName &&
- xImplKey->getKeyType( qualifiedLinkName ) == RegistryKeyType_LINK)
- {
- return xImplKey->getLinkTarget( qualifiedLinkName );
- }
- }
- }
+ if (xKey.is())
+ {
+ Sequence< Reference < XRegistryKey > > subKeys = xKey->openKeys();
+
+ OUString qualifiedLinkName( slash_UNO + linkName );
+
+ auto pSubKey = std::find_if(subKeys.begin(), subKeys.end(),
+ [&implName, &qualifiedLinkName](const Reference<XRegistryKey>& rSubKey) {
+ OUString tmpImplName = rSubKey->getKeyName().copy(strlen("/IMPLEMENTATIONS/"));
+ return tmpImplName == implName
+ && rSubKey->getKeyType( qualifiedLinkName ) == RegistryKeyType_LINK;
+ });
+ if (pSubKey != subKeys.end())
+ return (*pSubKey)->getLinkTarget( qualifiedLinkName );
+ }
- return OUString();
+ return OUString();
}
@@ -291,37 +281,25 @@ void createUniqueSubEntry(const Reference < XRegistryKey > & xSuperKey,
if (xSuperKey->getValueType() == RegistryValueType_ASCIILIST)
{
- sal_Int32 length = 0;
- bool bReady = false;
-
Sequence<OUString> implEntries = xSuperKey->getAsciiListValue();
- length = implEntries.getLength();
+ sal_Int32 length = implEntries.getLength();
- for (sal_Int32 i = 0; !bReady && (i < length); i++)
- {
- bReady = (implEntries.getConstArray()[i] == value);
- }
+ bool bReady = comphelper::findValue(implEntries, value) != -1;
if (bReady)
{
Sequence<OUString> implEntriesNew(length);
implEntriesNew.getArray()[0] = value;
- for (sal_Int32 i=0, j=1; i < length; i++)
- {
- if (implEntries.getConstArray()[i] != value)
- implEntriesNew.getArray()[j++] = implEntries.getConstArray()[i];
- }
+ std::copy_if(implEntries.begin(), implEntries.end(), std::next(implEntriesNew.begin()),
+ [&value](const OUString& rEntry) { return rEntry != value; });
xSuperKey->setAsciiListValue(implEntriesNew);
} else
{
Sequence<OUString> implEntriesNew(length+1);
implEntriesNew.getArray()[0] = value;
- for (sal_Int32 i = 0; i < length; i++)
- {
- implEntriesNew.getArray()[i+1] = implEntries.getConstArray()[i];
- }
+ std::copy(implEntries.begin(), implEntries.end(), std::next(implEntriesNew.begin()));
xSuperKey->setAsciiListValue(implEntriesNew);
}
} else
@@ -342,15 +320,9 @@ bool deleteSubEntry(const Reference < XRegistryKey >& xSuperKey, const OUString&
{
Sequence<OUString> implEntries = xSuperKey->getAsciiListValue();
sal_Int32 length = implEntries.getLength();
- sal_Int32 equals = 0;
+ sal_Int32 equals = static_cast<sal_Int32>(std::count(implEntries.begin(), implEntries.end(), value));
bool hasNoImplementations = false;
- for (sal_Int32 i = 0; i < length; i++)
- {
- if (implEntries.getConstArray()[i] == value)
- equals++;
- }
-
if (equals == length)
{
hasNoImplementations = true;
@@ -358,14 +330,8 @@ bool deleteSubEntry(const Reference < XRegistryKey >& xSuperKey, const OUString&
{
Sequence<OUString> implEntriesNew(length - equals);
- sal_Int32 j = 0;
- for (sal_Int32 i = 0; i < length; i++)
- {
- if (implEntries.getConstArray()[i] != value)
- {
- implEntriesNew.getArray()[j++] = implEntries.getConstArray()[i];
- }
- }
+ std::copy_if(implEntries.begin(), implEntries.end(), implEntriesNew.begin(),
+ [&value](const OUString& rEntry) { return rEntry != value; });
xSuperKey->setAsciiListValue(implEntriesNew);
}
@@ -457,15 +423,9 @@ void deleteUserLink(const Reference < XRegistryKey >& xRootKey,
{
Sequence<OUString> implEntries = xOldKey->getAsciiListValue();
sal_Int32 length = implEntries.getLength();
- sal_Int32 equals = 0;
+ sal_Int32 equals = static_cast<sal_Int32>(std::count(implEntries.begin(), implEntries.end(), implName));
bool hasNoImplementations = false;
- for (sal_Int32 i = 0; i < length; i++)
- {
- if (implEntries.getConstArray()[i] == implName)
- equals++;
- }
-
if (equals == length)
{
hasNoImplementations = true;
@@ -571,11 +531,10 @@ void prepareUserKeys(const Reference < XSimpleRegistry >& xDest,
if (subKeys.hasElements())
{
hasSubKeys = true;
- const Reference < XRegistryKey > * pSubKeys = subKeys.getConstArray();
- for (sal_Int32 i = 0; i < subKeys.getLength(); i++)
+ for (const Reference < XRegistryKey > & rSubKey : subKeys)
{
- prepareUserKeys(xDest, xUnoKey, pSubKeys[i], implName, bRegister);
+ prepareUserKeys(xDest, xUnoKey, rSubKey, implName, bRegister);
}
}
}
@@ -620,13 +579,10 @@ void deleteAllImplementations( const Reference < XSimpleRegistry >& xReg,
if (subKeys.hasElements())
{
- const Reference < XRegistryKey> * pSubKeys = subKeys.getConstArray();
- Reference < XRegistryKey > xImplKey;
bool hasLocationUrl = false;
- for (sal_Int32 i = 0; i < subKeys.getLength(); i++)
+ for (const Reference < XRegistryKey> & xImplKey : subKeys)
{
- xImplKey = pSubKeys[i];
Reference < XRegistryKey > xKey = xImplKey->openKey(
slash_UNO_slash_LOCATION );
@@ -651,20 +607,15 @@ void deleteAllImplementations( const Reference < XSimpleRegistry >& xReg,
{
Sequence< Reference < XRegistryKey > > subKeys2 = xKey->openKeys();
- if (subKeys2.hasElements())
+ for (const Reference < XRegistryKey > & rSubKey2 : subKeys2)
{
- const Reference < XRegistryKey > * pSubKeys2 = subKeys2.getConstArray();
-
- for (sal_Int32 j = 0; j < subKeys2.getLength(); j++)
+ if (rSubKey2->getKeyName() != (xImplKey->getKeyName() + slash_UNO_slash_SERVICES ) &&
+ rSubKey2->getKeyName() != (xImplKey->getKeyName() + slash_UNO_slash_REGISTRY_LINKS ) &&
+ rSubKey2->getKeyName() != (xImplKey->getKeyName() + slash_UNO_slash_ACTIVATOR ) &&
+ rSubKey2->getKeyName() != (xImplKey->getKeyName() + slash_UNO_slash_SINGLETONS ) &&
+ rSubKey2->getKeyName() != (xImplKey->getKeyName() + slash_UNO_slash_LOCATION) )
{
- if (pSubKeys2[j]->getKeyName() != (xImplKey->getKeyName() + slash_UNO_slash_SERVICES ) &&
- pSubKeys2[j]->getKeyName() != (xImplKey->getKeyName() + slash_UNO_slash_REGISTRY_LINKS ) &&
- pSubKeys2[j]->getKeyName() != (xImplKey->getKeyName() + slash_UNO_slash_ACTIVATOR ) &&
- pSubKeys2[j]->getKeyName() != (xImplKey->getKeyName() + slash_UNO_slash_SINGLETONS ) &&
- pSubKeys2[j]->getKeyName() != (xImplKey->getKeyName() + slash_UNO_slash_LOCATION) )
- {
- prepareUserKeys(xReg, xKey, pSubKeys2[j], implName, false);
- }
+ prepareUserKeys(xReg, xKey, rSubKey2, implName, false);
}
}
}
@@ -768,25 +719,15 @@ void deleteAllServiceEntries( const Reference < XSimpleRegistry >& xReg,
if (subKeys.hasElements())
{
- const Reference < XRegistryKey > * pSubKeys = subKeys.getConstArray();
- Reference < XRegistryKey > xServiceKey;
bool hasNoImplementations = false;
- for (sal_Int32 i = 0; i < subKeys.getLength(); i++)
+ for (const Reference < XRegistryKey > & xServiceKey : subKeys)
{
- xServiceKey = pSubKeys[i];
-
if (xServiceKey->getValueType() == RegistryValueType_ASCIILIST)
{
Sequence<OUString> implEntries = xServiceKey->getAsciiListValue();
sal_Int32 length = implEntries.getLength();
- sal_Int32 equals = 0;
-
- for (sal_Int32 j = 0; j < length; j++)
- {
- if (implEntries.getConstArray()[j] == implName)
- equals++;
- }
+ sal_Int32 equals = static_cast<sal_Int32>(std::count(implEntries.begin(), implEntries.end(), implName));
if (equals == length)
{
@@ -797,14 +738,8 @@ void deleteAllServiceEntries( const Reference < XSimpleRegistry >& xReg,
{
Sequence<OUString> implEntriesNew(length-equals);
- sal_Int32 j = 0;
- for (sal_Int32 k = 0; k < length; k++)
- {
- if (implEntries.getConstArray()[k] != implName)
- {
- implEntriesNew.getArray()[j++] = implEntries.getConstArray()[k];
- }
- }
+ std::copy_if(implEntries.begin(), implEntries.end(), implEntriesNew.begin(),
+ [&implName](const OUString& rEntry) { return rEntry != implName; });
xServiceKey->setAsciiListValue(implEntriesNew);
}
@@ -844,13 +779,8 @@ bool is_supported_service(
return true;
Sequence< Reference< reflection::XServiceTypeDescription > > seq(
xService_td->getMandatoryServices() );
- Reference< reflection::XServiceTypeDescription > const * p = seq.getConstArray();
- for ( sal_Int32 nPos = seq.getLength(); nPos--; )
- {
- if (is_supported_service( service_name, p[ nPos ] ))
- return true;
- }
- return false;
+ return std::any_of(seq.begin(), seq.end(), [&service_name](const auto& rService) {
+ return is_supported_service( service_name, rService ); });
}
@@ -951,14 +881,7 @@ void insert_singletons(
{
}
// check implname is already in
- sal_Int32 nPos_implnames = implnames.getLength();
- OUString const * pImplnames = implnames.getConstArray();
- while (nPos_implnames--)
- {
- if (implname == pImplnames[ nPos_implnames ])
- break;
- }
- if (nPos_implnames < 0)
+ if (comphelper::findValue(implnames, implname) == -1)
{
// append and write back
implnames.realloc( implnames.getLength() +1 );
@@ -987,13 +910,8 @@ void prepareRegistry(
"prepareRegistry(): source registry is empty" );
}
- const Reference < XRegistryKey >* pSubKeys = subKeys.getConstArray();
- Reference < XRegistryKey > xImplKey;
-
- for (sal_Int32 i = 0; i < subKeys.getLength(); i++)
+ for (const Reference < XRegistryKey >& xImplKey : subKeys)
{
- xImplKey = pSubKeys[i];
-
Reference < XRegistryKey > xKey = xImplKey->openKey(
slash_UNO_slash_SERVICES );
@@ -1001,7 +919,6 @@ void prepareRegistry(
{
// update entries in SERVICES section
Sequence< Reference < XRegistryKey > > serviceKeys = xKey->openKeys();
- const Reference < XRegistryKey > * pServiceKeys = serviceKeys.getConstArray();
OUString implName = xImplKey->getKeyName().copy(1);
sal_Int32 firstDot = implName.indexOf('/');
@@ -1011,9 +928,9 @@ void prepareRegistry(
sal_Int32 offset = xKey->getKeyName().getLength() + 1;
- for (sal_Int32 j = 0; j < serviceKeys.getLength(); j++)
+ for (const Reference < XRegistryKey >& rServiceKey : serviceKeys)
{
- OUString serviceName = pServiceKeys[j]->getKeyName().copy(offset);
+ OUString serviceName = rServiceKey->getKeyName().copy(offset);
createUniqueSubEntry(
xDest->getRootKey()->createKey(
@@ -1026,18 +943,13 @@ void prepareRegistry(
{
Sequence< Reference < XRegistryKey > > subKeys2 = xKey->openKeys();
- if (subKeys2.hasElements())
+ for (const Reference < XRegistryKey >& rSubKey2 : subKeys2)
{
- const Reference < XRegistryKey > * pSubKeys2 = subKeys2.getConstArray();
-
- for (sal_Int32 j = 0; j < subKeys2.getLength(); j++)
+ if (rSubKey2->getKeyName() != (xImplKey->getKeyName() + slash_UNO_slash_SERVICES) &&
+ rSubKey2->getKeyName() != (xImplKey->getKeyName() + slash_UNO_slash_REGISTRY_LINKS ) &&
+ rSubKey2->getKeyName() != (xImplKey->getKeyName() + slash_UNO_slash_SINGLETONS ))
{
- if (pSubKeys2[j]->getKeyName() != (xImplKey->getKeyName() + slash_UNO_slash_SERVICES) &&
- pSubKeys2[j]->getKeyName() != (xImplKey->getKeyName() + slash_UNO_slash_REGISTRY_LINKS ) &&
- pSubKeys2[j]->getKeyName() != (xImplKey->getKeyName() + slash_UNO_slash_SINGLETONS ))
- {
- prepareUserKeys(xDest, xKey, pSubKeys2[j], implName, true);
- }
+ prepareUserKeys(xDest, xKey, rSubKey2, implName, true);
}
}
}
@@ -1066,14 +978,9 @@ void prepareRegistry(
// update link entries in REGISTRY_LINKS section
Sequence<OUString> linkNames = xKey->getAsciiListValue();
- if (linkNames.hasElements())
+ for (const OUString& rLinkName : linkNames)
{
- const OUString* pLinkNames = linkNames.getConstArray();
-
- for (sal_Int32 j = 0; j < linkNames.getLength(); j++)
- {
- prepareLink(xDest, xImplKey, pLinkNames[j]);
- }
+ prepareLink(xDest, xImplKey, rLinkName);
}
}
@@ -1115,15 +1022,9 @@ void findImplementations( const Reference < XRegistryKey > & xSource,
{
Sequence< Reference < XRegistryKey > > subKeys = xSource->openKeys();
- if (subKeys.hasElements())
+ for (const Reference < XRegistryKey >& rSubKey : subKeys)
{
- const Reference < XRegistryKey >* pSubKeys = subKeys.getConstArray();
-
- for (sal_Int32 i = 0; i < subKeys.getLength(); i++)
- {
- findImplementations(pSubKeys[i], implNames);
- }
-
+ findImplementations(rSubKey, implNames);
}
}
catch(InvalidRegistryException&)
diff --git a/stoc/source/inspect/introspection.cxx b/stoc/source/inspect/introspection.cxx
index 79df9d25a542..474952f7cdd5 100644
--- a/stoc/source/inspect/introspection.cxx
+++ b/stoc/source/inspect/introspection.cxx
@@ -93,20 +93,12 @@ typedef WeakImplHelper< XIntrospectionAccess, XMaterialHolder, XExactName,
bool isDerivedFrom( const Reference<XIdlClass>& xToTestClass, const Reference<XIdlClass>& xDerivedFromClass )
{
Sequence< Reference<XIdlClass> > aClassesSeq = xToTestClass->getSuperclasses();
- const Reference<XIdlClass>* pClassesArray = aClassesSeq.getConstArray();
- sal_Int32 nSuperClassCount = aClassesSeq.getLength();
- for ( sal_Int32 i = 0; i < nSuperClassCount; ++i )
- {
- const Reference<XIdlClass>& rxClass = pClassesArray[i];
-
- if ( xDerivedFromClass->equals( rxClass ) ||
- isDerivedFrom( rxClass, xDerivedFromClass )
- )
- return true;
- }
-
- return false;
+ return std::any_of(aClassesSeq.begin(), aClassesSeq.end(),
+ [&xDerivedFromClass](const Reference<XIdlClass>& rxClass) {
+ return xDerivedFromClass->equals( rxClass )
+ || isDerivedFrom( rxClass, xDerivedFromClass );
+ });
}
@@ -1761,13 +1753,9 @@ css::uno::Reference<css::beans::XIntrospectionAccess> Implementation::inspect(
aClassSeq.realloc( nIfaceCount + 1 );
aClassSeq.getArray()[ nIfaceCount ] = xImplClass2;
- nIfaceCount++;
- const Reference<XIdlClass>* pParamArray = aClassSeq.getConstArray();
-
- for( sal_Int32 j = 0 ; j < nIfaceCount ; j++ )
+ for( const Reference<XIdlClass>& rxIfaceClass : aClassSeq )
{
- const Reference<XIdlClass>& rxIfaceClass = pParamArray[j];
if (!seen.insert(rxIfaceClass->getName()).second) {
continue;
}
@@ -1776,12 +1764,9 @@ css::uno::Reference<css::beans::XIntrospectionAccess> Implementation::inspect(
// Get fields
Sequence< Reference<XIdlField> > fields = rxIfaceClass->getFields();
- const Reference<XIdlField>* pFields = fields.getConstArray();
- sal_Int32 nLen = fields.getLength();
- for( i = 0 ; i < nLen ; i++ )
+ for( const Reference<XIdlField>& xField : fields )
{
- Reference<XIdlField> xField = pFields[i];
Reference<XIdlClass> xPropType = xField->getType();
// Is the property sequence big enough?
@@ -2291,7 +2276,6 @@ 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 Reference<XIdlClass>* pParamArray2 = aParams.getConstArray();
css::uno::Reference<css::reflection::XIdlClass>
xEventListenerClass(
@@ -2300,19 +2284,15 @@ css::uno::Reference<css::beans::XIntrospectionAccess> Implementation::inspect(
css::lang::XEventListener>::get()
.getTypeName()));
// Old: Reference<XIdlClass> xEventListenerClass = XEventListener_getReflection()->getIdlClass();
- sal_Int32 nParamCount = aParams.getLength();
- sal_Int32 k;
- for( k = 0 ; k < nParamCount ; k++ )
+ auto pParam = std::find_if(aParams.begin(), aParams.end(),
+ [&xEventListenerClass](const Reference<XIdlClass>& rxClass) {
+ // Are we derived from a listener?
+ return rxClass->equals( xEventListenerClass )
+ || isDerivedFrom( rxClass, xEventListenerClass );
+ });
+ if (pParam != aParams.end())
{
- const Reference<XIdlClass>& rxClass = pParamArray2[k];
-
- // Are we derived from a listener?
- if( rxClass->equals( xEventListenerClass ) ||
- isDerivedFrom( rxClass, xEventListenerClass ) )
- {
- xListenerClass = rxClass;
- break;
- }
+ xListenerClass = *pParam;
}
// Option 2: Unload the name of the method
@@ -2376,12 +2356,9 @@ css::uno::Reference<css::beans::XIntrospectionAccess> Implementation::inspect(
// Get fields
Sequence< Reference<XIdlField> > fields = xClassRef->getFields();
- const Reference<XIdlField>* pFields = fields.getConstArray();
- sal_Int32 nLen = fields.getLength();
- for( i = 0 ; i < nLen ; i++ )
+ for( const Reference<XIdlField>& xField : fields )
{
- Reference<XIdlField> xField = pFields[i];
Reference<XIdlClass> xPropType = xField->getType();
OUString aPropName = xField->getName();
diff --git a/stoc/source/invocation/invocation.cxx b/stoc/source/invocation/invocation.cxx
index 8211828f90cf..694ffa2904b8 100644
--- a/stoc/source/invocation/invocation.cxx
+++ b/stoc/source/invocation/invocation.cxx
@@ -680,14 +680,10 @@ Any Invocation_Impl::invoke( const OUString& FunctionName, const Sequence<Any>&
// OUT Params
OutIndices.realloc( nOutIndex );
- pOutIndices = OutIndices.getArray();
OutParams.realloc( nOutIndex );
- Any* pOutParams = OutParams.getArray();
- while (nOutIndex--)
- {
- pOutParams[nOutIndex] = pInvokeParams[ pOutIndices[nOutIndex] ];
- }
+ std::transform(OutIndices.begin(), OutIndices.end(), 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 5f38ec917c71..000c7d0dc900 100644
--- a/stoc/source/servicemanager/servicemanager.cxx
+++ b/stoc/source/servicemanager/servicemanager.cxx
@@ -51,6 +51,7 @@
#include <com/sun/star/container/XContentEnumerationAccess.hpp>
#include <com/sun/star/uno/XComponentContext.hpp>
+#include <iterator>
#include <unordered_map>
#include <unordered_set>
@@ -88,12 +89,7 @@ Sequence< OUString > retrieveAsciiValueList(
sal_Int32 n2Len = seq2.getLength();
seq.realloc( n1Len + n2Len );
- const OUString *pSource = seq2.getConstArray();
- OUString *pTarget = seq.getArray();
- for( int i = 0 ; i < n2Len ; i ++ )
- {
- pTarget[i+n1Len] = pSource[i];
- }
+ std::copy(seq2.begin(), seq2.end(), std::next(seq.begin(), n1Len));
}
}
}
@@ -198,13 +194,8 @@ beans::Property PropertySetInfo_Impl::getPropertyByName( OUString const & name )
sal_Bool PropertySetInfo_Impl::hasPropertyByName( OUString const & name )
{
- beans::Property const * p = m_properties.getConstArray();
- for ( sal_Int32 nPos = m_properties.getLength(); nPos--; )
- {
- if (p[ nPos ].Name == name)
- return true;
- }
- return false;
+ return std::any_of(m_properties.begin(), m_properties.end(),
+ [&name](const beans::Property& rProp) { return rProp.Name == name; });
}
@@ -784,12 +775,10 @@ Reference< XInterface > OServiceManager::createInstanceWithContext(
Sequence< Reference< XInterface > > factories(
queryServiceFactories( rServiceSpecifier, xContext ) );
- Reference< XInterface > const * p = factories.getConstArray();
- for ( sal_Int32 nPos = 0; nPos < factories.getLength(); ++nPos )
+ for ( Reference< XInterface > const & xFactory : factories )
{
try
{
- Reference< XInterface > const & xFactory = p[ nPos ];
if (xFactory.is())
{
Reference< XSingleComponentFactory > xFac( xFactory, UNO_QUERY );
@@ -838,12 +827,10 @@ Reference< XInterface > OServiceManager::createInstanceWithArgumentsAndContext(
Sequence< Reference< XInterface > > factories(
queryServiceFactories( rServiceSpecifier, xContext ) );
- Reference< XInterface > const * p = factories.getConstArray();
- for ( sal_Int32 nPos = 0; nPos < factories.getLength(); ++nPos )
+ for ( Reference< XInterface > const & xFactory : factories )
{
try
{
- Reference< XInterface > const & xFactory = p[ nPos ];
if (xFactory.is())
{
Reference< XSingleComponentFactory > xFac( xFactory, UNO_QUERY );
@@ -1052,11 +1039,10 @@ void OServiceManager::insert( const Any & Element )
//put into the service map
Sequence< OUString > aServiceNames = xInfo->getSupportedServiceNames();
- const OUString * pArray = aServiceNames.getConstArray();
- for( sal_Int32 i = 0; i < aServiceNames.getLength(); i++ )
+ for( const OUString& rServiceName : aServiceNames )
{
m_ServiceMap.emplace(
- pArray[i], *o3tl::doAccess<Reference<XInterface>>(Element) );
+ rServiceName, *o3tl::doAccess<Reference<XInterface>>(Element) );
}
}
}
@@ -1137,11 +1123,10 @@ void OServiceManager::remove( const Any & Element )
return;
Sequence< OUString > aServiceNames = xSF->getSupportedServiceNames();
- const OUString * pArray = aServiceNames.getConstArray();
- for( sal_Int32 i = 0; i < aServiceNames.getLength(); i++ )
+ for( const OUString& rServiceName : aServiceNames )
{
pair<HashMultimap_OWString_Interface::iterator, HashMultimap_OWString_Interface::iterator> p =
- m_ServiceMap.equal_range( pArray[i] );
+ m_ServiceMap.equal_range( rServiceName );
while( p.first != p.second )
{
@@ -1321,10 +1306,9 @@ Reference<XInterface > ORegistryServiceManager::loadWithServiceName(
const OUString& serviceName, Reference< XComponentContext > const & xContext )
{
Sequence<OUString> implEntries = getFromServiceName( serviceName );
- for (sal_Int32 i = 0; i < implEntries.getLength(); i++)
+ for (const auto& rEntry : implEntries)
{
- Reference< XInterface > x(
- loadWithImplementationName( implEntries.getConstArray()[i], xContext ) );
+ Reference< XInterface > x( loadWithImplementationName( rEntry, xContext ) );
if (x.is())
return x;
}
@@ -1349,8 +1333,9 @@ void ORegistryServiceManager::fillAllNamesFromRegistry( HashSet_OWString & rSet
{
sal_Int32 nPrefix = xServicesKey->getKeyName().getLength() +1;
Sequence<Reference<XRegistryKey > > aKeys = xServicesKey->openKeys();
- for( sal_Int32 i = 0; i < aKeys.getLength(); i++ )
- rSet.insert( aKeys.getConstArray()[i]->getKeyName().copy( nPrefix ) );
+ std::transform(aKeys.begin(), aKeys.end(), std::inserter(rSet, rSet.end()),
+ [nPrefix](const Reference<XRegistryKey>& rKey) -> OUString {
+ return rKey->getKeyName().copy( nPrefix ); });
}
}
catch (InvalidRegistryException &)
@@ -1428,11 +1413,8 @@ Reference<XEnumeration > ORegistryServiceManager::createContentEnumeration(
// get all implementation names registered under this service name from the registry
Sequence<OUString> aImpls = getFromServiceName( aServiceName );
// load and insert all factories specified by the registry
- sal_Int32 i;
- OUString aImplName;
- for( i = 0; i < aImpls.getLength(); i++ )
+ for( const OUString& aImplName : aImpls )
{
- aImplName = aImpls.getConstArray()[i];
if ( !haveFactoryWithThisImplementation(aImplName) )
{
loadWithImplementationName( aImplName, m_xContext );
diff --git a/stoc/source/simpleregistry/simpleregistry.cxx b/stoc/source/simpleregistry/simpleregistry.cxx
index 9d2a6a1e9382..ab2251cedc86 100644
--- a/stoc/source/simpleregistry/simpleregistry.cxx
+++ b/stoc/source/simpleregistry/simpleregistry.cxx
@@ -33,6 +33,7 @@
#include <com/sun/star/uno/RuntimeException.hpp>
#include <com/sun/star/uno/XInterface.hpp>
#include <com/sun/star/uno/Sequence.hxx>
+#include <comphelper/sequence.hxx>
#include <cppuhelper/implbase.hxx>
#include <cppuhelper/supportsservice.hxx>
#include <cppuhelper/weak.hxx>
@@ -313,12 +314,7 @@ css::uno::Sequence< sal_Int32 > Key::getLongListValue()
void Key::setLongListValue(css::uno::Sequence< sal_Int32 > const & seqValue)
{
osl::MutexGuard guard(registry_->mutex_);
- std::vector< sal_Int32 > list;
- list.reserve(seqValue.getLength());
- for (sal_Int32 i = 0; i < seqValue.getLength(); ++i)
- {
- list.push_back(seqValue[i]);
- }
+ auto list = comphelper::sequenceToContainer<std::vector<sal_Int32>>(seqValue);
RegError err = key_.setLongListValue(
OUString(), list.data(), static_cast< sal_uInt32 >(list.size()));
if (err != RegError::NO_ERROR) {
@@ -475,9 +471,9 @@ void Key::setAsciiListValue(
{
osl::MutexGuard guard(registry_->mutex_);
std::vector< OString > list;
- for (sal_Int32 i = 0; i < seqValue.getLength(); ++i) {
+ for (const auto& rValue : seqValue) {
OString utf8;
- if (!seqValue[i].convertToString(
+ if (!rValue.convertToString(
&utf8, RTL_TEXTENCODING_UTF8,
(RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR |
RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR)))
@@ -616,10 +612,8 @@ void Key::setStringListValue(
osl::MutexGuard guard(registry_->mutex_);
std::vector< sal_Unicode * > list;
list.reserve(seqValue.getLength());
- for (sal_Int32 i = 0; i < seqValue.getLength(); ++i)
- {
- list.push_back(const_cast< sal_Unicode * >(seqValue[i].getStr()));
- }
+ std::transform(seqValue.begin(), seqValue.end(), std::back_inserter(list),
+ [](const OUString& rValue) -> sal_Unicode* { return const_cast<sal_Unicode*>(rValue.getStr()); });
RegError err = key_.setUnicodeListValue(
OUString(), list.data(), static_cast< sal_uInt32 >(list.size()));
if (err != RegError::NO_ERROR) {