From 5ba84c3c7080d55d86b8b39db077b6da36cb700a Mon Sep 17 00:00:00 2001 From: Arkadiy Illarionov Date: Sat, 27 Jul 2019 23:20:29 +0300 Subject: Simplify Sequence iterations in scaddins, sccomp, scripting Use range-based loops, STL and comphelper functions Change-Id: I836422a1c81a3dc9585687ed2e506eb59bb4ec91 Reviewed-on: https://gerrit.libreoffice.org/76484 Tested-by: Jenkins Reviewed-by: Arkadiy Illarionov --- .../source/provider/BrowseNodeFactoryImpl.cxx | 25 ++++++++------------ scripting/source/provider/ProviderCache.cxx | 27 ++++++++++++++-------- scripting/source/provider/ProviderCache.hxx | 14 ++--------- scripting/source/provider/URIHelper.cxx | 26 ++++++++++----------- 4 files changed, 41 insertions(+), 51 deletions(-) (limited to 'scripting/source/provider') diff --git a/scripting/source/provider/BrowseNodeFactoryImpl.cxx b/scripting/source/provider/BrowseNodeFactoryImpl.cxx index 909443f5f511..c7a7829d900f 100644 --- a/scripting/source/provider/BrowseNodeFactoryImpl.cxx +++ b/scripting/source/provider/BrowseNodeFactoryImpl.cxx @@ -109,10 +109,8 @@ public: sal_Int32 index = 0; for ( Sequence< Reference < browse::XBrowseNode > >& children : seqs ) { - for ( sal_Int32 j = 0; j < children.getLength(); j++ ) - { - result[ index++ ] = children[ j ]; - } + std::copy(children.begin(), children.end(), std::next(result.begin(), index)); + index += children.getLength(); if (index >= numChildren) break; @@ -220,25 +218,23 @@ private: Sequence< Reference< browse::XBrowseNode > > langNodes = m_origNode->getChildNodes(); - for ( sal_Int32 i = 0; i < langNodes.getLength(); i++ ) + for ( const auto& rLangNode : langNodes ) { Reference< browse::XBrowseNode > xbn; - if ( langNodes[ i ]->getName() == "uno_packages" ) + if ( rLangNode->getName() == "uno_packages" ) { - xbn.set( new LocationBrowseNode( langNodes[ i ] ) ); + xbn.set( new LocationBrowseNode( rLangNode ) ); } else { - xbn.set( langNodes[ i ] ); + xbn.set( rLangNode ); } Sequence< Reference< browse::XBrowseNode > > grandchildren = xbn->getChildNodes(); - for ( sal_Int32 j = 0; j < grandchildren.getLength(); j++ ) + for ( const Reference< browse::XBrowseNode >& grandchild : grandchildren ) { - Reference< browse::XBrowseNode > grandchild(grandchildren[j]); - auto h_it = m_hBNA->find( grandchild->getName() ); @@ -289,11 +285,11 @@ std::vector< Reference< browse::XBrowseNode > > getAllBrowseNodes( const Referen return locnBNs; } - for ( sal_Int32 i = 0; i < openDocs.getLength(); i++ ) + for ( const auto& rDoc : openDocs ) { try { - Reference< frame::XModel > model( MiscUtils::tDocUrlToModel( openDocs[ i ] ), UNO_SET_THROW ); + Reference< frame::XModel > model( MiscUtils::tDocUrlToModel( rDoc ), UNO_SET_THROW ); // #i44599 Check if it's a real document or something special like Hidden/Preview css::uno::Reference< css::frame::XController > xCurrentController = model->getCurrentController(); @@ -401,9 +397,8 @@ public: vXBrowseNodes aVNodes; Sequence < Reference< browse::XBrowseNode > > nodes = m_xWrappedBrowseNode->getChildNodes(); - for ( sal_Int32 i=0; i& xBrowseNode : nodes ) { - Reference< browse::XBrowseNode > xBrowseNode = nodes[ i ]; OSL_ENSURE( xBrowseNode.is(), "DefaultBrowseNode::getChildNodes(): Invalid BrowseNode" ); if( xBrowseNode.is() ) aVNodes.push_back( new DefaultBrowseNode( m_xCtx, xBrowseNode ) ); diff --git a/scripting/source/provider/ProviderCache.cxx b/scripting/source/provider/ProviderCache.cxx index cf54ea0aee22..e97be35acb6f 100644 --- a/scripting/source/provider/ProviderCache.cxx +++ b/scripting/source/provider/ProviderCache.cxx @@ -17,6 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include #include #include #include @@ -150,17 +151,17 @@ ProviderCache::populateCache() if ( serviceNames.hasElements() ) { - for ( sal_Int32 index = 0; index < serviceNames.getLength(); index++ ) + auto pName = std::find_if(serviceNames.begin(), serviceNames.end(), + [this](const OUString& rName) { + return rName.startsWith("com.sun.star.script.provider.ScriptProviderFor") + && !isInBlackList(rName); + }); + if (pName != serviceNames.end()) { - if ( serviceNames[ index ].startsWith( "com.sun.star.script.provider.ScriptProviderFor" ) - && !isInBlackList( serviceNames[ index ] ) ) - { - serviceName = serviceNames[ index ]; - ProviderDetails details; - details.factory = factory; - m_hProviderDetailsCache[ serviceName ] = details; - break; - } + serviceName = *pName; + ProviderDetails details; + details.factory = factory; + m_hProviderDetailsCache[ serviceName ] = details; } } } @@ -193,6 +194,12 @@ ProviderCache::createProvider( ProviderDetails& details ) return details.provider; } + +bool +ProviderCache::isInBlackList( const OUString& serviceName ) +{ + return comphelper::findValue(m_sBlackList, serviceName) != -1; +} } //end namespace /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/scripting/source/provider/ProviderCache.hxx b/scripting/source/provider/ProviderCache.hxx index bd13ec9545da..3ad9bc5fab1a 100644 --- a/scripting/source/provider/ProviderCache.hxx +++ b/scripting/source/provider/ProviderCache.hxx @@ -67,19 +67,9 @@ private: void populateCache(); /// @throws css::uno::RuntimeException - css::uno::Reference< css::script::provider::XScriptProvider > + css::uno::Reference< css::script::provider::XScriptProvider > createProvider( ProviderDetails& details ); - bool isInBlackList( const OUString& serviceName ) - { - for ( sal_Int32 index = 0; index < m_sBlackList.getLength(); index++ ) - { - if ( m_sBlackList[ index ] == serviceName ) - { - return true; - } - } - return false; - } + bool isInBlackList( const OUString& serviceName ); css::uno::Sequence< OUString > m_sBlackList; ProviderDetails_hash m_hProviderDetailsCache; osl::Mutex m_mutex; diff --git a/scripting/source/provider/URIHelper.cxx b/scripting/source/provider/URIHelper.cxx index 172f0ac0ae66..650d019d1779 100644 --- a/scripting/source/provider/URIHelper.cxx +++ b/scripting/source/provider/URIHelper.cxx @@ -144,23 +144,21 @@ ScriptingFrameworkURIHelper::initBaseURI() uno::Sequence< OUString > children = m_xSimpleFileAccess->getFolderContents( uri, true ); - for ( sal_Int32 i = 0; i < children.getLength(); i++ ) - { - OUString child = children[i]; + auto pChild = std::find_if(children.begin(), children.end(), [&test](const OUString& child) { sal_Int32 idx = child.lastIndexOf(test); - - if ( idx != -1 && (idx + test.getLength()) == child.getLength() ) + return idx != -1 && (idx + test.getLength()) == child.getLength(); + }); + if (pChild != children.end()) + { + if ( bAppendScriptsPart ) { - if ( bAppendScriptsPart ) - { - m_sBaseURI = child.concat( SCRIPTS_PART ); - } - else - { - m_sBaseURI = child; - } - return true; + m_sBaseURI = pChild->concat( SCRIPTS_PART ); } + else + { + m_sBaseURI = *pChild; + } + return true; } return false; } -- cgit v1.2.3