Kaydet (Commit) b38e6902 authored tarafından Arkadiy Illarionov's avatar Arkadiy Illarionov Kaydeden (comit) Noel Grandin

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: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 45f0c58c
...@@ -2457,10 +2457,9 @@ double ConvertDataList::Convert( double fVal, const OUString& rFrom, const OUStr ...@@ -2457,10 +2457,9 @@ double ConvertDataList::Convert( double fVal, const OUString& rFrom, const OUStr
sal_Int16 nLevelFrom = 0; sal_Int16 nLevelFrom = 0;
sal_Int16 nLevelTo = 0; sal_Int16 nLevelTo = 0;
auto it = maVector.begin(); for( const auto& rItem : maVector )
while( it != maVector.end() && ( bSearchFrom || bSearchTo ) )
{ {
ConvertData* p = it->get(); ConvertData* p = rItem.get();
if( bSearchFrom ) if( bSearchFrom )
{ {
sal_Int16 n = p->GetMatchingLevel( rFrom ); sal_Int16 n = p->GetMatchingLevel( rFrom );
...@@ -2499,7 +2498,8 @@ double ConvertDataList::Convert( double fVal, const OUString& rFrom, const OUStr ...@@ -2499,7 +2498,8 @@ double ConvertDataList::Convert( double fVal, const OUString& rFrom, const OUStr
} }
} }
++it; if( !bSearchFrom && !bSearchTo )
break;
} }
if( !pFrom || !pTo ) if( !pFrom || !pTo )
......
...@@ -86,40 +86,38 @@ void SAL_CALL CoinMPSolver::solve() ...@@ -86,40 +86,38 @@ void SAL_CALL CoinMPSolver::solve()
// set all variables to zero // set all variables to zero
//! store old values? //! store old values?
//! use old values as initial values? //! use old values as initial values?
std::vector<table::CellAddress>::const_iterator aVarIter; for ( const auto& rVarCell : aVariableCells )
for ( aVarIter = aVariableCells.begin(); aVarIter != aVariableCells.end(); ++aVarIter )
{ {
SolverComponent::SetValue( mxDoc, *aVarIter, 0.0 ); SolverComponent::SetValue( mxDoc, rVarCell, 0.0 );
} }
// read initial values from all dependent cells // read initial values from all dependent cells
ScSolverCellHashMap::iterator aCellsIter; for ( auto& rEntry : aCellsHash )
for ( aCellsIter = aCellsHash.begin(); aCellsIter != aCellsHash.end(); ++aCellsIter )
{ {
double fValue = SolverComponent::GetValue( mxDoc, aCellsIter->first ); double fValue = SolverComponent::GetValue( mxDoc, rEntry.first );
aCellsIter->second.push_back( fValue ); // store as first element, as-is rEntry.second.push_back( fValue ); // store as first element, as-is
} }
// loop through variables // 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 // 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 fChanged = SolverComponent::GetValue( mxDoc, rEntry.first );
double fInitial = aCellsIter->second.front(); double fInitial = rEntry.second.front();
aCellsIter->second.push_back( fChanged - fInitial ); 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 fInitial = rEntry.second.front();
double fCoeff = aCellsIter->second.back(); // last appended: coefficient for this variable double fCoeff = rEntry.second.back(); // last appended: coefficient for this variable
double fTwo = SolverComponent::GetValue( mxDoc, aCellsIter->first ); double fTwo = SolverComponent::GetValue( mxDoc, rEntry.first );
bool bLinear = rtl::math::approxEqual( fTwo, fInitial + 2.0 * fCoeff ) || bool bLinear = rtl::math::approxEqual( fTwo, fInitial + 2.0 * fCoeff ) ||
rtl::math::approxEqual( fInitial, fTwo - 2.0 * fCoeff ); rtl::math::approxEqual( fInitial, fTwo - 2.0 * fCoeff );
...@@ -128,7 +126,7 @@ void SAL_CALL CoinMPSolver::solve() ...@@ -128,7 +126,7 @@ void SAL_CALL CoinMPSolver::solve()
maStatus = SolverComponent::GetResourceString( RID_ERROR_NONLINEAR ); 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(); xModel->unlockControllers();
......
...@@ -123,40 +123,38 @@ void SAL_CALL LpsolveSolver::solve() ...@@ -123,40 +123,38 @@ void SAL_CALL LpsolveSolver::solve()
// set all variables to zero // set all variables to zero
//! store old values? //! store old values?
//! use old values as initial values? //! use old values as initial values?
std::vector<table::CellAddress>::const_iterator aVarIter; for ( const auto& rVarCell : aVariableCells )
for ( aVarIter = aVariableCells.begin(); aVarIter != aVariableCells.end(); ++aVarIter )
{ {
SolverComponent::SetValue( mxDoc, *aVarIter, 0.0 ); SolverComponent::SetValue( mxDoc, rVarCell, 0.0 );
} }
// read initial values from all dependent cells // read initial values from all dependent cells
ScSolverCellHashMap::iterator aCellsIter; for ( auto& rEntry : aCellsHash )
for ( aCellsIter = aCellsHash.begin(); aCellsIter != aCellsHash.end(); ++aCellsIter )
{ {
double fValue = SolverComponent::GetValue( mxDoc, aCellsIter->first ); double fValue = SolverComponent::GetValue( mxDoc, rEntry.first );
aCellsIter->second.push_back( fValue ); // store as first element, as-is rEntry.second.push_back( fValue ); // store as first element, as-is
} }
// loop through variables // 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 // 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 fChanged = SolverComponent::GetValue( mxDoc, rEntry.first );
double fInitial = aCellsIter->second.front(); double fInitial = rEntry.second.front();
aCellsIter->second.push_back( fChanged - fInitial ); 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 fInitial = rEntry.second.front();
double fCoeff = aCellsIter->second.back(); // last appended: coefficient for this variable double fCoeff = rEntry.second.back(); // last appended: coefficient for this variable
double fTwo = SolverComponent::GetValue( mxDoc, aCellsIter->first ); double fTwo = SolverComponent::GetValue( mxDoc, rEntry.first );
bool bLinear = rtl::math::approxEqual( fTwo, fInitial + 2.0 * fCoeff ) || bool bLinear = rtl::math::approxEqual( fTwo, fInitial + 2.0 * fCoeff ) ||
rtl::math::approxEqual( fInitial, fTwo - 2.0 * fCoeff ); rtl::math::approxEqual( fInitial, fTwo - 2.0 * fCoeff );
...@@ -165,7 +163,7 @@ void SAL_CALL LpsolveSolver::solve() ...@@ -165,7 +163,7 @@ void SAL_CALL LpsolveSolver::solve()
maStatus = SolverComponent::GetResourceString( RID_ERROR_NONLINEAR ); 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(); xModel->unlockControllers();
......
...@@ -266,10 +266,12 @@ namespace basprov ...@@ -266,10 +266,12 @@ namespace basprov
aOutParam.realloc( nOutParamCount ); aOutParam.realloc( nOutParamCount );
sal_Int16* pOutParamIndex = aOutParamIndex.getArray(); sal_Int16* pOutParamIndex = aOutParamIndex.getArray();
Any* pOutParam = aOutParam.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; *pOutParamIndex = rEntry.first;
*pOutParam = aIt->second; ++pOutParamIndex;
*pOutParam = rEntry.second;
++pOutParam;
} }
} }
} }
......
...@@ -105,17 +105,17 @@ public: ...@@ -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 ); 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++ ) for ( sal_Int32 j = 0; j < children.getLength(); j++ )
{ {
result[ index++ ] = children[ j ]; result[ index++ ] = children[ j ];
} }
if (index >= numChildren)
break;
} }
return result; return result;
} }
...@@ -411,10 +411,11 @@ public: ...@@ -411,10 +411,11 @@ public:
::std::sort( aVNodes.begin(), aVNodes.end(), alphaSortForBNodes() ); ::std::sort( aVNodes.begin(), aVNodes.end(), alphaSortForBNodes() );
Sequence < Reference< browse::XBrowseNode > > children( aVNodes.size() ); Sequence < Reference< browse::XBrowseNode > > children( aVNodes.size() );
vXBrowseNodes::const_iterator it = aVNodes.begin(); sal_Int32 i = 0;
for ( sal_Int32 i=0; it != aVNodes.end() && i<children.getLength(); i++, ++it ) for ( const auto& rxNode : aVNodes )
{ {
children[ i ].set( *it ); children[ i ].set( rxNode );
i++;
} }
return children; return children;
} }
...@@ -501,10 +502,11 @@ public: ...@@ -501,10 +502,11 @@ public:
// no need to sort user, share, doc1...docN // no need to sort user, share, doc1...docN
//::std::sort( m_vNodes.begin(), m_vNodes.end(), alphaSortForBNodes() ); //::std::sort( m_vNodes.begin(), m_vNodes.end(), alphaSortForBNodes() );
Sequence < Reference< browse::XBrowseNode > > children( m_vNodes.size() ); Sequence < Reference< browse::XBrowseNode > > children( m_vNodes.size() );
vXBrowseNodes::const_iterator it = m_vNodes.begin(); sal_Int32 i = 0;
for ( sal_Int32 i=0; it != m_vNodes.end() && i<children.getLength(); i++, ++it ) for ( const auto& rxNode : m_vNodes )
{ {
children[ i ].set( *it ); children[ i ].set( rxNode );
i++;
} }
return children; return children;
} }
......
...@@ -220,11 +220,10 @@ Sequence< OUString > StringResourceImpl::implGetResourceIDs( LocaleItem* pLocale ...@@ -220,11 +220,10 @@ Sequence< OUString > StringResourceImpl::implGetResourceIDs( LocaleItem* pLocale
aIDSeq.realloc( nResourceIDCount ); aIDSeq.realloc( nResourceIDCount );
OUString* pStrings = aIDSeq.getArray(); OUString* pStrings = aIDSeq.getArray();
IdToStringMap::const_iterator it;
int iTarget = 0; 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; pStrings[iTarget] = aStr;
iTarget++; iTarget++;
} }
...@@ -445,21 +444,19 @@ void StringResourceImpl::newLocale( const Locale& locale ) ...@@ -445,21 +444,19 @@ void StringResourceImpl::newLocale( const Locale& locale )
{ {
const IdToStringMap& rSourceMap = pCopyFromItem->m_aIdToStringMap; const IdToStringMap& rSourceMap = pCopyFromItem->m_aIdToStringMap;
IdToStringMap& rTargetMap = pLocaleItem->m_aIdToStringMap; IdToStringMap& rTargetMap = pLocaleItem->m_aIdToStringMap;
IdToStringMap::const_iterator it; for( const auto& rEntry : rSourceMap )
for( it = rSourceMap.begin(); it != rSourceMap.end(); ++it )
{ {
OUString aId = (*it).first; OUString aId = rEntry.first;
OUString aStr = (*it).second; OUString aStr = rEntry.second;
rTargetMap[ aId ] = aStr; rTargetMap[ aId ] = aStr;
} }
const IdToIndexMap& rSourceIndexMap = pCopyFromItem->m_aIdToIndexMap; const IdToIndexMap& rSourceIndexMap = pCopyFromItem->m_aIdToIndexMap;
IdToIndexMap& rTargetIndexMap = pLocaleItem->m_aIdToIndexMap; IdToIndexMap& rTargetIndexMap = pLocaleItem->m_aIdToIndexMap;
IdToIndexMap::const_iterator it_index; for( const auto& rIndex : rSourceIndexMap )
for( it_index = rSourceIndexMap.begin(); it_index != rSourceIndexMap.end(); ++it_index )
{ {
OUString aId = (*it_index).first; OUString aId = rIndex.first;
sal_Int32 nIndex = (*it_index).second; sal_Int32 nIndex = rIndex.second;
rTargetIndexMap[ aId ] = nIndex; rTargetIndexMap[ aId ] = nIndex;
} }
pLocaleItem->m_nNextIndex = pCopyFromItem->m_nNextIndex; pLocaleItem->m_nNextIndex = pCopyFromItem->m_nNextIndex;
...@@ -511,31 +508,29 @@ void StringResourceImpl::removeLocale( const Locale& locale ) ...@@ -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? // Last locale?
if( nLocaleCount == 1 ) if( nLocaleCount == 1 )
{
m_nNextUniqueNumericId = 0;
if( m_pDefaultLocaleItem )
{ {
m_nNextUniqueNumericId = 0; m_aChangedDefaultLocaleVector.push_back(
if( m_pDefaultLocaleItem ) o3tl::make_unique<LocaleItem>( m_pDefaultLocaleItem->m_locale ) );
{
m_aChangedDefaultLocaleVector.push_back(
o3tl::make_unique<LocaleItem>( m_pDefaultLocaleItem->m_locale ) );
}
m_pCurrentLocaleItem = nullptr;
m_pDefaultLocaleItem = nullptr;
} }
m_pCurrentLocaleItem = nullptr;
m_pDefaultLocaleItem = nullptr;
}
m_aLocaleItemVector.erase( it ); m_aLocaleItemVector.erase( it );
implModified(); implModified();
break;
}
} }
} }
} }
...@@ -2019,29 +2014,22 @@ bool StringResourcePersistenceImpl::implWritePropertiesFile( LocaleItem const * ...@@ -2019,29 +2014,22 @@ bool StringResourcePersistenceImpl::implWritePropertiesFile( LocaleItem const *
{ {
// Sort ids according to read order // Sort ids according to read order
const IdToIndexMap& rIndexMap = pLocaleItem->m_aIdToIndexMap; const IdToIndexMap& rIndexMap = pLocaleItem->m_aIdToIndexMap;
IdToIndexMap::const_iterator it_index;
// Find max/min index // Find max/min index
sal_Int32 nMinIndex = -1; auto itMinMax = std::minmax_element(rIndexMap.begin(), rIndexMap.end(),
sal_Int32 nMaxIndex = -1; [](const IdToIndexMap::value_type& a, const IdToIndexMap::value_type& b) { return a.second < b.second; });
for( it_index = rIndexMap.begin(); it_index != rIndexMap.end(); ++it_index ) sal_Int32 nMinIndex = itMinMax.first->second;
{ sal_Int32 nMaxIndex = itMinMax.second->second;
sal_Int32 nIndex = (*it_index).second;
if( nMinIndex > nIndex || nMinIndex == -1 )
nMinIndex = nIndex;
if( nMaxIndex < nIndex )
nMaxIndex = nIndex;
}
sal_Int32 nTabSize = nMaxIndex - nMinIndex + 1; sal_Int32 nTabSize = nMaxIndex - nMinIndex + 1;
// Create sorted array of pointers to the id strings // Create sorted array of pointers to the id strings
std::unique_ptr<const OUString*[]> pIdPtrs( new const OUString*[nTabSize] ); std::unique_ptr<const OUString*[]> pIdPtrs( new const OUString*[nTabSize] );
for(sal_Int32 i = 0 ; i < nTabSize ; i++ ) for(sal_Int32 i = 0 ; i < nTabSize ; i++ )
pIdPtrs[i] = nullptr; 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; sal_Int32 nIndex = rIndex.second;
pIdPtrs[nIndex - nMinIndex] = &((*it_index).first); pIdPtrs[nIndex - nMinIndex] = &(rIndex.first);
} }
// Write lines in correct order // Write lines in correct order
......
...@@ -844,10 +844,6 @@ EventListener::firing_Impl(const ScriptEvent& evt, Any* pRet ) ...@@ -844,10 +844,6 @@ EventListener::firing_Impl(const ScriptEvent& evt, Any* pRet )
} }
if ( xScriptProvider.is() && mpShell ) 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(); BasicManager* pBasicManager = mpShell->GetBasicManager();
OUString sProject; OUString sProject;
OUString sScriptCode( evt.ScriptCode ); OUString sScriptCode( evt.ScriptCode );
...@@ -871,7 +867,7 @@ EventListener::firing_Impl(const ScriptEvent& evt, Any* pRet ) ...@@ -871,7 +867,7 @@ EventListener::firing_Impl(const ScriptEvent& evt, Any* pRet )
} }
OUString sMacroLoc = sProject + "." + sScriptCode + "."; 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 the document is closed, we should not execute macro.
if (m_bDocClosed) if (m_bDocClosed)
...@@ -879,7 +875,7 @@ EventListener::firing_Impl(const ScriptEvent& evt, Any* pRet ) ...@@ -879,7 +875,7 @@ EventListener::firing_Impl(const ScriptEvent& evt, Any* pRet )
break; break;
} }
OUString sTemp = sName.concat( (*txInfo).sVBAName ); OUString sTemp = sName.concat( rTxInfo.sVBAName );
// see if we have a match for the handlerextension // see if we have a match for the handlerextension
// where ScriptCode is methodname_handlerextension // where ScriptCode is methodname_handlerextension
OUString sToResolve = sMacroLoc.concat( sTemp ); OUString sToResolve = sMacroLoc.concat( sTemp );
...@@ -888,16 +884,16 @@ EventListener::firing_Impl(const ScriptEvent& evt, Any* pRet ) ...@@ -888,16 +884,16 @@ EventListener::firing_Impl(const ScriptEvent& evt, Any* pRet )
if ( aMacroResolvedInfo.mbFound ) if ( aMacroResolvedInfo.mbFound )
{ {
if (! txInfo->ApproveRule(evt, txInfo->pPara) ) if (! rTxInfo.ApproveRule(evt, rTxInfo.pPara) )
{ {
continue; continue;
} }
// !! translate arguments & emulate events where necessary // !! translate arguments & emulate events where necessary
Sequence< Any > aArguments; Sequence< Any > aArguments;
if ( (*txInfo).toVBA ) if ( rTxInfo.toVBA )
{ {
aArguments = (*txInfo).toVBA( evt.Arguments ); aArguments = rTxInfo.toVBA( evt.Arguments );
} }
else else
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment