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>
This commit is contained in:
parent
8ece12e466
commit
664b84c137
@ -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))
|
||||
|
Loading…
x
Reference in New Issue
Block a user