From dec9b7eb045330aa82245c0ab0122af7e73fcf99 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Mon, 7 Jan 2019 14:28:08 +0100 Subject: [PATCH] PerfProfiler: Various style issues Don't use else after return, initialize variables, cast enum to int when comparing with an int, delete copy and move ctors and assignment operators for QDataStream-derived classes. Change-Id: If4c0e55cc458283c4bef3f819738a285f260a3dc Reviewed-by: Christian Kandeler --- .../perfprofiler/perfconfigeventsmodel.cpp | 29 ++++++++++--------- src/plugins/perfprofiler/perfdatareader.cpp | 9 +++--- .../perfprofiler/perfprofilertracefile.cpp | 10 ++++++- 3 files changed, 29 insertions(+), 19 deletions(-) diff --git a/src/plugins/perfprofiler/perfconfigeventsmodel.cpp b/src/plugins/perfprofiler/perfconfigeventsmodel.cpp index cf5bd6079a6..b11b99394bf 100644 --- a/src/plugins/perfprofiler/perfconfigeventsmodel.cpp +++ b/src/plugins/perfprofiler/perfconfigeventsmodel.cpp @@ -68,9 +68,8 @@ QVariant PerfConfigEventsModel::data(const QModelIndex &index, int role) const auto meta = QMetaEnum::fromType(); return QString::fromLatin1(meta.valueToKey(description.eventType)) .mid(static_cast(strlen("EventType"))).toLower(); - } else { - return description.eventType; } + return description.eventType; } case ColumnSubType: { switch (description.eventType) { @@ -79,8 +78,7 @@ QVariant PerfConfigEventsModel::data(const QModelIndex &index, int role) const case EventTypeCache: if (role == Qt::DisplayRole) return subTypeString(description.eventType, description.subType); - else - return description.subType; + return description.subType; case EventTypeRaw: if (role == Qt::DisplayRole) return QString("r%1").arg(description.numericEvent, 3, 16, QLatin1Char('0')); @@ -108,18 +106,20 @@ QVariant PerfConfigEventsModel::data(const QModelIndex &index, int role) const if (description.operation & OperationExecute) result += 'x'; return result; - } else if (description.eventType == EventTypeCache) { + } + + if (description.eventType == EventTypeCache) { if (description.operation == OperationInvalid) return QVariant(); auto meta = QMetaEnum::fromType(); return QString::fromLatin1(meta.valueToKey(description.operation)).mid( static_cast(strlen("Operation"))).toLower(); - } else { - return QVariant(); } - } else { - return description.operation; + + return QVariant(); } + + return description.operation; case ColumnResult: if (role == Qt::DisplayRole) { if (description.result == ResultInvalid) @@ -127,9 +127,8 @@ QVariant PerfConfigEventsModel::data(const QModelIndex &index, int role) const auto meta = QMetaEnum::fromType(); return QString::fromLatin1(meta.valueToKey(description.result)).mid( static_cast(strlen("Result"))).toLower(); - } else { - return description.result; } + return description.result; default: return QVariant(); } @@ -352,7 +351,9 @@ PerfConfigEventsModel::EventDescription PerfConfigEventsModel::parseEvent( } } return description; - } else if (event.startsWith('r') && event.length() == 4) { + } + + if (event.startsWith('r') && event.length() == 4) { bool ok = false; const uint eventNumber = event.mid(1).toUInt(&ok, 16); if (ok) { @@ -385,9 +386,9 @@ PerfConfigEventsModel::EventDescription PerfConfigEventsModel::parseEvent( if (subtype != -1) { description.subType = SubType(subtype); - if (subtype < SubTypeEventTypeSoftware) + if (subtype < int(SubTypeEventTypeSoftware)) description.eventType = EventTypeHardware; - else if (subtype < SubTypeEventTypeCache) + else if (subtype < int(SubTypeEventTypeCache)) description.eventType = EventTypeSoftware; else description.eventType = EventTypeCache; diff --git a/src/plugins/perfprofiler/perfdatareader.cpp b/src/plugins/perfprofiler/perfdatareader.cpp index dac5ea09b47..ee0a1401e9b 100644 --- a/src/plugins/perfprofiler/perfdatareader.cpp +++ b/src/plugins/perfprofiler/perfdatareader.cpp @@ -271,11 +271,12 @@ qint64 PerfDataReader::adjustTimestamp(qint64 timestamp) + m_localProcessStart; } return timestamp - m_remoteProcessStart; - } else if (m_remoteProcessStart != std::numeric_limits::max()) { - return m_remoteProcessStart; - } else { - return -1; } + + if (m_remoteProcessStart != std::numeric_limits::max()) + return m_remoteProcessStart; + + return -1; } bool PerfDataReader::acceptsSamples() const diff --git a/src/plugins/perfprofiler/perfprofilertracefile.cpp b/src/plugins/perfprofiler/perfprofilertracefile.cpp index 9b9eb3dc31c..7359e8f5d49 100644 --- a/src/plugins/perfprofiler/perfprofilertracefile.cpp +++ b/src/plugins/perfprofiler/perfprofilertracefile.cpp @@ -133,7 +133,7 @@ struct PerfFeatures PerfNrCpus nrCpus; QByteArray cpuDesc; QByteArray cpuId; - quint64 totalMem; + quint64 totalMem = 0; QList cmdline; QList buildIds; PerfCpuTopology cpuTopology; @@ -336,6 +336,7 @@ void PerfProfilerTraceFile::load(QIODevice *file) } class Packet : public QDataStream { + Q_DISABLE_COPY(Packet) public: Packet(QDataStream *parent) : QDataStream(&m_content, QIODevice::WriteOnly), m_parent(parent) @@ -347,12 +348,16 @@ public: (*m_parent) << m_content; } + Packet(Packet &&) = delete; + Packet &operator=(Packet &&) = delete; + private: QByteArray m_content; QDataStream *m_parent; }; class CompressedDataStream : public QDataStream { + Q_DISABLE_COPY(CompressedDataStream) public: CompressedDataStream(QIODevice *device) : QDataStream(&m_content, QIODevice::WriteOnly), m_device(device) @@ -364,6 +369,9 @@ public: flush(); } + CompressedDataStream(CompressedDataStream &&) = delete; + CompressedDataStream &operator=(CompressedDataStream &&) = delete; + void flush() { if (!m_device.isNull() && !m_content.isEmpty()) {