Commit 66a0c467 authored by Alexander Volkov's avatar Alexander Volkov

Avoid creation of needless temporary containers

Summary: Found by clazy.

Reviewers: #plasma, broulik

Reviewed By: #plasma, broulik

Subscribers: broulik, plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D15946
parent f5d9943e
......@@ -60,10 +60,12 @@ KWayland::Client::OutputDevice::Transform WaylandOutput::toKWaylandTransform(con
QString WaylandOutput::toKScreenModeId(int kwaylandmodeid) const
{
if (!m_modeIdMap.values().contains(kwaylandmodeid)) {
auto it = std::find(m_modeIdMap.constBegin(), m_modeIdMap.constEnd(), kwaylandmodeid);
if (it == m_modeIdMap.constEnd()) {
qCWarning(KSCREEN_WAYLAND) << "Invalid kwayland mode id:" << kwaylandmodeid << m_modeIdMap;
return QStringLiteral("invalid_mode_id");
}
return m_modeIdMap.key(kwaylandmodeid, QStringLiteral("invalid_mode_id"));
return it.key();
}
int WaylandOutput::toKWaylandModeId(const QString &kscreenmodeid) const
......@@ -143,7 +145,7 @@ void WaylandOutput::updateKScreenOutput(KScreen::OutputPtr &output)
qCDebug(KSCREEN_WAYLAND) << "Could not create mode id from" << m.id << ", using" << modename << "instead.";
modeid = modename;
}
if (m_modeIdMap.keys().contains(modeid)) {
if (m_modeIdMap.contains(modeid)) {
qCWarning(KSCREEN_WAYLAND) << "Mode id already in use:" << modeid;
}
......
......@@ -44,9 +44,7 @@ QScreenConfig::QScreenConfig(QObject *parent)
QScreenConfig::~QScreenConfig()
{
foreach(auto output, m_outputMap.values()) {
delete output;
}
qDeleteAll(m_outputMap);
}
ConfigPtr QScreenConfig::toKScreenConfig() const
......@@ -60,7 +58,7 @@ ConfigPtr QScreenConfig::toKScreenConfig() const
int QScreenConfig::outputId(const QScreen *qscreen)
{
QList<int> ids;
foreach(auto output, m_outputMap.values()) {
foreach(auto output, m_outputMap) {
if (qscreen == output->qscreen()) {
return output->id();
}
......@@ -86,7 +84,7 @@ void QScreenConfig::screenRemoved(QScreen *qscreen)
qCDebug(KSCREEN_QSCREEN) << "Screen removed" << qscreen << QGuiApplication::screens().count();
// Find output matching the QScreen object and remove it
int removedOutputId = -1;
foreach(auto output, m_outputMap.values()) {
foreach(auto output, m_outputMap) {
if (output->qscreen() == qscreen) {
removedOutputId = output->id();
m_outputMap.remove(removedOutputId);
......@@ -105,14 +103,14 @@ void QScreenConfig::updateKScreenConfig(ConfigPtr &config) const
//Removing removed outputs
KScreen::OutputList outputs = config->outputs();
Q_FOREACH(const KScreen::OutputPtr &output, outputs) {
if (!m_outputMap.keys().contains(output->id())) {
if (!m_outputMap.contains(output->id())) {
config->removeOutput(output->id());
}
}
// Add KScreen::Outputs that aren't in the list yet, handle primaryOutput
KScreen::OutputList kscreenOutputs = config->outputs();
foreach(QScreenOutput *output, m_outputMap.values()) {
foreach(QScreenOutput *output, m_outputMap) {
KScreen::OutputPtr kscreenOutput = kscreenOutputs[output->id()];
if (!kscreenOutput) {
......
......@@ -98,12 +98,17 @@ class Q_DECL_HIDDEN Output::Private
bool Output::Private::compareModeList(const ModeList& before, const ModeList &after)
{
if (before.keys() != after.keys()) {
if (before.count() != after.count()) {
return false;
}
for (const QString &key : before.keys()) {
const auto mb = before.value(key);
const auto ma = after.value(key);
for (auto itb = before.constBegin(); itb != before.constEnd(); ++itb) {
auto ita = after.constFind(itb.key());
if (ita == after.constEnd()) {
return false;
}
const auto &mb = itb.value();
const auto &ma = ita.value();
if (mb->id() != ma->id()) {
return false;
}
......
......@@ -113,8 +113,9 @@ OutputDeviceInterface* WaylandConfigReader::createOutputDevice(const QVariantMap
OutputDeviceInterface::Mode m0;
const QSize _size = sizeFromJson(mode[QStringLiteral("size")]);
if (mode.keys().contains(QStringLiteral("refreshRate"))) {
m0.refreshRate = qRound(mode[QStringLiteral("refreshRate")].toReal() * 1000); // config has it in Hz
auto refreshRateIt = mode.constFind(QStringLiteral("refreshRate"));
if (refreshRateIt != mode.constEnd()) {
m0.refreshRate = qRound(refreshRateIt->toReal() * 1000); // config has it in Hz
}
bool isCurrent = currentModeId == mode[QStringLiteral("id")].toInt();
bool isPreferred = preferredModes.contains(mode[QStringLiteral("id")]);
......@@ -128,8 +129,9 @@ OutputDeviceInterface* WaylandConfigReader::createOutputDevice(const QVariantMap
flags = OutputDeviceInterface::ModeFlags(OutputDeviceInterface::ModeFlag::Preferred);
}
if (mode.keys().contains(QLatin1String("id"))) {
m0.id = mode[QStringLiteral("id")].toInt();
auto idIt = mode.constFind(QStringLiteral("id"));
if (idIt != mode.constEnd()) {
m0.id = idIt->toInt();
} else {
m0.id = mode_id;
}
......
......@@ -126,8 +126,9 @@ void WaylandTestServer::configurationChangeRequested(KWayland::Server::OutputCon
Q_EMIT configReceived();
auto changes = configurationInterface->changes();
Q_FOREACH (const auto &outputdevice, changes.keys()) {
auto c = changes[outputdevice];
for (auto it = changes.constBegin(); it != changes.constEnd(); ++it) {
auto outputdevice = it.key();
auto c = it.value();
if (c->enabledChanged()) {
qCDebug(KSCREEN_WAYLAND_TESTSERVER) << "Setting enabled:";
outputdevice->setEnabled(c->enabled());
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment