diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2016-08-17 09:20:37 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2016-08-27 05:09:20 +0000 |
commit | 3c7d67a04419345787b7aa6ce9ca13c9ded1ba82 (patch) | |
tree | 5f9cf85cf0270f755576076d03dfe0940f6a1c1f /src/plugins/platforms | |
parent | efcae5d5caefcaf86bfb76fce7d4d1a5c4229753 (diff) |
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 <lars.knoll@qt.io>
Diffstat (limited to 'src/plugins/platforms')
-rw-r--r-- | src/plugins/platforms/offscreen/offscreen.pro | 2 | ||||
-rw-r--r-- | 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<WId> ids = m_windowAreaHash.keys(); - foreach (WId id, ids) { - QHash<WId, QOffscreenBackingStore *>::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(); } |