Use qAsConst in fors when there's a risk for it to detach

This commit is contained in:
Aleix Pol 2021-05-13 18:41:39 +02:00
parent 50dd08531e
commit 035ea75ab7
25 changed files with 46 additions and 48 deletions

View file

@ -458,14 +458,14 @@ void AbstractClient::setDesktops(QVector<VirtualDesktop*> 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);
}

View file

@ -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);
});

View file

@ -262,7 +262,7 @@ void ScriptedEffectLoader::queryAndLoadAll()
m_queryConnection = connect(watcher, &QFutureWatcher<QList<KPluginMetaData>>::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));

View file

@ -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);
}

View file

@ -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());
}

View file

@ -199,7 +199,7 @@ void DesktopGridEffect::paintScreen(int mask, const QRegion &region, 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();
}
}

View file

@ -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();

View file

@ -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;
}

View file

@ -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);
}

View file

@ -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);

View file

@ -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",

View file

@ -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();

View file

@ -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;
}

View file

@ -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<PropertyDefinition> &&vector, uint32_t objectType)

View file

@ -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();

View file

@ -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();

View file

@ -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;
}

View file

@ -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) {

View file

@ -425,8 +425,8 @@ QList<QAction *> KWin::Script::actionsForUserActionMenu(KWin::AbstractClient *cl
QList<QAction *> 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<QAction*> 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<Script *>(s)) {
actions << script->actionsForUserActionMenu(c, parent);

View file

@ -242,7 +242,7 @@ void VirtualDesktopManager::setRootInfo(NETRootInfo *info)
m_rootInfo->setDesktopLayout(NET::OrientationHorizontal, columns, m_rows, NET::DesktopLayoutCornerTopLeft);
updateRootInfo();
m_rootInfo->setCurrentDesktop(currentDesktop()->x11DesktopNumber());
for (auto *vd : m_desktops) {
for (auto *vd : qAsConst(m_desktops)) {
m_rootInfo->setDesktopName(vd->x11DesktopNumber(), vd->name().toUtf8().data());
}
}
@ -611,7 +611,7 @@ void VirtualDesktopManager::setCount(uint count)
if (!s_loadingDesktopSettings) {
save();
}
for (auto vd : newDesktops) {
for (auto vd : qAsConst(newDesktops)) {
emit desktopCreated(vd);
}
emit countChanged(oldCount, m_desktops.count());

View file

@ -1019,7 +1019,7 @@ void Workspace::slotReconfigure()
updateToolWindows(true);
RuleBook::self()->load();
for (AbstractClient *client : m_allClients) {
for (AbstractClient *client : qAsConst(m_allClients)) {
if (client->supportsWindowRules()) {
client->evaluateWindowRules();
RuleBook::self()->discardUsed(client, false);
@ -1030,8 +1030,8 @@ void Workspace::slotReconfigure()
!options->borderlessMaximizedWindows()) {
// in case borderless maximized windows option changed and new option
// is to have borders, we need to unset the borders for all maximized windows
for (auto it = m_allClients.begin();
it != m_allClients.end();
for (auto it = m_allClients.cbegin();
it != m_allClients.cend();
++it) {
if ((*it)->maximizeMode() == MaximizeFull)
(*it)->checkNoBorder();

View file

@ -158,7 +158,7 @@ void Dnd::x11OffersChanged(const QStringList &added, const QStringList &removed)
bool Dnd::handleClientMessage(xcb_client_message_event_t *event)
{
for (Drag *drag : m_oldDrags) {
for (Drag *drag : qAsConst(m_oldDrags)) {
if (drag->handleClientMessage(event)) {
return true;
}

View file

@ -181,7 +181,7 @@ DragEventReply XToWlDrag::moveFilter(Toplevel *target, const QPoint &pos)
bool XToWlDrag::handleClientMessage(xcb_client_message_event_t *event)
{
for (auto *visit : m_oldVisits) {
for (auto *visit : qAsConst(m_oldVisits)) {
if (visit->handleClientMessage(event)) {
return true;
}

View file

@ -250,7 +250,7 @@ bool Selection::handleSelectionNotify(xcb_selection_notify_event_t *event)
if (m_xSource && m_xSource->handleSelectionNotify(event)) {
return true;
}
for (TransferXtoWl *transfer : m_xToWlTransfers) {
for (TransferXtoWl *transfer : qAsConst(m_xToWlTransfers)) {
if (transfer->handleSelectionNotify(event)) {
return true;
}
@ -260,12 +260,12 @@ bool Selection::handleSelectionNotify(xcb_selection_notify_event_t *event)
bool Selection::handlePropertyNotify(xcb_property_notify_event_t *event)
{
for (TransferXtoWl *transfer : m_xToWlTransfers) {
for (TransferXtoWl *transfer : qAsConst(m_xToWlTransfers)) {
if (transfer->handlePropertyNotify(event)) {
return true;
}
}
for (TransferWltoX *transfer : m_wlToXTransfers) {
for (TransferWltoX *transfer : qAsConst(m_wlToXTransfers)) {
if (transfer->handlePropertyNotify(event)) {
return true;
}
@ -339,10 +339,10 @@ void Selection::endTimeoutTransfersTimer()
void Selection::timeoutTransfers()
{
for (TransferXtoWl *transfer : m_xToWlTransfers) {
for (TransferXtoWl *transfer : qAsConst(m_xToWlTransfers)) {
transfer->timeout();
}
for (TransferWltoX *transfer : m_wlToXTransfers) {
for (TransferWltoX *transfer : qAsConst(m_wlToXTransfers)) {
transfer->timeout();
}
}

View file

@ -92,7 +92,7 @@ void WlSource::sendTargets(xcb_selection_request_event_t *event)
targets[1] = atoms->targets;
size_t cnt = 2;
for (const auto &mime : m_offers) {
for (const auto &mime : qAsConst(m_offers)) {
targets[cnt] = Selection::mimeTypeToAtom(mime);
cnt++;
}
@ -238,7 +238,7 @@ void X11Source::handleTargets()
all << mimePair;
}
// all left in m_offers are not in the updated targets
for (const auto &mimePair : m_offers) {
for (const auto &mimePair : qAsConst(m_offers)) {
removed << mimePair.first;
}
m_offers = all;
@ -259,7 +259,7 @@ void X11Source::setDataSource(KWayland::Client::DataSource *dataSource)
m_dataSource = dataSource;
for (const Mime &offer : m_offers) {
for (const Mime &offer : qAsConst(m_offers)) {
dataSource->offer(offer.first);
}