From 9d0649d33878b7325f9bd78923bdba1c87cf194f Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 13 Dec 2017 22:41:46 +0100 Subject: 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 --- src/corelib/io/qstandardpaths_unix.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'src/corelib/io/qstandardpaths_unix.cpp') 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 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 -- cgit v1.2.3