diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2019-05-17 11:07:02 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2019-05-21 10:48:37 +0200 |
commit | 5f2e1d94c07c3d4d2f0f24598f8ab385fad3b74c (patch) | |
tree | 9fbf0dadcbee835e367952aff84e41055de9f230 /src/compositor/extensions/qwaylandxdgshellv5.cpp | |
parent | 7107f7501df329cf785cec1585767e5d7cbab6c2 (diff) | |
download | qtwayland-5f2e1d94c07c3d4d2f0f24598f8ab385fad3b74c.tar.gz |
Eradicate Q_FOREACH loops [1/2]: trivial cases
In this patch, we port Q_FOREACH loops to C++11 ranged-for loops. All cases are
trivial in the sense that either the argument is already const or is trivially
marked as const, either by qAsConst(), or, in the case of rvalues, by storing
to a const auto temporary first.
In addition, all loop bodies are clear enough to confirm that the container we
iterate over is not changed under iteration. This does not exclude cases where
a loop is prematurely exited just after calling a modifier on the container, as
that is safe, if not especially elegant.
Change-Id: I87a63f07797437d421567d60e52305391a3c4f21
Reviewed-by: Johan Helsing <johan.helsing@qt.io>
Diffstat (limited to 'src/compositor/extensions/qwaylandxdgshellv5.cpp')
-rw-r--r-- | src/compositor/extensions/qwaylandxdgshellv5.cpp | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/src/compositor/extensions/qwaylandxdgshellv5.cpp b/src/compositor/extensions/qwaylandxdgshellv5.cpp index a85efbc5..eebfab6d 100644 --- a/src/compositor/extensions/qwaylandxdgshellv5.cpp +++ b/src/compositor/extensions/qwaylandxdgshellv5.cpp @@ -414,7 +414,7 @@ void QWaylandXdgSurfaceV5Private::xdg_surface_ack_configure(Resource *resource, break; } - QVector<uint> changedStates; + std::vector<uint> changedStates; std::set_symmetric_difference( m_lastAckedConfigure.states.begin(), m_lastAckedConfigure.states.end(), config.states.begin(), config.states.end(), @@ -423,7 +423,7 @@ void QWaylandXdgSurfaceV5Private::xdg_surface_ack_configure(Resource *resource, m_lastAckedConfigure = config; if (!changedStates.empty()) { - Q_FOREACH (uint state, changedStates) { + for (uint state : changedStates) { switch (state) { case QWaylandXdgSurfaceV5::State::MaximizedState: emit q->maximizedChanged(); @@ -580,7 +580,7 @@ void QWaylandXdgShellV5::initialize() QWaylandClient *QWaylandXdgShellV5::popupClient() const { Q_D(const QWaylandXdgShellV5); - Q_FOREACH (QWaylandXdgPopupV5 *popup, d->m_xdgPopups) { + for (QWaylandXdgPopupV5 *popup : d->m_xdgPopups) { if (popup->surface()->hasContent()) return popup->surface()->client(); } @@ -987,7 +987,9 @@ void QWaylandXdgSurfaceV5::initialize() QList<int> QWaylandXdgSurfaceV5::statesAsInts() const { QList<int> list; - Q_FOREACH (uint state, states()) { + const auto s = states(); + list.reserve(s.size()); + for (auto state : s) { list << static_cast<int>(state); } return list; @@ -1238,7 +1240,8 @@ uint QWaylandXdgSurfaceV5::sendConfigure(const QSize &size, const QVector<uint> uint QWaylandXdgSurfaceV5::sendConfigure(const QSize &size, const QVector<QWaylandXdgSurfaceV5::State> &states) { QVector<uint> asUints; - Q_FOREACH (QWaylandXdgSurfaceV5::State state, states) { + asUints.reserve(states.size()); + for (QWaylandXdgSurfaceV5::State state : states) { asUints << state; } return sendConfigure(size, asUints); |