summaryrefslogtreecommitdiffstats
path: root/src/testlib
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2022-05-02 23:18:52 +0200
committerMarc Mutz <marc.mutz@qt.io>2022-05-05 10:39:37 +0200
commit664b84c1372d933adecdb4196059675684922111 (patch)
tree806d83f6129e873c387abdcc564de1cc63cc57be /src/testlib
parent8ece12e466f8a0c6b0daeb5ed6601094fd7a0dbc (diff)
De-pessimize QBenchmarkValgrindUtils::extractResult()
As if QIODevice::readLine() and QIODevice::Text open-mode aren't slow enough, the old code took the line QByteArray, converted it to a QString so it could apply a trivial regex to it: '^summary: (\d+)'. We can, of course, use QByteArray::startsWith("summary: ") followed by std::from_chars(), these days, to get the same effect, without having to JIT-compile an RX and convert every line into UTF-16 first. Change-Id: I20d80ffb469329d3c3efd08c71fcf5abf9f486d3 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'src/testlib')
-rw-r--r--src/testlib/qbenchmarkvalgrind.cpp20
1 files changed, 12 insertions, 8 deletions
diff --git a/src/testlib/qbenchmarkvalgrind.cpp b/src/testlib/qbenchmarkvalgrind.cpp
index 0ebc4626ad..821ee5f289 100644
--- a/src/testlib/qbenchmarkvalgrind.cpp
+++ b/src/testlib/qbenchmarkvalgrind.cpp
@@ -48,6 +48,7 @@
#include <QtCore/qset.h>
#include <QtTest/private/callgrind_p.h>
+#include <charconv>
#include <optional>
QT_BEGIN_NAMESPACE
@@ -92,15 +93,18 @@ qint64 QBenchmarkValgrindUtils::extractResult(const QString &fileName)
Q_UNUSED(openOk);
std::optional<qint64> val = std::nullopt;
- QRegularExpression rxValue(u"^summary: (\\d+)"_s);
while (!file.atEnd()) {
- const QString line(QLatin1StringView(file.readLine()));
- QRegularExpressionMatch match = rxValue.match(line);
- if (match.hasMatch()) {
- bool ok;
- val = match.captured(1).toLongLong(&ok);
- Q_ASSERT(ok);
- break;
+ const QByteArray line = file.readLine();
+ constexpr QByteArrayView tag = "summary: ";
+ if (line.startsWith(tag)) {
+ const auto maybeNumber = line.data() + tag.size();
+ const auto end = line.data() + line.size();
+ qint64 v;
+ const auto r = std::from_chars(maybeNumber, end, v);
+ if (r.ec == std::errc{}) {
+ val = v;
+ break;
+ }
}
}
if (Q_UNLIKELY(!val))