From 035ea75ab78c362493db67ab41349ff7238878ca Mon Sep 17 00:00:00 2001 From: Aleix Pol Date: Thu, 13 May 2021 18:41:39 +0200 Subject: [PATCH] Use qAsConst in fors when there's a risk for it to detach --- src/abstract_client.cpp | 8 ++++---- src/deleted.cpp | 2 +- src/effectloader.cpp | 2 +- src/effects.cpp | 2 +- src/effects/cubeslide/cubeslide.cpp | 4 ++-- src/effects/desktopgrid/desktopgrid.cpp | 6 +++--- src/effects/slide/slide.cpp | 2 +- src/globalshortcuts.cpp | 2 +- src/kcmkwin/common/effectsmodel.cpp | 4 ++-- src/layers.cpp | 4 ++-- src/main_wayland.cpp | 2 +- src/platformsupport/scenes/opengl/egl_dmabuf.cpp | 2 +- src/plugins/platforms/drm/drm_gpu.cpp | 2 +- src/plugins/platforms/drm/drm_object.cpp | 4 +--- src/plugins/platforms/drm/drm_output.cpp | 4 ++-- src/plugins/platforms/wayland/egl_wayland_backend.cpp | 2 +- src/plugins/platforms/wayland/wayland_backend.cpp | 4 ++-- src/plugins/qpa/integration.cpp | 2 +- src/scripting/scripting.cpp | 6 +++--- src/virtualdesktops.cpp | 4 ++-- src/workspace.cpp | 6 +++--- src/xwl/dnd.cpp | 2 +- src/xwl/drag_x.cpp | 2 +- src/xwl/selection.cpp | 10 +++++----- src/xwl/selection_source.cpp | 6 +++--- 25 files changed, 46 insertions(+), 48 deletions(-) diff --git a/src/abstract_client.cpp b/src/abstract_client.cpp index 0ee0d7251d..7cb0f28062 100644 --- a/src/abstract_client.cpp +++ b/src/abstract_client.cpp @@ -458,14 +458,14 @@ void AbstractClient::setDesktops(QVector desktops) } else { windowManagementInterface()->setOnAllDesktops(false); auto currentDesktops = windowManagementInterface()->plasmaVirtualDesktops(); - for (auto desktop: m_desktops) { + for (auto desktop: qAsConst(m_desktops)) { if (!currentDesktops.contains(desktop->id())) { windowManagementInterface()->addPlasmaVirtualDesktop(desktop->id()); } else { currentDesktops.removeOne(desktop->id()); } } - for (auto desktopId: currentDesktops) { + for (const auto &desktopId: qAsConst(currentDesktops)) { windowManagementInterface()->removePlasmaVirtualDesktop(desktopId); } } @@ -1637,7 +1637,7 @@ void AbstractClient::setupWindowManagementInterface() } ); - for (const auto vd : m_desktops) { + for (const auto vd : qAsConst(m_desktops)) { w->addPlasmaVirtualDesktop(vd->id()); } @@ -1678,7 +1678,7 @@ void AbstractClient::setupWindowManagementInterface() } ); - for (const auto &activity : m_activityList) { + for (const auto &activity : qAsConst(m_activityList)) { w->addPlasmaActivity(activity); } diff --git a/src/deleted.cpp b/src/deleted.cpp index d9104c8d61..5a4b7ec8bf 100644 --- a/src/deleted.cpp +++ b/src/deleted.cpp @@ -113,7 +113,7 @@ void Deleted::copyToDeleted(Toplevel* c) m_caption = client->caption(); } - for (auto vd : m_desktops) { + for (auto vd : qAsConst(m_desktops)) { connect(vd, &QObject::destroyed, this, [=] { m_desktops.removeOne(vd); }); diff --git a/src/effectloader.cpp b/src/effectloader.cpp index e1063155dc..bc3185e37a 100644 --- a/src/effectloader.cpp +++ b/src/effectloader.cpp @@ -262,7 +262,7 @@ void ScriptedEffectLoader::queryAndLoadAll() m_queryConnection = connect(watcher, &QFutureWatcher>::finished, this, [this, watcher]() { const auto effects = watcher->result(); - for (auto effect : effects) { + for (const auto &effect : effects) { const LoadEffectFlags flags = readConfig(effect.pluginId(), effect.isEnabledByDefault()); if (flags.testFlag(LoadEffectFlag::Load)) { m_queue->enqueue(qMakePair(effect, flags)); diff --git a/src/effects.cpp b/src/effects.cpp index 92dd0d8809..9a1b358409 100644 --- a/src/effects.cpp +++ b/src/effects.cpp @@ -271,7 +271,7 @@ EffectsHandlerImpl::~EffectsHandlerImpl() void EffectsHandlerImpl::unloadAllEffects() { - for (const EffectPair &pair : loaded_effects) { + for (const EffectPair &pair : qAsConst(loaded_effects)) { destroyEffect(pair.second); } diff --git a/src/effects/cubeslide/cubeslide.cpp b/src/effects/cubeslide/cubeslide.cpp index 3ed7c46618..aab4674f48 100644 --- a/src/effects/cubeslide/cubeslide.cpp +++ b/src/effects/cubeslide/cubeslide.cpp @@ -377,7 +377,7 @@ void CubeSlideEffect::postPaintScreen() else timeLine.setEasingCurve(QEasingCurve::Linear); if (slideRotations.empty()) { - for (EffectWindow* w : staticWindows) { + for (EffectWindow* w : qAsConst(staticWindows)) { w->setData(WindowForceBlurRole, QVariant()); w->setData(WindowForceBackgroundContrastRole, QVariant()); } @@ -654,7 +654,7 @@ void CubeSlideEffect::slotNumberDesktopsChanged() return; } - for (EffectWindow *w : staticWindows) { + for (EffectWindow *w : qAsConst(staticWindows)) { w->setData(WindowForceBlurRole, QVariant()); w->setData(WindowForceBackgroundContrastRole, QVariant()); } diff --git a/src/effects/desktopgrid/desktopgrid.cpp b/src/effects/desktopgrid/desktopgrid.cpp index 61dfb9fc1e..7de79aac05 100644 --- a/src/effects/desktopgrid/desktopgrid.cpp +++ b/src/effects/desktopgrid/desktopgrid.cpp @@ -199,7 +199,7 @@ void DesktopGridEffect::paintScreen(int mask, const QRegion ®ion, ScreenPaint } // paint the add desktop button - for (EffectQuickScene *view : m_desktopButtons) { + for (EffectQuickScene *view : qAsConst(m_desktopButtons)) { view->rootItem()->setOpacity(timeline.currentValue()); effects->renderEffectQuickView(view); } @@ -474,7 +474,7 @@ void DesktopGridEffect::windowInputMouseEvent(QEvent* e) return; QMouseEvent* me = static_cast< QMouseEvent* >(e); if (!(wasWindowMove || wasDesktopMove)) { - for (EffectQuickScene *view : m_desktopButtons) { + for (EffectQuickScene *view : qAsConst(m_desktopButtons)) { view->forwardMouseEvent(me); if (e->isAccepted()) { return; @@ -1062,7 +1062,7 @@ void DesktopGridEffect::setActive(bool active) [this] { if (activated) return; - for (EffectQuickScene *view : m_desktopButtons) { + for (EffectQuickScene *view : qAsConst(m_desktopButtons)) { view->hide(); } } diff --git a/src/effects/slide/slide.cpp b/src/effects/slide/slide.cpp index 0b9203aff4..ddbbce236b 100644 --- a/src/effects/slide/slide.cpp +++ b/src/effects/slide/slide.cpp @@ -391,7 +391,7 @@ void SlideEffect::stop() w->setData(WindowForceBlurRole, QVariant()); } - for (EffectWindow *w : m_elevatedWindows) { + for (EffectWindow *w : qAsConst(m_elevatedWindows)) { effects->setElevatedWindow(w, false); } m_elevatedWindows.clear(); diff --git a/src/globalshortcuts.cpp b/src/globalshortcuts.cpp index 3e67318342..c90c2d6da2 100644 --- a/src/globalshortcuts.cpp +++ b/src/globalshortcuts.cpp @@ -105,7 +105,7 @@ void GlobalShortcutsManager::objectDeleted(QObject *object) bool GlobalShortcutsManager::addIfNotExists(GlobalShortcut sc) { - for (const auto &cs : m_shortcuts) { + for (const auto &cs : qAsConst(m_shortcuts)) { if (sc.shortcut() == cs.shortcut()) { return false; } diff --git a/src/kcmkwin/common/effectsmodel.cpp b/src/kcmkwin/common/effectsmodel.cpp index 123ea04c0b..9904200a80 100644 --- a/src/kcmkwin/common/effectsmodel.cpp +++ b/src/kcmkwin/common/effectsmodel.cpp @@ -416,7 +416,7 @@ void EffectsModel::load(LoadOptions options) auto commit = [this, options] { if (options == LoadOptions::KeepDirty) { - for (const EffectData &oldEffect : m_effects) { + for (const EffectData &oldEffect : qAsConst(m_effects)) { if (!oldEffect.changed) { continue; } @@ -448,7 +448,7 @@ void EffectsModel::load(LoadOptions options) if (interface.isValid()) { QStringList effectNames; effectNames.reserve(m_pendingEffects.count()); - for (const EffectData &data : m_pendingEffects) { + for (const EffectData &data : qAsConst(m_pendingEffects)) { effectNames.append(data.serviceName); } diff --git a/src/layers.cpp b/src/layers.cpp index 1f7933c775..27d4449f73 100644 --- a/src/layers.cpp +++ b/src/layers.cpp @@ -197,7 +197,7 @@ void Workspace::propagateClients(bool propagate_new_clients) xcb_window_t *cl(nullptr); if (propagate_new_clients) { cl = new xcb_window_t[ manual_overlays.count() + clients.count()]; - for (const auto win : manual_overlays) { + for (const auto win : qAsConst(manual_overlays)) { cl[pos++] = win; } for (auto it = clients.constBegin(); it != clients.constEnd(); ++it) @@ -214,7 +214,7 @@ void Workspace::propagateClients(bool propagate_new_clients) cl[pos++] = client->window(); } } - for (const auto win : manual_overlays) { + for (const auto win : qAsConst(manual_overlays)) { cl[pos++] = win; } rootInfo()->setClientListStacking(cl, pos); diff --git a/src/main_wayland.cpp b/src/main_wayland.cpp index cb3fc2ac35..fa1f2958c6 100644 --- a/src/main_wayland.cpp +++ b/src/main_wayland.cpp @@ -265,7 +265,7 @@ void ApplicationWayland::startSession() } // start the applications passed to us as command line arguments if (!m_applicationsToStart.isEmpty()) { - for (const QString &application: m_applicationsToStart) { + for (const QString &application: qAsConst(m_applicationsToStart)) { QStringList arguments = KShell::splitArgs(application); if (arguments.isEmpty()) { qWarning("Failed to launch application: %s is an invalid command", diff --git a/src/platformsupport/scenes/opengl/egl_dmabuf.cpp b/src/platformsupport/scenes/opengl/egl_dmabuf.cpp index d235e73926..5bc8495ec0 100644 --- a/src/platformsupport/scenes/opengl/egl_dmabuf.cpp +++ b/src/platformsupport/scenes/opengl/egl_dmabuf.cpp @@ -162,7 +162,7 @@ void EglDmabufBuffer::addImage(EGLImage image) void EglDmabufBuffer::removeImages() { - for (auto image : m_images) { + for (auto image : qAsConst(m_images)) { eglDestroyImageKHR(m_interfaceImpl->m_backend->eglDisplay(), image); } m_images.clear(); diff --git a/src/plugins/platforms/drm/drm_gpu.cpp b/src/plugins/platforms/drm/drm_gpu.cpp index 9b31bb193e..103b980030 100644 --- a/src/plugins/platforms/drm/drm_gpu.cpp +++ b/src/plugins/platforms/drm/drm_gpu.cpp @@ -323,7 +323,7 @@ DrmOutput *DrmGpu::findOutput(quint32 connector) DrmPlane *DrmGpu::getCompatiblePlane(DrmPlane::TypeIndex typeIndex, DrmCrtc *crtc) { - for (auto plane : m_unusedPlanes) { + for (auto plane : qAsConst(m_unusedPlanes)) { if (plane->type() != typeIndex) { continue; } diff --git a/src/plugins/platforms/drm/drm_object.cpp b/src/plugins/platforms/drm/drm_object.cpp index 54d7aa3e37..e0a8e4f8a1 100644 --- a/src/plugins/platforms/drm/drm_object.cpp +++ b/src/plugins/platforms/drm/drm_object.cpp @@ -27,9 +27,7 @@ DrmObject::DrmObject(DrmGpu *gpu, uint32_t objectId) DrmObject::~DrmObject() { - for (auto *p : m_props) { - delete p; - } + qDeleteAll(m_props); } bool DrmObject::initProps(const QVector &&vector, uint32_t objectType) diff --git a/src/plugins/platforms/drm/drm_output.cpp b/src/plugins/platforms/drm/drm_output.cpp index bba4ce3f2d..a396f1b824 100644 --- a/src/plugins/platforms/drm/drm_output.cpp +++ b/src/plugins/platforms/drm/drm_output.cpp @@ -595,7 +595,7 @@ void DrmOutput::pageFlipped() return; } if (m_gpu->atomicModeSetting()) { - for (DrmPlane *p : m_nextPlanesFlipList) { + for (DrmPlane *p : qAsConst(m_nextPlanesFlipList)) { p->flipBuffer(); } m_nextPlanesFlipList.clear(); @@ -770,7 +770,7 @@ bool DrmOutput::doAtomicCommit(AtomicCommitMode mode) } // TODO: see above, rework later for overlay planes! - for (DrmPlane *p : m_nextPlanesFlipList) { + for (DrmPlane *p : qAsConst(m_nextPlanesFlipList)) { p->setNext(nullptr); } m_nextPlanesFlipList.clear(); diff --git a/src/plugins/platforms/wayland/egl_wayland_backend.cpp b/src/plugins/platforms/wayland/egl_wayland_backend.cpp index 8c7f0b113b..e5a3fcd84b 100644 --- a/src/plugins/platforms/wayland/egl_wayland_backend.cpp +++ b/src/plugins/platforms/wayland/egl_wayland_backend.cpp @@ -125,7 +125,7 @@ EglWaylandBackend::~EglWaylandBackend() void EglWaylandBackend::cleanupSurfaces() { - for (auto o : m_outputs) { + for (auto o : qAsConst(m_outputs)) { cleanupOutput(o); } m_outputs.clear(); diff --git a/src/plugins/platforms/wayland/wayland_backend.cpp b/src/plugins/platforms/wayland/wayland_backend.cpp index 5a99d43dde..16ea571f3b 100644 --- a/src/plugins/platforms/wayland/wayland_backend.cpp +++ b/src/plugins/platforms/wayland/wayland_backend.cpp @@ -811,7 +811,7 @@ void WaylandBackend::togglePointerLock() return; } - for (auto output : m_outputs) { + for (auto output : qAsConst(m_outputs)) { output->lockPointer(m_seat->pointer(), !m_pointerLockRequested); } m_pointerLockRequested = !m_pointerLockRequested; @@ -820,7 +820,7 @@ void WaylandBackend::togglePointerLock() bool WaylandBackend::pointerIsLocked() { - for (auto *output : m_outputs) { + for (auto *output : qAsConst(m_outputs)) { if (output->pointerIsLocked()) { return true; } diff --git a/src/plugins/qpa/integration.cpp b/src/plugins/qpa/integration.cpp index 8c14b2b0c4..aea9f3d9cb 100644 --- a/src/plugins/qpa/integration.cpp +++ b/src/plugins/qpa/integration.cpp @@ -45,7 +45,7 @@ Integration::Integration() Integration::~Integration() { - for (QPlatformScreen *platformScreen : m_screens) { + for (QPlatformScreen *platformScreen : qAsConst(m_screens)) { QWindowSystemInterface::handleScreenRemoved(platformScreen); } if (m_dummyScreen) { diff --git a/src/scripting/scripting.cpp b/src/scripting/scripting.cpp index 840ac245c1..7d3fa0ed4f 100644 --- a/src/scripting/scripting.cpp +++ b/src/scripting/scripting.cpp @@ -425,8 +425,8 @@ QList KWin::Script::actionsForUserActionMenu(KWin::AbstractClient *cl QList actions; actions.reserve(m_userActionsMenuCallbacks.count()); - for (QJSValue callback : m_userActionsMenuCallbacks) { - QJSValue result = callback.call({ m_engine->toScriptValue(client) }); + for (QJSValue callback : qAsConst(m_userActionsMenuCallbacks)) { + const QJSValue result = callback.call({ m_engine->toScriptValue(client) }); if (result.isError()) { continue; } @@ -813,7 +813,7 @@ KWin::Scripting::~Scripting() QList< QAction * > KWin::Scripting::actionsForUserActionMenu(KWin::AbstractClient *c, QMenu *parent) { QList actions; - for (AbstractScript *s : scripts) { + for (AbstractScript *s : qAsConst(scripts)) { // TODO: Allow declarative scripts to add their own user actions. if (Script *script = qobject_cast