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:
parent
94fbea2f30
commit
9d0649d338
@ -284,16 +284,12 @@ static QStringList xdgDataDirs()
|
||||
dirs.append(QString::fromLatin1("/usr/local/share"));
|
||||
dirs.append(QString::fromLatin1("/usr/share"));
|
||||
} else {
|
||||
dirs = xdgDataDirsEnv.split(QLatin1Char(':'), QString::SkipEmptyParts);
|
||||
const auto parts = xdgDataDirsEnv.splitRef(QLatin1Char(':'), QString::SkipEmptyParts);
|
||||
|
||||
// Normalize paths, skip relative paths
|
||||
QMutableListIterator<QString> it(dirs);
|
||||
while (it.hasNext()) {
|
||||
const QString dir = it.next();
|
||||
if (!dir.startsWith(QLatin1Char('/')))
|
||||
it.remove();
|
||||
else
|
||||
it.setValue(QDir::cleanPath(dir));
|
||||
for (const QStringRef &dir : parts) {
|
||||
if (dir.startsWith(QLatin1Char('/')))
|
||||
dirs.push_back(QDir::cleanPath(dir.toString()));
|
||||
}
|
||||
|
||||
// Remove duplicates from the list, there's no use for duplicated
|
||||
|
Loading…
x
Reference in New Issue
Block a user