summaryrefslogtreecommitdiffstats
path: root/src/testlib
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2022-05-02 22:33:45 +0200
committerMarc Mutz <marc.mutz@qt.io>2022-05-03 11:44:56 +0200
commitff4f2e939732f0878d1be088da6667c9a6f76df8 (patch)
tree84b522085812545e7db02124aedc08d2216877ce /src/testlib
parent7905b624fda19960f85cfada6b84e416d738a22a (diff)
QBenchmarkValgrindUtils::extractResult(): use std::optional
... instead of a pair of val and valSeen variables. More elegant. Pick-to: 6.3 Change-Id: I0fcf9a3b5611e30fb81d92619993a7828496cd1b Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/testlib')
-rw-r--r--src/testlib/qbenchmarkvalgrind.cpp10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/testlib/qbenchmarkvalgrind.cpp b/src/testlib/qbenchmarkvalgrind.cpp
index 13a2cdcdb4..0ebc4626ad 100644
--- a/src/testlib/qbenchmarkvalgrind.cpp
+++ b/src/testlib/qbenchmarkvalgrind.cpp
@@ -48,6 +48,8 @@
#include <QtCore/qset.h>
#include <QtTest/private/callgrind_p.h>
+#include <optional>
+
QT_BEGIN_NAMESPACE
using namespace Qt::StringLiterals;
@@ -89,8 +91,7 @@ qint64 QBenchmarkValgrindUtils::extractResult(const QString &fileName)
Q_ASSERT(openOk);
Q_UNUSED(openOk);
- qint64 val = -1;
- bool valSeen = false;
+ std::optional<qint64> val = std::nullopt;
QRegularExpression rxValue(u"^summary: (\\d+)"_s);
while (!file.atEnd()) {
const QString line(QLatin1StringView(file.readLine()));
@@ -99,13 +100,12 @@ qint64 QBenchmarkValgrindUtils::extractResult(const QString &fileName)
bool ok;
val = match.captured(1).toLongLong(&ok);
Q_ASSERT(ok);
- valSeen = true;
break;
}
}
- if (Q_UNLIKELY(!valSeen))
+ if (Q_UNLIKELY(!val))
qFatal("Failed to extract result");
- return val;
+ return *val;
}
// Gets the newest file name (i.e. the one with the highest integer suffix).