Optimize parsing of search results

PR #22906.
This commit is contained in:
Vladimir Golovnev 2025-06-26 08:49:58 +03:00 committed by GitHub
parent 71af105a89
commit 41d7d672ce
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 92 additions and 48 deletions

View file

@ -47,7 +47,7 @@ private slots:
{
using BAViews = QList<QByteArrayView>;
const auto check = [](const QByteArrayView in, const QByteArrayView sep, const BAViews expected)
const auto checkSkipEmptyParts = [](const QByteArrayView in, const QByteArrayView sep, const BAViews expected)
{
// verify it works
QCOMPARE(Utils::ByteArray::splitToViews(in, sep), expected);
@ -56,26 +56,56 @@ private slots:
using Latin1Views = QList<QLatin1StringView>;
const Latin1Views reference = QLatin1StringView(in)
.tokenize(QLatin1StringView(sep), Qt::SkipEmptyParts).toContainer();
.tokenize(QLatin1StringView(sep), Qt::SkipEmptyParts).toContainer();
Latin1Views expectedStrings;
for (const auto &string : expected)
expectedStrings.append(QLatin1StringView(string));
QCOMPARE(reference, expectedStrings);
};
check({}, {}, {});
check({}, "/", {});
check("/", "/", {});
check("/a", "/", {"a"});
check("/a/", "/", {"a"});
check("/a/b", "/", (BAViews {"a", "b"}));
check("/a/b/", "/", (BAViews {"a", "b"}));
check("/a/b", "//", {"/a/b"});
check("//a/b", "//", {"a/b"});
check("//a//b", "//", (BAViews {"a", "b"}));
check("//a//b/", "//", (BAViews {"a", "b/"}));
check("//a//b//", "//", (BAViews {"a", "b"}));
check("///a//b//", "//", (BAViews {"/a", "b"}));
checkSkipEmptyParts({}, {}, {});
checkSkipEmptyParts({}, "/", {});
checkSkipEmptyParts("/", "/", {});
checkSkipEmptyParts("/a", "/", {"a"});
checkSkipEmptyParts("/a/", "/", {"a"});
checkSkipEmptyParts("/a/b", "/", (BAViews {"a", "b"}));
checkSkipEmptyParts("/a/b/", "/", (BAViews {"a", "b"}));
checkSkipEmptyParts("/a/b", "//", {"/a/b"});
checkSkipEmptyParts("//a/b", "//", {"a/b"});
checkSkipEmptyParts("//a//b", "//", (BAViews {"a", "b"}));
checkSkipEmptyParts("//a//b/", "//", (BAViews {"a", "b/"}));
checkSkipEmptyParts("//a//b//", "//", (BAViews {"a", "b"}));
checkSkipEmptyParts("///a//b//", "//", (BAViews {"/a", "b"}));
const auto checkKeepEmptyParts = [](const QByteArrayView in, const QByteArrayView sep, const BAViews expected)
{
// verify it works
QCOMPARE(Utils::ByteArray::splitToViews(in, sep, Qt::KeepEmptyParts), expected);
// verify it has the same behavior as `split(Qt::KeepEmptyParts)`
using Latin1Views = QList<QLatin1StringView>;
const Latin1Views reference = QLatin1StringView(in)
.tokenize(QLatin1StringView(sep), Qt::KeepEmptyParts).toContainer();
Latin1Views expectedStrings;
for (const auto &string : expected)
expectedStrings.append(QLatin1StringView(string));
QCOMPARE(reference, expectedStrings);
};
checkKeepEmptyParts({}, {}, {{}, {}});
checkKeepEmptyParts({}, "/", {{}});
checkKeepEmptyParts("/", "/", {"", ""});
checkKeepEmptyParts("/a", "/", {"", "a"});
checkKeepEmptyParts("/a/", "/", {"", "a", ""});
checkKeepEmptyParts("/a/b", "/", (BAViews {"", "a", "b"}));
checkKeepEmptyParts("/a/b/", "/", (BAViews {"", "a", "b", ""}));
checkKeepEmptyParts("/a/b", "//", {"/a/b"});
checkKeepEmptyParts("//a/b", "//", {"", "a/b"});
checkKeepEmptyParts("//a//b", "//", (BAViews {"", "a", "b"}));
checkKeepEmptyParts("//a//b/", "//", (BAViews {"", "a", "b/"}));
checkKeepEmptyParts("//a//b//", "//", (BAViews {"", "a", "b", ""}));
checkKeepEmptyParts("///a//b//", "//", (BAViews {"", "/a", "b", ""}));
}
void testAsQByteArray() const