From f9de9eae3ab4ada318de1b1a2e64a0f76d6a0c52 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sat, 17 Oct 2015 23:22:29 +0200 Subject: [PATCH] Replace backwards Java-style iteration with new reverse_iterators Faster, and, thanks to the new reverse_iterators, just as convenient. Change-Id: Ibc6c64051a8ede4a47428e9271ffbeaa921fc255 Reviewed-by: Friedemann Kleint Reviewed-by: David Faure --- src/corelib/mimetypes/qmimeprovider.cpp | 7 ++----- src/widgets/widgets/qmenu.cpp | 7 +++---- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/corelib/mimetypes/qmimeprovider.cpp b/src/corelib/mimetypes/qmimeprovider.cpp index ebaa1b069c..e0fe144c26 100644 --- a/src/corelib/mimetypes/qmimeprovider.cpp +++ b/src/corelib/mimetypes/qmimeprovider.cpp @@ -578,11 +578,8 @@ void QMimeBinaryProvider::loadMimeTypePrivate(QMimeTypePrivate &data) QString mainPattern; const QString preferredLanguage = QLocale::system().name(); - QListIterator mimeFilesIter(mimeFiles); - mimeFilesIter.toBack(); - while (mimeFilesIter.hasPrevious()) { // global first, then local. - const QString fullPath = mimeFilesIter.previous(); - QFile qfile(fullPath); + for (QStringList::const_reverse_iterator it = mimeFiles.crbegin(), end = mimeFiles.crend(); it != end; ++it) { // global first, then local. + QFile qfile(*it); if (!qfile.open(QFile::ReadOnly)) continue; diff --git a/src/widgets/widgets/qmenu.cpp b/src/widgets/widgets/qmenu.cpp index b29d7de5f5..27e977f027 100644 --- a/src/widgets/widgets/qmenu.cpp +++ b/src/widgets/widgets/qmenu.cpp @@ -192,11 +192,10 @@ void QMenuPrivate::syncPlatformMenu() return; QPlatformMenuItem *beforeItem = Q_NULLPTR; - QListIterator it(q->actions()); - it.toBack(); - while (it.hasPrevious()) { + const QList actions = q->actions(); + for (QList::const_reverse_iterator it = actions.rbegin(), end = actions.rend(); it != end; ++it) { QPlatformMenuItem *menuItem = platformMenu->createMenuItem(); - QAction *action = it.previous(); + QAction *action = *it; menuItem->setTag(reinterpret_cast(action)); QObject::connect(menuItem, SIGNAL(activated()), action, SLOT(trigger()), Qt::QueuedConnection); QObject::connect(menuItem, SIGNAL(hovered()), action, SIGNAL(hovered()), Qt::QueuedConnection);