From 6ffdc88e79904882e319bdd0b901e7491abae0b3 Mon Sep 17 00:00:00 2001 From: Arkadiy Illarionov Date: Sat, 20 Jul 2019 20:03:15 +0300 Subject: 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 --- stoc/source/implementationregistration/implreg.cxx | 215 ++++++--------------- 1 file changed, 58 insertions(+), 157 deletions(-) (limited to 'stoc/source/implementationregistration/implreg.cxx') 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& 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 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 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 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 implEntries = xSuperKey->getAsciiListValue(); sal_Int32 length = implEntries.getLength(); - sal_Int32 equals = 0; + sal_Int32 equals = static_cast(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 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 implEntries = xOldKey->getAsciiListValue(); sal_Int32 length = implEntries.getLength(); - sal_Int32 equals = 0; + sal_Int32 equals = static_cast(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 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(std::count(implEntries.begin(), implEntries.end(), implName)); if (equals == length) { @@ -797,14 +738,8 @@ void deleteAllServiceEntries( const Reference < XSimpleRegistry >& xReg, { Sequence 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 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&) -- cgit gs'>feature/gtk3nativedialogs LibreOffice 核心代码仓库文档基金会
summaryrefslogtreecommitdiff
AgeCommit message (Expand)Author
2013-10-28gbuild: set Package default target to INSTDIRMichael Stahl
2013-09-23Try to fix cross-compilationTor Lillqvist
2013-09-11Towards a working instdir for Mac OS XStephan Bergmann
2013-08-18Further work on the "Mac-like app structure" optionTor Lillqvist
2013-04-30install example java scripts using filelistDavid Tardon