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>
bb10
Marc Mutz 2022-05-02 22:33:45 +02:00
parent 7905b624fd
commit ff4f2e9397
1 changed files with 5 additions and 5 deletions

View File

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