QStandardDirs: fix quadratic loop

Instead of a bad copy of remove_if, with quadratic complexity, use
an ok copy of copy_if, with linear complexity.

Port to QStringRef as a drive-by.

Change-Id: I47fde73b33305385835b0012f6d332e973470789
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
This commit is contained in:
Marc Mutz 2017-12-13 22:41:46 +01:00
parent 94fbea2f30
commit 9d0649d338

View File

@ -284,16 +284,12 @@ static QStringList xdgDataDirs()
dirs.append(QString::fromLatin1("/usr/local/share")); dirs.append(QString::fromLatin1("/usr/local/share"));
dirs.append(QString::fromLatin1("/usr/share")); dirs.append(QString::fromLatin1("/usr/share"));
} else { } else {
dirs = xdgDataDirsEnv.split(QLatin1Char(':'), QString::SkipEmptyParts); const auto parts = xdgDataDirsEnv.splitRef(QLatin1Char(':'), QString::SkipEmptyParts);
// Normalize paths, skip relative paths // Normalize paths, skip relative paths
QMutableListIterator<QString> it(dirs); for (const QStringRef &dir : parts) {
while (it.hasNext()) { if (dir.startsWith(QLatin1Char('/')))
const QString dir = it.next(); dirs.push_back(QDir::cleanPath(dir.toString()));
if (!dir.startsWith(QLatin1Char('/')))
it.remove();
else
it.setValue(QDir::cleanPath(dir));
} }
// Remove duplicates from the list, there's no use for duplicated // Remove duplicates from the list, there's no use for duplicated