summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qstandardpaths_unix.cpp
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2017-12-13 22:41:46 +0100
committerMarc Mutz <marc.mutz@kdab.com>2019-05-21 08:58:16 +0200
commit9d0649d33878b7325f9bd78923bdba1c87cf194f (patch)
tree0549576c2e6df9646b35e3d9a469b76d10db9856 /src/corelib/io/qstandardpaths_unix.cpp
parent94fbea2f302d240f7063fba5502634c0b3736430 (diff)
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>
Diffstat (limited to 'src/corelib/io/qstandardpaths_unix.cpp')
-rw-r--r--src/corelib/io/qstandardpaths_unix.cpp12
1 files changed, 4 insertions, 8 deletions
diff --git a/src/corelib/io/qstandardpaths_unix.cpp b/src/corelib/io/qstandardpaths_unix.cpp
index eaa545b4fd..0c276e0a56 100644
--- a/src/corelib/io/qstandardpaths_unix.cpp
+++ b/src/corelib/io/qstandardpaths_unix.cpp
@@ -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