InterfaceTree: Change foreach to const_iterator

Change all occurences of the foreach macro to while loops with
const_iterator for performance reasons

Change-Id: I1cd378696136b3d6cc100b9bfff95295baa2ff83
Reviewed-on: https://code.wireshark.org/review/18286
Reviewed-by: Anders Broman <a.broman58@gmail.com>
This commit is contained in:
Roland Knall 2016-10-18 22:28:28 +02:00 committed by Anders Broman
parent 864f750be5
commit e68247e1fd
3 changed files with 36 additions and 17 deletions

View File

@ -116,17 +116,21 @@ QMenu * InterfaceFrame::getSelectionMenu()
QMenu * contextMenu = new QMenu();
QList<int> typesDisplayed = proxyModel->typesDisplayed();
foreach(int ifType, ifTypeDescription.keys())
QMap<int, QString>::const_iterator it = ifTypeDescription.constBegin();
while(it != ifTypeDescription.constEnd())
{
if ( ! typesDisplayed.contains(ifType) )
continue;
int ifType = it.key();
QAction *endp_action = new QAction(ifTypeDescription[ifType], this);
endp_action->setData(qVariantFromValue(ifType));
endp_action->setCheckable(true);
endp_action->setChecked(proxyModel->isInterfaceTypeShown(ifType));
connect(endp_action, SIGNAL(triggered()), this, SLOT(triggeredIfTypeButton()));
contextMenu->addAction(endp_action);
if ( typesDisplayed.contains(ifType) )
{
QAction *endp_action = new QAction(it.value(), this);
endp_action->setData(qVariantFromValue(ifType));
endp_action->setCheckable(true);
endp_action->setChecked(proxyModel->isInterfaceTypeShown(ifType));
connect(endp_action, SIGNAL(triggered()), this, SLOT(triggeredIfTypeButton()));
contextMenu->addAction(endp_action);
}
++it;
}
return contextMenu;

View File

@ -71,11 +71,13 @@ void InterfaceSortFilterModel::resetPreferenceData()
if ( stored_prefs.length() > 0 )
{
QStringList ifTypesStored = stored_prefs.split(',');
foreach(QString val, ifTypesStored)
QStringList::const_iterator it = ifTypesStored.constBegin();
while(it != ifTypesStored.constEnd())
{
int i_val = val.toInt();
int i_val = (*it).toInt();
if ( ! displayHiddenTypes.contains(i_val) )
displayHiddenTypes.append(i_val);
++it;
}
}
@ -135,9 +137,11 @@ void InterfaceSortFilterModel::setInterfaceTypeVisible(int ifType, bool visible)
return;
QString new_pref;
foreach(int i, displayHiddenTypes)
QList<int>::const_iterator it = displayHiddenTypes.constBegin();
while( it != displayHiddenTypes.constEnd() )
{
new_pref.append(QString("%1,").arg(i));
new_pref.append(QString("%1,").arg(*it));
++it;
}
if (new_pref.length() > 0)
new_pref = new_pref.left(new_pref.length() - 1);

View File

@ -253,8 +253,12 @@ void InterfaceTreeModel::interfaceListChanged()
{
emit beginResetModel();
foreach(QString key, points.keys())
points[key]->clear();
QMap<QString, PointList *>::const_iterator it = points.constBegin();
while(it != points.constEnd())
{
it.value()->clear();
++it;
}
points.clear();
emit endResetModel();
@ -412,15 +416,22 @@ bool InterfaceTreeModel::updateSelectedDevices(QItemSelection sourceSelection)
#ifdef HAVE_LIBPCAP
QList<int> selectedIndices;
foreach(QItemSelectionRange selection, sourceSelection)
QItemSelection::const_iterator it = sourceSelection.constBegin();
while(it != sourceSelection.constEnd())
{
foreach(QModelIndex index, selection.indexes())
QModelIndexList indeces = ((QItemSelectionRange) (*it)).indexes();
QModelIndexList::const_iterator cit = indeces.constBegin();
while(cit != indeces.constEnd())
{
QModelIndex index = (QModelIndex) (*cit);
if ( ! selectedIndices.contains(index.row()) )
{
selectedIndices.append(index.row());
}
++cit;
}
++it;
}
global_capture_opts.num_selected = 0;