qnetworkrequest: port parseMatchImpl to QBAV

to save allocations, and use tokenize to avoid temp container

Change-Id: I2a43612b9d15538a93d4afd2c544714507141f0f
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
Anton Kudryavtsev 2023-08-25 16:49:09 +03:00
parent 8db5896bbe
commit 3730212312

View File

@ -1220,31 +1220,29 @@ static QVariant parseETag(QByteArrayView raw)
} }
template<typename T> template<typename T>
static QVariant parseMatchImpl(const QByteArray &raw, T op) static QVariant parseMatchImpl(QByteArrayView raw, T op)
{ {
const QByteArray trimmedRaw = raw.trimmed(); const QByteArrayView trimmedRaw = raw.trimmed();
if (trimmedRaw == "*") if (trimmedRaw == "*")
return QStringList(QStringLiteral("*")); return QStringList(QStringLiteral("*"));
QStringList tags; QStringList tags;
const QList<QByteArray> split = trimmedRaw.split(','); for (auto &element : QLatin1StringView(trimmedRaw).tokenize(','_L1)) {
for (const QByteArray &element : split) { if (const auto trimmed = element.trimmed(); op(trimmed))
const QByteArray trimmed = element.trimmed(); tags += QString::fromLatin1(trimmed);
if (!op(trimmed))
continue;
tags += QString::fromLatin1(trimmed);
} }
return tags; return tags;
} }
static QVariant parseIfMatch(const QByteArray &raw)
static QVariant parseIfMatch(QByteArrayView raw)
{ {
return parseMatchImpl(raw, [](QByteArrayView element) { return parseMatchImpl(raw, [](QByteArrayView element) {
return element.startsWith('"') && element.endsWith('"'); return element.startsWith('"') && element.endsWith('"');
}); });
} }
static QVariant parseIfNoneMatch(const QByteArray &raw) static QVariant parseIfNoneMatch(QByteArrayView raw)
{ {
return parseMatchImpl(raw, [](QByteArrayView element) { return parseMatchImpl(raw, [](QByteArrayView element) {
return (element.startsWith('"') || element.startsWith(R"(W/")")) && element.endsWith('"'); return (element.startsWith('"') || element.startsWith(R"(W/")")) && element.endsWith('"');