scaddins/source/analysis/analysishelper.cxx | 8 +- sccomp/source/solver/CoinMPSolver.cxx | 36 ++++----- sccomp/source/solver/LpsolveSolver.cxx | 36 ++++----- scripting/source/basprov/basscript.cxx | 8 +- scripting/source/provider/BrowseNodeFactoryImpl.cxx | 24 +++--- scripting/source/stringresource/stringresource.cxx | 76 ++++++++------------ scripting/source/vbaevents/eventhelper.cxx | 14 +-- 7 files changed, 93 insertions(+), 109 deletions(-)
New commits: commit b38e690296e48657ec8c66427a6511f42f4b0115 Author: Arkadiy Illarionov <qar...@gmail.com> AuthorDate: Wed Dec 19 21:53:06 2018 +0300 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Thu Dec 20 08:15:54 2018 +0100 Simplify containers iterations in scaddins, sccomp, scripting Use range-based loop or replace with STL functions Change-Id: I21ec2eea8f322e2792097d352fc352dc6099c7b7 Reviewed-on: https://gerrit.libreoffice.org/65461 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/scaddins/source/analysis/analysishelper.cxx b/scaddins/source/analysis/analysishelper.cxx index 1a21ecbb0b31..787c99bd3dd8 100644 --- a/scaddins/source/analysis/analysishelper.cxx +++ b/scaddins/source/analysis/analysishelper.cxx @@ -2457,10 +2457,9 @@ double ConvertDataList::Convert( double fVal, const OUString& rFrom, const OUStr sal_Int16 nLevelFrom = 0; sal_Int16 nLevelTo = 0; - auto it = maVector.begin(); - while( it != maVector.end() && ( bSearchFrom || bSearchTo ) ) + for( const auto& rItem : maVector ) { - ConvertData* p = it->get(); + ConvertData* p = rItem.get(); if( bSearchFrom ) { sal_Int16 n = p->GetMatchingLevel( rFrom ); @@ -2499,7 +2498,8 @@ double ConvertDataList::Convert( double fVal, const OUString& rFrom, const OUStr } } - ++it; + if( !bSearchFrom && !bSearchTo ) + break; } if( !pFrom || !pTo ) diff --git a/sccomp/source/solver/CoinMPSolver.cxx b/sccomp/source/solver/CoinMPSolver.cxx index dbd19a4d9f43..d227e48d5f0f 100644 --- a/sccomp/source/solver/CoinMPSolver.cxx +++ b/sccomp/source/solver/CoinMPSolver.cxx @@ -86,40 +86,38 @@ void SAL_CALL CoinMPSolver::solve() // set all variables to zero //! store old values? //! use old values as initial values? - std::vector<table::CellAddress>::const_iterator aVarIter; - for ( aVarIter = aVariableCells.begin(); aVarIter != aVariableCells.end(); ++aVarIter ) + for ( const auto& rVarCell : aVariableCells ) { - SolverComponent::SetValue( mxDoc, *aVarIter, 0.0 ); + SolverComponent::SetValue( mxDoc, rVarCell, 0.0 ); } // read initial values from all dependent cells - ScSolverCellHashMap::iterator aCellsIter; - for ( aCellsIter = aCellsHash.begin(); aCellsIter != aCellsHash.end(); ++aCellsIter ) + for ( auto& rEntry : aCellsHash ) { - double fValue = SolverComponent::GetValue( mxDoc, aCellsIter->first ); - aCellsIter->second.push_back( fValue ); // store as first element, as-is + double fValue = SolverComponent::GetValue( mxDoc, rEntry.first ); + rEntry.second.push_back( fValue ); // store as first element, as-is } // loop through variables - for ( aVarIter = aVariableCells.begin(); aVarIter != aVariableCells.end(); ++aVarIter ) + for ( const auto& rVarCell : aVariableCells ) { - SolverComponent::SetValue( mxDoc, *aVarIter, 1.0 ); // set to 1 to examine influence + SolverComponent::SetValue( mxDoc, rVarCell, 1.0 ); // set to 1 to examine influence // read value change from all dependent cells - for ( aCellsIter = aCellsHash.begin(); aCellsIter != aCellsHash.end(); ++aCellsIter ) + for ( auto& rEntry : aCellsHash ) { - double fChanged = SolverComponent::GetValue( mxDoc, aCellsIter->first ); - double fInitial = aCellsIter->second.front(); - aCellsIter->second.push_back( fChanged - fInitial ); + double fChanged = SolverComponent::GetValue( mxDoc, rEntry.first ); + double fInitial = rEntry.second.front(); + rEntry.second.push_back( fChanged - fInitial ); } - SolverComponent::SetValue( mxDoc, *aVarIter, 2.0 ); // minimal test for linearity + SolverComponent::SetValue( mxDoc, rVarCell, 2.0 ); // minimal test for linearity - for ( aCellsIter = aCellsHash.begin(); aCellsIter != aCellsHash.end(); ++aCellsIter ) + for ( const auto& rEntry : aCellsHash ) { - double fInitial = aCellsIter->second.front(); - double fCoeff = aCellsIter->second.back(); // last appended: coefficient for this variable - double fTwo = SolverComponent::GetValue( mxDoc, aCellsIter->first ); + double fInitial = rEntry.second.front(); + double fCoeff = rEntry.second.back(); // last appended: coefficient for this variable + double fTwo = SolverComponent::GetValue( mxDoc, rEntry.first ); bool bLinear = rtl::math::approxEqual( fTwo, fInitial + 2.0 * fCoeff ) || rtl::math::approxEqual( fInitial, fTwo - 2.0 * fCoeff ); @@ -128,7 +126,7 @@ void SAL_CALL CoinMPSolver::solve() maStatus = SolverComponent::GetResourceString( RID_ERROR_NONLINEAR ); } - SolverComponent::SetValue( mxDoc, *aVarIter, 0.0 ); // set back to zero for examining next variable + SolverComponent::SetValue( mxDoc, rVarCell, 0.0 ); // set back to zero for examining next variable } xModel->unlockControllers(); diff --git a/sccomp/source/solver/LpsolveSolver.cxx b/sccomp/source/solver/LpsolveSolver.cxx index 08b56ff1f9e9..0eb7d08dafd6 100644 --- a/sccomp/source/solver/LpsolveSolver.cxx +++ b/sccomp/source/solver/LpsolveSolver.cxx @@ -123,40 +123,38 @@ void SAL_CALL LpsolveSolver::solve() // set all variables to zero //! store old values? //! use old values as initial values? - std::vector<table::CellAddress>::const_iterator aVarIter; - for ( aVarIter = aVariableCells.begin(); aVarIter != aVariableCells.end(); ++aVarIter ) + for ( const auto& rVarCell : aVariableCells ) { - SolverComponent::SetValue( mxDoc, *aVarIter, 0.0 ); + SolverComponent::SetValue( mxDoc, rVarCell, 0.0 ); } // read initial values from all dependent cells - ScSolverCellHashMap::iterator aCellsIter; - for ( aCellsIter = aCellsHash.begin(); aCellsIter != aCellsHash.end(); ++aCellsIter ) + for ( auto& rEntry : aCellsHash ) { - double fValue = SolverComponent::GetValue( mxDoc, aCellsIter->first ); - aCellsIter->second.push_back( fValue ); // store as first element, as-is + double fValue = SolverComponent::GetValue( mxDoc, rEntry.first ); + rEntry.second.push_back( fValue ); // store as first element, as-is } // loop through variables - for ( aVarIter = aVariableCells.begin(); aVarIter != aVariableCells.end(); ++aVarIter ) + for ( const auto& rVarCell : aVariableCells ) { - SolverComponent::SetValue( mxDoc, *aVarIter, 1.0 ); // set to 1 to examine influence + SolverComponent::SetValue( mxDoc, rVarCell, 1.0 ); // set to 1 to examine influence // read value change from all dependent cells - for ( aCellsIter = aCellsHash.begin(); aCellsIter != aCellsHash.end(); ++aCellsIter ) + for ( auto& rEntry : aCellsHash ) { - double fChanged = SolverComponent::GetValue( mxDoc, aCellsIter->first ); - double fInitial = aCellsIter->second.front(); - aCellsIter->second.push_back( fChanged - fInitial ); + double fChanged = SolverComponent::GetValue( mxDoc, rEntry.first ); + double fInitial = rEntry.second.front(); + rEntry.second.push_back( fChanged - fInitial ); } - SolverComponent::SetValue( mxDoc, *aVarIter, 2.0 ); // minimal test for linearity + SolverComponent::SetValue( mxDoc, rVarCell, 2.0 ); // minimal test for linearity - for ( aCellsIter = aCellsHash.begin(); aCellsIter != aCellsHash.end(); ++aCellsIter ) + for ( const auto& rEntry : aCellsHash ) { - double fInitial = aCellsIter->second.front(); - double fCoeff = aCellsIter->second.back(); // last appended: coefficient for this variable - double fTwo = SolverComponent::GetValue( mxDoc, aCellsIter->first ); + double fInitial = rEntry.second.front(); + double fCoeff = rEntry.second.back(); // last appended: coefficient for this variable + double fTwo = SolverComponent::GetValue( mxDoc, rEntry.first ); bool bLinear = rtl::math::approxEqual( fTwo, fInitial + 2.0 * fCoeff ) || rtl::math::approxEqual( fInitial, fTwo - 2.0 * fCoeff ); @@ -165,7 +163,7 @@ void SAL_CALL LpsolveSolver::solve() maStatus = SolverComponent::GetResourceString( RID_ERROR_NONLINEAR ); } - SolverComponent::SetValue( mxDoc, *aVarIter, 0.0 ); // set back to zero for examining next variable + SolverComponent::SetValue( mxDoc, rVarCell, 0.0 ); // set back to zero for examining next variable } xModel->unlockControllers(); diff --git a/scripting/source/basprov/basscript.cxx b/scripting/source/basprov/basscript.cxx index 6eac074750a9..fbefb064dc97 100644 --- a/scripting/source/basprov/basscript.cxx +++ b/scripting/source/basprov/basscript.cxx @@ -266,10 +266,12 @@ namespace basprov aOutParam.realloc( nOutParamCount ); sal_Int16* pOutParamIndex = aOutParamIndex.getArray(); Any* pOutParam = aOutParam.getArray(); - for ( OutParamMap::iterator aIt = aOutParamMap.begin(); aIt != aOutParamMap.end(); ++aIt, ++pOutParamIndex, ++pOutParam ) + for ( const auto& rEntry : aOutParamMap ) { - *pOutParamIndex = aIt->first; - *pOutParam = aIt->second; + *pOutParamIndex = rEntry.first; + ++pOutParamIndex; + *pOutParam = rEntry.second; + ++pOutParam; } } } diff --git a/scripting/source/provider/BrowseNodeFactoryImpl.cxx b/scripting/source/provider/BrowseNodeFactoryImpl.cxx index a0ff04cf2e1f..6621d5453737 100644 --- a/scripting/source/provider/BrowseNodeFactoryImpl.cxx +++ b/scripting/source/provider/BrowseNodeFactoryImpl.cxx @@ -105,17 +105,17 @@ public: } } - std::vector< Sequence< Reference < browse::XBrowseNode > > >::const_iterator it = seqs.begin(); - std::vector< Sequence< Reference < browse::XBrowseNode > > >::const_iterator it_end = seqs.end(); - Sequence< Reference < browse::XBrowseNode > > result( numChildren ); - for ( sal_Int32 index = 0; it != it_end && index < numChildren ; ++it ) + sal_Int32 index = 0; + for ( Sequence< Reference < browse::XBrowseNode > >& children : seqs ) { - Sequence< Reference < browse::XBrowseNode > > children = *it; for ( sal_Int32 j = 0; j < children.getLength(); j++ ) { result[ index++ ] = children[ j ]; } + + if (index >= numChildren) + break; } return result; } @@ -411,10 +411,11 @@ public: ::std::sort( aVNodes.begin(), aVNodes.end(), alphaSortForBNodes() ); Sequence < Reference< browse::XBrowseNode > > children( aVNodes.size() ); - vXBrowseNodes::const_iterator it = aVNodes.begin(); - for ( sal_Int32 i=0; it != aVNodes.end() && i<children.getLength(); i++, ++it ) + sal_Int32 i = 0; + for ( const auto& rxNode : aVNodes ) { - children[ i ].set( *it ); + children[ i ].set( rxNode ); + i++; } return children; } @@ -501,10 +502,11 @@ public: // no need to sort user, share, doc1...docN //::std::sort( m_vNodes.begin(), m_vNodes.end(), alphaSortForBNodes() ); Sequence < Reference< browse::XBrowseNode > > children( m_vNodes.size() ); - vXBrowseNodes::const_iterator it = m_vNodes.begin(); - for ( sal_Int32 i=0; it != m_vNodes.end() && i<children.getLength(); i++, ++it ) + sal_Int32 i = 0; + for ( const auto& rxNode : m_vNodes ) { - children[ i ].set( *it ); + children[ i ].set( rxNode ); + i++; } return children; } diff --git a/scripting/source/stringresource/stringresource.cxx b/scripting/source/stringresource/stringresource.cxx index bf4260646caa..81639ef1ea3e 100644 --- a/scripting/source/stringresource/stringresource.cxx +++ b/scripting/source/stringresource/stringresource.cxx @@ -220,11 +220,10 @@ Sequence< OUString > StringResourceImpl::implGetResourceIDs( LocaleItem* pLocale aIDSeq.realloc( nResourceIDCount ); OUString* pStrings = aIDSeq.getArray(); - IdToStringMap::const_iterator it; int iTarget = 0; - for( it = rHashMap.begin(); it != rHashMap.end(); ++it ) + for( const auto& rEntry : rHashMap ) { - OUString aStr = (*it).first; + OUString aStr = rEntry.first; pStrings[iTarget] = aStr; iTarget++; } @@ -445,21 +444,19 @@ void StringResourceImpl::newLocale( const Locale& locale ) { const IdToStringMap& rSourceMap = pCopyFromItem->m_aIdToStringMap; IdToStringMap& rTargetMap = pLocaleItem->m_aIdToStringMap; - IdToStringMap::const_iterator it; - for( it = rSourceMap.begin(); it != rSourceMap.end(); ++it ) + for( const auto& rEntry : rSourceMap ) { - OUString aId = (*it).first; - OUString aStr = (*it).second; + OUString aId = rEntry.first; + OUString aStr = rEntry.second; rTargetMap[ aId ] = aStr; } const IdToIndexMap& rSourceIndexMap = pCopyFromItem->m_aIdToIndexMap; IdToIndexMap& rTargetIndexMap = pLocaleItem->m_aIdToIndexMap; - IdToIndexMap::const_iterator it_index; - for( it_index = rSourceIndexMap.begin(); it_index != rSourceIndexMap.end(); ++it_index ) + for( const auto& rIndex : rSourceIndexMap ) { - OUString aId = (*it_index).first; - sal_Int32 nIndex = (*it_index).second; + OUString aId = rIndex.first; + sal_Int32 nIndex = rIndex.second; rTargetIndexMap[ aId ] = nIndex; } pLocaleItem->m_nNextIndex = pCopyFromItem->m_nNextIndex; @@ -511,31 +508,29 @@ void StringResourceImpl::removeLocale( const Locale& locale ) } } } - for( auto it = m_aLocaleItemVector.begin(); it != m_aLocaleItemVector.end(); ++it ) + auto it = std::find_if(m_aLocaleItemVector.begin(), m_aLocaleItemVector.end(), + [&pRemoveItem](const std::unique_ptr<LocaleItem>& rxItem) { return rxItem.get() == pRemoveItem; }); + if (it != m_aLocaleItemVector.end()) { - if( it->get() == pRemoveItem ) - { - // Remember locale item to delete file while storing - m_aDeletedLocaleItemVector.push_back( std::move(*it) ); + // Remember locale item to delete file while storing + m_aDeletedLocaleItemVector.push_back( std::move(*it) ); - // Last locale? - if( nLocaleCount == 1 ) + // Last locale? + if( nLocaleCount == 1 ) + { + m_nNextUniqueNumericId = 0; + if( m_pDefaultLocaleItem ) { - m_nNextUniqueNumericId = 0; - if( m_pDefaultLocaleItem ) - { - m_aChangedDefaultLocaleVector.push_back( - o3tl::make_unique<LocaleItem>( m_pDefaultLocaleItem->m_locale ) ); - } - m_pCurrentLocaleItem = nullptr; - m_pDefaultLocaleItem = nullptr; + m_aChangedDefaultLocaleVector.push_back( + o3tl::make_unique<LocaleItem>( m_pDefaultLocaleItem->m_locale ) ); } + m_pCurrentLocaleItem = nullptr; + m_pDefaultLocaleItem = nullptr; + } - m_aLocaleItemVector.erase( it ); + m_aLocaleItemVector.erase( it ); - implModified(); - break; - } + implModified(); } } } @@ -2019,29 +2014,22 @@ bool StringResourcePersistenceImpl::implWritePropertiesFile( LocaleItem const * { // Sort ids according to read order const IdToIndexMap& rIndexMap = pLocaleItem->m_aIdToIndexMap; - IdToIndexMap::const_iterator it_index; // Find max/min index - sal_Int32 nMinIndex = -1; - sal_Int32 nMaxIndex = -1; - for( it_index = rIndexMap.begin(); it_index != rIndexMap.end(); ++it_index ) - { - sal_Int32 nIndex = (*it_index).second; - if( nMinIndex > nIndex || nMinIndex == -1 ) - nMinIndex = nIndex; - if( nMaxIndex < nIndex ) - nMaxIndex = nIndex; - } + auto itMinMax = std::minmax_element(rIndexMap.begin(), rIndexMap.end(), + [](const IdToIndexMap::value_type& a, const IdToIndexMap::value_type& b) { return a.second < b.second; }); + sal_Int32 nMinIndex = itMinMax.first->second; + sal_Int32 nMaxIndex = itMinMax.second->second; sal_Int32 nTabSize = nMaxIndex - nMinIndex + 1; // Create sorted array of pointers to the id strings std::unique_ptr<const OUString*[]> pIdPtrs( new const OUString*[nTabSize] ); for(sal_Int32 i = 0 ; i < nTabSize ; i++ ) pIdPtrs[i] = nullptr; - for( it_index = rIndexMap.begin(); it_index != rIndexMap.end(); ++it_index ) + for( const auto& rIndex : rIndexMap ) { - sal_Int32 nIndex = (*it_index).second; - pIdPtrs[nIndex - nMinIndex] = &((*it_index).first); + sal_Int32 nIndex = rIndex.second; + pIdPtrs[nIndex - nMinIndex] = &(rIndex.first); } // Write lines in correct order diff --git a/scripting/source/vbaevents/eventhelper.cxx b/scripting/source/vbaevents/eventhelper.cxx index 408539cb7038..c0859edfaa4e 100644 --- a/scripting/source/vbaevents/eventhelper.cxx +++ b/scripting/source/vbaevents/eventhelper.cxx @@ -844,10 +844,6 @@ EventListener::firing_Impl(const ScriptEvent& evt, Any* pRet ) } if ( xScriptProvider.is() && mpShell ) { - std::list< TranslateInfo >::const_iterator txInfo = - eventInfo_it->second.begin(); - std::list< TranslateInfo >::const_iterator txInfo_end = eventInfo_it->second.end(); - BasicManager* pBasicManager = mpShell->GetBasicManager(); OUString sProject; OUString sScriptCode( evt.ScriptCode ); @@ -871,7 +867,7 @@ EventListener::firing_Impl(const ScriptEvent& evt, Any* pRet ) } OUString sMacroLoc = sProject + "." + sScriptCode + "."; - for ( ; txInfo != txInfo_end; ++txInfo ) + for (const auto& rTxInfo : eventInfo_it->second) { // If the document is closed, we should not execute macro. if (m_bDocClosed) @@ -879,7 +875,7 @@ EventListener::firing_Impl(const ScriptEvent& evt, Any* pRet ) break; } - OUString sTemp = sName.concat( (*txInfo).sVBAName ); + OUString sTemp = sName.concat( rTxInfo.sVBAName ); // see if we have a match for the handlerextension // where ScriptCode is methodname_handlerextension OUString sToResolve = sMacroLoc.concat( sTemp ); @@ -888,16 +884,16 @@ EventListener::firing_Impl(const ScriptEvent& evt, Any* pRet ) if ( aMacroResolvedInfo.mbFound ) { - if (! txInfo->ApproveRule(evt, txInfo->pPara) ) + if (! rTxInfo.ApproveRule(evt, rTxInfo.pPara) ) { continue; } // !! translate arguments & emulate events where necessary Sequence< Any > aArguments; - if ( (*txInfo).toVBA ) + if ( rTxInfo.toVBA ) { - aArguments = (*txInfo).toVBA( evt.Arguments ); + aArguments = rTxInfo.toVBA( evt.Arguments ); } else { _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits