From 3c7d67a04419345787b7aa6ce9ca13c9ded1ba82 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 17 Aug 2016 09:20:37 +0200 Subject: offscreen plugin: eradicate Q_FOREACH loops ... by replacing them with C++11 for-each loops. In clearHash(), replace iteration over QHash::keys() with iteration over the hash itself. Also use the new const- iterator overload of QHash::erase() to save one attempted detach (in QHash::find()). Mark the plugin as QT_NO_FOREACH. Saves almost 2KiB (1.4%) in text size on optimized GCC 6.1 Linux AMD64 builds. Change-Id: I9bb3154130687c0061ea09b04ab5f627a4d2296c Reviewed-by: Lars Knoll --- src/plugins/platforms/offscreen/offscreen.pro | 2 ++ src/plugins/platforms/offscreen/qoffscreencommon.cpp | 17 ++++++++--------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/plugins/platforms/offscreen/offscreen.pro b/src/plugins/platforms/offscreen/offscreen.pro index cc65449b04..fbaa853c41 100644 --- a/src/plugins/platforms/offscreen/offscreen.pro +++ b/src/plugins/platforms/offscreen/offscreen.pro @@ -2,6 +2,8 @@ TARGET = qoffscreen QT += core-private gui-private platformsupport-private +DEFINES += QT_NO_FOREACH + SOURCES = main.cpp \ qoffscreenintegration.cpp \ qoffscreenwindow.cpp \ diff --git a/src/plugins/platforms/offscreen/qoffscreencommon.cpp b/src/plugins/platforms/offscreen/qoffscreencommon.cpp index a63aacdbfe..85422071aa 100644 --- a/src/plugins/platforms/offscreen/qoffscreencommon.cpp +++ b/src/plugins/platforms/offscreen/qoffscreencommon.cpp @@ -59,9 +59,9 @@ public: void setPos(const QPoint &pos) Q_DECL_OVERRIDE { m_pos = pos; - QWindowList wl = QGuiApplication::topLevelWindows(); + const QWindowList wl = QGuiApplication::topLevelWindows(); QWindow *containing = 0; - foreach (QWindow *w, wl) { + for (QWindow *w : wl) { if (w->type() != Qt::Desktop && w->isExposed() && w->geometry().contains(pos)) { containing = w; break; @@ -104,9 +104,9 @@ QPixmap QOffscreenScreen::grabWindow(WId id, int x, int y, int width, int height QOffscreenWindow *window = QOffscreenWindow::windowForWinId(id); if (!window || window->window()->type() == Qt::Desktop) { - QWindowList wl = QGuiApplication::topLevelWindows(); + const QWindowList wl = QGuiApplication::topLevelWindows(); QWindow *containing = 0; - foreach (QWindow *w, wl) { + for (QWindow *w : wl) { if (w->type() != Qt::Desktop && w->isExposed() && w->geometry().contains(rect)) { containing = w; break; @@ -212,11 +212,10 @@ QOffscreenBackingStore *QOffscreenBackingStore::backingStoreForWinId(WId id) void QOffscreenBackingStore::clearHash() { - QList ids = m_windowAreaHash.keys(); - foreach (WId id, ids) { - QHash::iterator it = m_backingStoreForWinIdHash.find(id); - if (it.value() == this) - m_backingStoreForWinIdHash.remove(id); + for (auto it = m_windowAreaHash.cbegin(), end = m_windowAreaHash.cend(); it != end; ++it) { + const auto it2 = qAsConst(m_backingStoreForWinIdHash).find(it.key()); + if (it2.value() == this) + m_backingStoreForWinIdHash.erase(it2); } m_windowAreaHash.clear(); } -- cgit v1.2.3