Utils: Improve FilePath::sort

Remove the conversion to/from QString for sorting.

Change-Id: I89921328b6d9e952c802d41998495bd2ffbb9f99
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Marcus Tillmanns
2023-05-10 08:53:35 +02:00
parent 2c433f7fe1
commit fc95d7a737
2 changed files with 63 additions and 5 deletions

View File

@@ -1531,11 +1531,17 @@ void FilePath::removeDuplicates(FilePaths &files)
void FilePath::sort(FilePaths &files)
{
// FIXME: Improve.
// FIXME: This drops the osType information, which is not correct.
QStringList list = transform<QStringList>(files, &FilePath::toString);
list.sort();
files = FileUtils::toFilePathList(list);
std::sort(files.begin(), files.end(), [](const FilePath &a, const FilePath &b) {
const int scheme = a.scheme().compare(b.scheme());
if (scheme != 0)
return scheme < 0;
const int host = a.host().compare(b.host());
if (host != 0)
return host < 0;
return a.pathView() < b.pathView();
});
}
void join(QString &left, const QString &right)