From ff4f2e939732f0878d1be088da6667c9a6f76df8 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 2 May 2022 22:33:45 +0200 Subject: [PATCH] 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 --- src/testlib/qbenchmarkvalgrind.cpp | 10 +++++----- 1 file 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 #include +#include + 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 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).