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:
parent
8db5896bbe
commit
3730212312
@ -1220,31 +1220,29 @@ static QVariant parseETag(QByteArrayView raw)
|
||||
}
|
||||
|
||||
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 == "*")
|
||||
return QStringList(QStringLiteral("*"));
|
||||
|
||||
QStringList tags;
|
||||
const QList<QByteArray> split = trimmedRaw.split(',');
|
||||
for (const QByteArray &element : split) {
|
||||
const QByteArray trimmed = element.trimmed();
|
||||
if (!op(trimmed))
|
||||
continue;
|
||||
tags += QString::fromLatin1(trimmed);
|
||||
for (auto &element : QLatin1StringView(trimmedRaw).tokenize(','_L1)) {
|
||||
if (const auto trimmed = element.trimmed(); op(trimmed))
|
||||
tags += QString::fromLatin1(trimmed);
|
||||
}
|
||||
return tags;
|
||||
}
|
||||
|
||||
static QVariant parseIfMatch(const QByteArray &raw)
|
||||
|
||||
static QVariant parseIfMatch(QByteArrayView raw)
|
||||
{
|
||||
return parseMatchImpl(raw, [](QByteArrayView element) {
|
||||
return element.startsWith('"') && element.endsWith('"');
|
||||
});
|
||||
}
|
||||
|
||||
static QVariant parseIfNoneMatch(const QByteArray &raw)
|
||||
static QVariant parseIfNoneMatch(QByteArrayView raw)
|
||||
{
|
||||
return parseMatchImpl(raw, [](QByteArrayView element) {
|
||||
return (element.startsWith('"') || element.startsWith(R"(W/")")) && element.endsWith('"');
|
||||
|
Loading…
Reference in New Issue
Block a user