summaryrefslogtreecommitdiff
path: root/desktop
diff options
context:
space:
mode:
authorArkadiy Illarionov <qarkai@gmail.com>2019-02-20 01:10:07 +0300
committerNoel Grandin <noel.grandin@collabora.co.uk>2019-02-20 07:17:38 +0100
commit6a143985bdc5d12d1f9e8cf8592440282986c099 (patch)
tree346e09d6ba1146b52a6a484a2883f3e898184648 /desktop
parentd707a5e64ba53ddb7669cca725915527aa788a6b (diff)
Simplify containers iterations in desktop, dtrans, editeng, extensions
Use range-based loop or replace with STL functions Change-Id: Ic5389d123d0a6a32a8bb46b081165e94a7c55292 Reviewed-on: https://gerrit.libreoffice.org/68036 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'desktop')
-rw-r--r--desktop/source/deployment/gui/dp_gui_extlistbox.cxx75
-rw-r--r--desktop/source/migration/migration.cxx17
2 files changed, 40 insertions, 52 deletions
diff --git a/desktop/source/deployment/gui/dp_gui_extlistbox.cxx b/desktop/source/deployment/gui/dp_gui_extlistbox.cxx
index 8a92a746ca2f..eb34d3730ada 100644
--- a/desktop/source/deployment/gui/dp_gui_extlistbox.cxx
+++ b/desktop/source/deployment/gui/dp_gui_extlistbox.cxx
@@ -885,15 +885,12 @@ bool ExtensionBox_Impl::FindEntryPos( const TEntry_Impl& rEntry, const long nSta
void ExtensionBox_Impl::cleanVecListenerAdded()
{
- auto i = m_vListenerAdded.begin();
- while( i != m_vListenerAdded.end())
- {
- const uno::Reference<deployment::XPackage> hardRef(*i);
- if (!hardRef.is())
- i = m_vListenerAdded.erase(i);
- else
- ++i;
- }
+ m_vListenerAdded.erase(std::remove_if(m_vListenerAdded.begin(), m_vListenerAdded.end(),
+ [](const uno::WeakReference<deployment::XPackage>& rxListener) {
+ const uno::Reference<deployment::XPackage> hardRef(rxListener);
+ return !hardRef.is();
+ }),
+ m_vListenerAdded.end());
}
void ExtensionBox_Impl::addEventListenerOnce(
@@ -1003,39 +1000,37 @@ void ExtensionBox_Impl::removeEntry( const uno::Reference< deployment::XPackage
{
::osl::ClearableMutexGuard aGuard( m_entriesMutex );
- for ( auto iIndex = m_vEntries.begin(); iIndex != m_vEntries.end(); ++iIndex )
+ auto iIndex = std::find_if(m_vEntries.begin(), m_vEntries.end(),
+ [&xPackage](const TEntry_Impl& rxEntry) { return rxEntry->m_xPackage == xPackage; });
+ if (iIndex != m_vEntries.end())
{
- if ( (*iIndex)->m_xPackage == xPackage )
+ long nPos = iIndex - m_vEntries.begin();
+
+ // Entries mustn't be removed here, because they contain a hyperlink control
+ // which can only be deleted when the thread has the solar mutex. Therefore
+ // the entry will be moved into the m_vRemovedEntries list which will be
+ // cleared on the next paint event
+ m_vRemovedEntries.push_back( *iIndex );
+ (*iIndex)->m_xPackage->removeEventListener(m_xRemoveListener.get());
+ m_vEntries.erase( iIndex );
+
+ m_bNeedsRecalc = true;
+
+ if ( IsReallyVisible() )
+ invalidate = true;
+
+ if ( m_bHasActive )
{
- long nPos = iIndex - m_vEntries.begin();
-
- // Entries mustn't be removed here, because they contain a hyperlink control
- // which can only be deleted when the thread has the solar mutex. Therefore
- // the entry will be moved into the m_vRemovedEntries list which will be
- // cleared on the next paint event
- m_vRemovedEntries.push_back( *iIndex );
- (*iIndex)->m_xPackage->removeEventListener(m_xRemoveListener.get());
- m_vEntries.erase( iIndex );
-
- m_bNeedsRecalc = true;
-
- if ( IsReallyVisible() )
- invalidate = true;
-
- if ( m_bHasActive )
- {
- if ( nPos < m_nActive )
- m_nActive -= 1;
- else if ( ( nPos == m_nActive ) &&
- ( nPos == static_cast<long>(m_vEntries.size()) ) )
- m_nActive -= 1;
-
- m_bHasActive = false;
- //clear before calling out of this method
- aGuard.clear();
- selectEntry( m_nActive );
- }
- break;
+ if ( nPos < m_nActive )
+ m_nActive -= 1;
+ else if ( ( nPos == m_nActive ) &&
+ ( nPos == static_cast<long>(m_vEntries.size()) ) )
+ m_nActive -= 1;
+
+ m_bHasActive = false;
+ //clear before calling out of this method
+ aGuard.clear();
+ selectEntry( m_nActive );
}
}
}
diff --git a/desktop/source/migration/migration.cxx b/desktop/source/migration/migration.cxx
index bea253cb5c96..7a4476f69319 100644
--- a/desktop/source/migration/migration.cxx
+++ b/desktop/source/migration/migration.cxx
@@ -337,18 +337,11 @@ bool MigrationImpl::checkMigrationCompleted()
static void insertSorted(migrations_available& rAvailableMigrations, supported_migration const & aSupportedMigration)
{
- bool bInserted( false );
- migrations_available::iterator pIter = rAvailableMigrations.begin();
- while (pIter != rAvailableMigrations.end())
- {
- if ( pIter->nPriority < aSupportedMigration.nPriority ) {
- rAvailableMigrations.insert(pIter, aSupportedMigration );
- bInserted = true;
- break; // i111193: insert invalidates iterator!
- }
- ++pIter;
- }
- if ( !bInserted )
+ migrations_available::iterator pIter = std::find_if(rAvailableMigrations.begin(), rAvailableMigrations.end(),
+ [&aSupportedMigration](const supported_migration& rMigration) { return rMigration.nPriority < aSupportedMigration.nPriority; });
+ if (pIter != rAvailableMigrations.end())
+ rAvailableMigrations.insert(pIter, aSupportedMigration );
+ else
rAvailableMigrations.push_back( aSupportedMigration );
}