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 --- scaddins/source/analysis/analysis.cxx | 14 ++--- scaddins/source/analysis/analysishelper.cxx | 62 +++++++--------------- sccomp/source/solver/CoinMPSolver.cxx | 17 +++--- sccomp/source/solver/LpsolveSolver.cxx | 25 ++++----- scripting/source/basprov/basmethnode.cxx | 16 ++---- scripting/source/basprov/basprov.cxx | 7 ++- scripting/source/dlgprov/dlgevtatt.cxx | 13 ++--- scripting/source/protocolhandler/scripthandler.cxx | 19 +++---- .../source/provider/BrowseNodeFactoryImpl.cxx | 25 ++++----- scripting/source/provider/ProviderCache.cxx | 27 ++++++---- scripting/source/provider/ProviderCache.hxx | 14 +---- scripting/source/provider/URIHelper.cxx | 26 +++++---- scripting/source/stringresource/stringresource.cxx | 5 +- scripting/source/vbaevents/eventhelper.cxx | 22 +++----- 14 files changed, 107 insertions(+), 185 deletions(-) diff --git a/scaddins/source/analysis/analysis.cxx b/scaddins/source/analysis/analysis.cxx index 3587d859c2d6..ce3c866aba2b 100644 --- a/scaddins/source/analysis/analysis.cxx +++ b/scaddins/source/analysis/analysis.cxx @@ -571,19 +571,11 @@ double SAL_CALL AnalysisAddIn::getSeriessum( double fX, double fN, double fM, co if( fX != 0.0 ) { - sal_Int32 n1, n2; - sal_Int32 nE1 = aCoeffList.getLength(); - sal_Int32 nE2; - - for( n1 = 0 ; n1 < nE1 ; n1++ ) + for( const uno::Sequence< double >& rList : aCoeffList ) { - const uno::Sequence< double >& rList = aCoeffList[ n1 ]; - nE2 = rList.getLength(); - const double* pList = rList.getConstArray(); - - for( n2 = 0 ; n2 < nE2 ; n2++ ) + for( const double fCoef : rList ) { - fRet += pList[ n2 ] * pow( fX, fN ); + fRet += fCoef * pow( fX, fN ); fN += fM; } diff --git a/scaddins/source/analysis/analysishelper.cxx b/scaddins/source/analysis/analysishelper.cxx index c44c55f763db..c608732b14d6 100644 --- a/scaddins/source/analysis/analysishelper.cxx +++ b/scaddins/source/analysis/analysishelper.cxx @@ -1481,14 +1481,10 @@ void SortedIndividualInt32List::InsertHolidayList( if( !(rHolAny >>= aAnySeq) ) throw lang::IllegalArgumentException(); - const uno::Sequence< uno::Any >* pSeqArray = aAnySeq.getConstArray(); - for( sal_Int32 nIndex1 = 0; nIndex1 < aAnySeq.getLength(); nIndex1++ ) + for( const uno::Sequence< uno::Any >& rSubSeq : aAnySeq ) { - const uno::Sequence< uno::Any >& rSubSeq = pSeqArray[ nIndex1 ]; - const uno::Any* pAnyArray = rSubSeq.getConstArray(); - - for( sal_Int32 nIndex2 = 0; nIndex2 < rSubSeq.getLength(); nIndex2++ ) - InsertHolidayList( rAnyConv, pAnyArray[ nIndex2 ], nNullDate, false/*bInsertOnWeekend*/ ); + for( const uno::Any& rAny : rSubSeq ) + InsertHolidayList( rAnyConv, rAny, nNullDate, false/*bInsertOnWeekend*/ ); } } else @@ -1499,13 +1495,10 @@ void SortedIndividualInt32List::InsertHolidayList( void ScaDoubleList::Append( const uno::Sequence< uno::Sequence< double > >& rValueSeq ) { - const uno::Sequence< double >* pSeqArray = rValueSeq.getConstArray(); - for( sal_Int32 nIndex1 = 0; nIndex1 < rValueSeq.getLength(); nIndex1++ ) + for( const uno::Sequence< double >& rSubSeq : rValueSeq ) { - const uno::Sequence< double >& rSubSeq = pSeqArray[ nIndex1 ]; - const double* pArray = rSubSeq.getConstArray(); - for( sal_Int32 nIndex2 = 0; nIndex2 < rSubSeq.getLength(); nIndex2++ ) - Append( pArray[ nIndex2 ] ); + for( const double fValue : rSubSeq ) + Append( fValue ); } } @@ -1513,13 +1506,10 @@ void ScaDoubleList::Append( void ScaDoubleList::Append( const uno::Sequence< uno::Sequence< sal_Int32 > >& rValueSeq ) { - const uno::Sequence< sal_Int32 >* pSeqArray = rValueSeq.getConstArray(); - for( sal_Int32 nIndex1 = 0; nIndex1 < rValueSeq.getLength(); nIndex1++ ) + for( const uno::Sequence< sal_Int32 >& rSubSeq : rValueSeq ) { - const uno::Sequence< sal_Int32 >& rSubSeq = pSeqArray[ nIndex1 ]; - const sal_Int32* pArray = rSubSeq.getConstArray(); - for( sal_Int32 nIndex2 = 0; nIndex2 < rSubSeq.getLength(); nIndex2++ ) - Append( pArray[ nIndex2 ] ); + for( const sal_Int32 nValue : rSubSeq ) + Append( nValue ); } } @@ -1547,9 +1537,8 @@ void ScaDoubleList::Append( const uno::Sequence< uno::Any >& rAnySeq, bool bIgnoreEmpty ) { - const uno::Any* pArray = rAnySeq.getConstArray(); - for( sal_Int32 nIndex = 0; nIndex < rAnySeq.getLength(); nIndex++ ) - Append( rAnyConv, pArray[ nIndex ], bIgnoreEmpty ); + for( const uno::Any& rAny : rAnySeq ) + Append( rAnyConv, rAny, bIgnoreEmpty ); } @@ -1558,9 +1547,8 @@ void ScaDoubleList::Append( const uno::Sequence< uno::Sequence< uno::Any > >& rAnySeq, bool bIgnoreEmpty ) { - const uno::Sequence< uno::Any >* pArray = rAnySeq.getConstArray(); - for( sal_Int32 nIndex = 0; nIndex < rAnySeq.getLength(); nIndex++ ) - Append( rAnyConv, pArray[ nIndex ], bIgnoreEmpty ); + for( const uno::Sequence< uno::Any >& rArray : rAnySeq ) + Append( rAnyConv, rArray, bIgnoreEmpty ); } void ScaDoubleList::Append( @@ -2013,19 +2001,10 @@ ComplexList::~ComplexList() void ComplexList::Append( const uno::Sequence< uno::Sequence< OUString > >& r ) { - sal_Int32 n1, n2; - sal_Int32 nE1 = r.getLength(); - sal_Int32 nE2; - - for( n1 = 0 ; n1 < nE1 ; n1++ ) + for( const uno::Sequence< OUString >& rList : r ) { - const uno::Sequence< OUString >& rList = r[ n1 ]; - nE2 = rList.getLength(); - - for( n2 = 0 ; n2 < nE2 ; n2++ ) + for( const OUString& rStr : rList ) { - const OUString& rStr = rList[ n2 ]; - if( !rStr.isEmpty() ) Append( Complex( rStr ) ); } @@ -2035,11 +2014,8 @@ void ComplexList::Append( const uno::Sequence< uno::Sequence< OUString > >& r ) void ComplexList::Append( const uno::Sequence< uno::Any >& aMultPars ) { - sal_Int32 nEle = aMultPars.getLength(); - - for( sal_Int32 i = 0 ; i < nEle ; i++ ) + for( const uno::Any& r : aMultPars ) { - const uno::Any& r = aMultPars[ i ]; switch( r.getValueTypeClass() ) { case uno::TypeClass_VOID: break; @@ -2060,10 +2036,8 @@ void ComplexList::Append( const uno::Sequence< uno::Any >& aMultPars ) if( !(r >>= aValArr) ) throw lang::IllegalArgumentException(); - sal_Int32 nE = aValArr.getLength(); - const uno::Sequence< uno::Any >* pArr = aValArr.getConstArray(); - for( sal_Int32 n = 0 ; n < nE ; n++ ) - Append( pArr[ n ] ); + for( const uno::Sequence< uno::Any >& rArr : aValArr ) + Append( rArr ); } break; default: diff --git a/sccomp/source/solver/CoinMPSolver.cxx b/sccomp/source/solver/CoinMPSolver.cxx index cd2973580997..b422c3456875 100644 --- a/sccomp/source/solver/CoinMPSolver.cxx +++ b/sccomp/source/solver/CoinMPSolver.cxx @@ -63,10 +63,7 @@ void SAL_CALL CoinMPSolver::solve() // collect variables in vector (?) - std::vector aVariableCells; - aVariableCells.reserve(maVariables.getLength()); - for (sal_Int32 nPos=0; nPos>(maVariables); size_t nVariables = aVariableCells.size(); size_t nVar = 0; @@ -75,12 +72,12 @@ void SAL_CALL CoinMPSolver::solve() ScSolverCellHashMap aCellsHash; aCellsHash[maObjective].reserve( nVariables + 1 ); // objective function - for (sal_Int32 nConstrPos = 0; nConstrPos < maConstraints.getLength(); ++nConstrPos) + for (const auto& rConstr : maConstraints) { - table::CellAddress aCellAddr = maConstraints[nConstrPos].Left; + table::CellAddress aCellAddr = rConstr.Left; aCellsHash[aCellAddr].reserve( nVariables + 1 ); // constraints: left hand side - if ( maConstraints[nConstrPos].Right >>= aCellAddr ) + if ( rConstr.Right >>= aCellAddr ) aCellsHash[aCellAddr].reserve( nVariables + 1 ); // constraints: right hand side } @@ -258,13 +255,13 @@ void SAL_CALL CoinMPSolver::solve() // apply single-var integer constraints - for (sal_Int32 nConstrPos = 0; nConstrPos < maConstraints.getLength(); ++nConstrPos) + for (const auto& rConstr : maConstraints) { - sheet::SolverConstraintOperator eOp = maConstraints[nConstrPos].Operator; + sheet::SolverConstraintOperator eOp = rConstr.Operator; if ( eOp == sheet::SolverConstraintOperator_INTEGER || eOp == sheet::SolverConstraintOperator_BINARY ) { - table::CellAddress aLeftAddr = maConstraints[nConstrPos].Left; + table::CellAddress aLeftAddr = rConstr.Left; // find variable index for cell for (nVar=0; nVar aVariableCells; - aVariableCells.reserve(maVariables.getLength()); - for (sal_Int32 nPos=0; nPos>(maVariables); size_t nVariables = aVariableCells.size(); size_t nVar = 0; @@ -110,12 +107,12 @@ void SAL_CALL LpsolveSolver::solve() ScSolverCellHashMap aCellsHash; aCellsHash[maObjective].reserve( nVariables + 1 ); // objective function - for (sal_Int32 nConstrPos = 0; nConstrPos < maConstraints.getLength(); ++nConstrPos) + for (const auto& rConstr : maConstraints) { - table::CellAddress aCellAddr = maConstraints[nConstrPos].Left; + table::CellAddress aCellAddr = rConstr.Left; aCellsHash[aCellAddr].reserve( nVariables + 1 ); // constraints: left hand side - if ( maConstraints[nConstrPos].Right >>= aCellAddr ) + if ( rConstr.Right >>= aCellAddr ) aCellsHash[aCellAddr].reserve( nVariables + 1 ); // constraints: right hand side } @@ -195,10 +192,10 @@ void SAL_CALL LpsolveSolver::solve() set_add_rowmode(lp, TRUE); - for (sal_Int32 nConstrPos = 0; nConstrPos < maConstraints.getLength(); ++nConstrPos) + for (const auto& rConstr : maConstraints) { // integer constraints are set later - sheet::SolverConstraintOperator eOp = maConstraints[nConstrPos].Operator; + sheet::SolverConstraintOperator eOp = rConstr.Operator; if ( eOp == sheet::SolverConstraintOperator_LESS_EQUAL || eOp == sheet::SolverConstraintOperator_GREATER_EQUAL || eOp == sheet::SolverConstraintOperator_EQUAL ) @@ -206,13 +203,13 @@ void SAL_CALL LpsolveSolver::solve() double fDirectValue = 0.0; bool bRightCell = false; table::CellAddress aRightAddr; - const uno::Any& rRightAny = maConstraints[nConstrPos].Right; + const uno::Any& rRightAny = rConstr.Right; if ( rRightAny >>= aRightAddr ) bRightCell = true; // cell specified as right-hand side else rRightAny >>= fDirectValue; // constant value - table::CellAddress aLeftAddr = maConstraints[nConstrPos].Left; + table::CellAddress aLeftAddr = rConstr.Left; const std::vector& rLeftCoeff = aCellsHash[aLeftAddr]; std::unique_ptr pValues(new REAL[nVariables+1] ); @@ -263,13 +260,13 @@ void SAL_CALL LpsolveSolver::solve() // apply single-var integer constraints - for (sal_Int32 nConstrPos = 0; nConstrPos < maConstraints.getLength(); ++nConstrPos) + for (const auto& rConstr : maConstraints) { - sheet::SolverConstraintOperator eOp = maConstraints[nConstrPos].Operator; + sheet::SolverConstraintOperator eOp = rConstr.Operator; if ( eOp == sheet::SolverConstraintOperator_INTEGER || eOp == sheet::SolverConstraintOperator_BINARY ) { - table::CellAddress aLeftAddr = maConstraints[nConstrPos].Left; + table::CellAddress aLeftAddr = rConstr.Left; // find variable index for cell for (nVar=0; nVar aProps = xModel->getArgs(); - sal_Int32 nProps = aProps.getLength(); - const PropertyValue* pProps = aProps.getConstArray(); - for ( sal_Int32 i = 0; i < nProps; ++i ) - { - // TODO: according to MBA the property 'Title' may change in future - if ( pProps[i].Name == "Title" ) - { - pProps[i].Value >>= sDocURL; - break; - } - } + // TODO: according to MBA the property 'Title' may change in future + const PropertyValue* pProp = std::find_if(aProps.begin(), aProps.end(), + [](const PropertyValue& rProp) { return rProp.Name == "Title"; }); + if (pProp != aProps.end()) + pProp->Value >>= sDocURL; } } } diff --git a/scripting/source/basprov/basprov.cxx b/scripting/source/basprov/basprov.cxx index 692f198cc960..1f0926abfa25 100644 --- a/scripting/source/basprov/basprov.cxx +++ b/scripting/source/basprov/basprov.cxx @@ -427,17 +427,16 @@ namespace basprov { Sequence< OUString > aLibNames = xLibContainer->getElementNames(); sal_Int32 nLibCount = aLibNames.getLength(); - const OUString* pLibNames = aLibNames.getConstArray(); aChildNodes.realloc( nLibCount ); Reference< browse::XBrowseNode >* pChildNodes = aChildNodes.getArray(); sal_Int32 childrenFound = 0; - for ( sal_Int32 i = 0 ; i < nLibCount ; ++i ) + for ( const OUString& rLibName : aLibNames ) { bool bCreate = false; if ( m_bIsAppScriptCtx ) { - const bool bShared = isLibraryShared( xLibContainer, pLibNames[i] ); + const bool bShared = isLibraryShared( xLibContainer, rLibName ); if (m_bIsUserCtx != bShared) bCreate = true; } @@ -449,7 +448,7 @@ namespace basprov { pChildNodes[childrenFound++] = new BasicLibraryNodeImpl(m_xContext, m_sScriptingContext, pBasicManager, - xLibContainer, pLibNames[i], m_bIsAppScriptCtx); + xLibContainer, rLibName, m_bIsAppScriptCtx); } } diff --git a/scripting/source/dlgprov/dlgevtatt.cxx b/scripting/source/dlgprov/dlgevtatt.cxx index 2bdcf0d2cfba..691b12ca757b 100644 --- a/scripting/source/dlgprov/dlgevtatt.cxx +++ b/scripting/source/dlgprov/dlgevtatt.cxx @@ -221,14 +221,12 @@ namespace dlgprov if ( xEventCont.is() ) { Sequence< OUString > aNames = xEventCont->getElementNames(); - const OUString* pNames = aNames.getConstArray(); - sal_Int32 nNameCount = aNames.getLength(); - for ( sal_Int32 j = 0; j < nNameCount; ++j ) + for ( const OUString& rName : aNames ) { ScriptEventDescriptor aDesc; - Any aElement = xEventCont->getByName( pNames[ j ] ); + Any aElement = xEventCont->getByName( rName ); aElement >>= aDesc; OUString sKey = aDesc.ScriptType; if ( aDesc.ScriptType == "Script" || aDesc.ScriptType == "UNO" ) @@ -277,15 +275,12 @@ namespace dlgprov void DialogEventsAttacherImpl::nestedAttachEvents( const Sequence< Reference< XInterface > >& Objects, const Any& Helper, OUString& sDialogCodeName ) { - const Reference< XInterface >* pObjects = Objects.getConstArray(); - sal_Int32 nObjCount = Objects.getLength(); - - for ( sal_Int32 i = 0; i < nObjCount; ++i ) + for ( const Reference< XInterface >& rObject : Objects ) { // We know that we have to do with instances of XControl. // Otherwise this is not the right implementation for // XScriptEventsAttacher and we have to give up. - Reference< XControl > xControl( pObjects[ i ], UNO_QUERY ); + Reference< XControl > xControl( rObject, UNO_QUERY ); Reference< XControlContainer > xControlContainer( xControl, UNO_QUERY ); Reference< XDialog > xDialog( xControl, UNO_QUERY ); if ( !xControl.is() ) diff --git a/scripting/source/protocolhandler/scripthandler.cxx b/scripting/source/protocolhandler/scripthandler.cxx index c4b7a519beb6..d1a7fb9e8bb1 100644 --- a/scripting/source/protocolhandler/scripthandler.cxx +++ b/scripting/source/protocolhandler/scripthandler.cxx @@ -111,12 +111,9 @@ const Sequence < DispatchDescriptor >& seqDescriptor ) { sal_Int32 nCount = seqDescriptor.getLength(); Sequence< Reference< XDispatch > > lDispatcher( nCount ); - for ( sal_Int32 i = 0; i < nCount; ++i ) - { - lDispatcher[ i ] = queryDispatch( seqDescriptor[ i ].FeatureURL, - seqDescriptor[ i ].FrameName, - seqDescriptor[ i ].SearchFlags ); - } + std::transform(seqDescriptor.begin(), seqDescriptor.end(), lDispatcher.begin(), + [this](const DispatchDescriptor& rDescr) -> Reference { + return queryDispatch(rDescr.FeatureURL, rDescr.FrameName, rDescr.SearchFlags); }); return lDispatcher; } @@ -184,18 +181,18 @@ void SAL_CALL ScriptProtocolHandler::dispatchWithNotification( if ( lArgs.hasElements() ) { int argCount = 0; - for ( int index = 0; index < lArgs.getLength(); index++ ) + for ( const auto& rArg : lArgs ) { // Sometimes we get a propertyval with name = "Referer" or "SynchronMode". These // are not actual arguments to be passed to script, but flags describing the // call, so ignore. Who thought that passing such "meta-arguments" mixed in with // real arguments was a good idea? - if ( (lArgs[ index ].Name != "Referer" && - lArgs[ index ].Name != "SynchronMode") || - lArgs[ index ].Name.isEmpty() ) //TODO:??? + if ( (rArg.Name != "Referer" && + rArg.Name != "SynchronMode") || + rArg.Name.isEmpty() ) //TODO:??? { inArgs.realloc( ++argCount ); - inArgs[ argCount - 1 ] = lArgs[ index ].Value; + inArgs[ argCount - 1 ] = rArg.Value; } } } 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; } diff --git a/scripting/source/stringresource/stringresource.cxx b/scripting/source/stringresource/stringresource.cxx index a50076ffc762..2c4c2f8a785d 100644 --- a/scripting/source/stringresource/stringresource.cxx +++ b/scripting/source/stringresource/stringresource.cxx @@ -1532,11 +1532,8 @@ void StringResourcePersistenceImpl::implScanLocaleNames( const Sequence< OUStrin Locale aDefaultLocale; bool bDefaultFound = false; - sal_Int32 nCount = aContentSeq.getLength(); - const OUString* pFiles = aContentSeq.getConstArray(); - for( int i = 0 ; i < nCount ; i++ ) + for( const OUString& aCompleteName : aContentSeq ) { - OUString aCompleteName = pFiles[i]; OUString aPureName; OUString aExtension; sal_Int32 iDot = aCompleteName.lastIndexOf( '.' ); diff --git a/scripting/source/vbaevents/eventhelper.cxx b/scripting/source/vbaevents/eventhelper.cxx index 8388450aa2b2..d987c5206999 100644 --- a/scripting/source/vbaevents/eventhelper.cxx +++ b/scripting/source/vbaevents/eventhelper.cxx @@ -382,21 +382,13 @@ ScriptEventHelper::getEventListeners() xIntrospection->inspect( makeAny( m_xControl ) ); Sequence< Type > aControlListeners = xIntrospectionAccess->getSupportedListeners(); - sal_Int32 nLength = aControlListeners.getLength(); - for ( sal_Int32 i = 0; i< nLength; ++i ) + for ( const Type& listType : aControlListeners ) { - Type& listType = aControlListeners[ i ]; OUString sFullTypeName = listType.getTypeName(); Sequence< OUString > sMeths = comphelper::getEventMethodsForType( listType ); - sal_Int32 sMethLen = sMeths.getLength(); - for ( sal_Int32 j=0 ; j < sMethLen; ++j ) - { - OUString sEventMethod = sFullTypeName; - sEventMethod += DELIM; - sEventMethod += sMeths[ j ]; - eventMethods.push_back( sEventMethod ); - } + std::transform(sMeths.begin(), sMeths.end(), std::back_inserter(eventMethods), + [&sFullTypeName](const OUString& rMeth) -> OUString { return sFullTypeName + DELIM + rMeth; }); } return comphelper::containerToSequence(eventMethods); @@ -476,16 +468,14 @@ typedef std::unordered_map< OUString, Any > EventSupplierHash; ReadOnlyEventsNameContainer::ReadOnlyEventsNameContainer( const Sequence< OUString >& eventMethods, const OUString& sCodeName ) { - const OUString* pSrc = eventMethods.getConstArray(); - sal_Int32 nLen = eventMethods.getLength(); - for ( sal_Int32 index = 0; index < nLen; ++index, ++pSrc ) + for ( const OUString& rSrc : eventMethods ) { Any aDesc; ScriptEventDescriptor evtDesc; - if ( eventMethodToDescriptor( *pSrc, evtDesc, sCodeName ) ) + if ( eventMethodToDescriptor( rSrc, evtDesc, sCodeName ) ) { aDesc <<= evtDesc; - m_hEvents[ *pSrc ] = aDesc; + m_hEvents[ rSrc ] = aDesc; } } } -- cgit v1.2.3