QStandardPaths: use qTokenizer

Avoids allocating memory for the array.

Change-Id: I425235b948609e5f0ffcfffd0f93375a224e5bcb
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
(cherry picked from commit 403a47cfd571c9954e91234084c6994901939326)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Thiago Macieira 2024-12-31 16:34:13 -03:00 committed by Qt Cherry-pick Bot
parent 96fe113608
commit b39b3551b7

View File

@ -522,11 +522,10 @@ QString QStandardPaths::findExecutable(const QString &executableName, const QStr
}
// Remove trailing slashes, which occur on Windows.
const QStringList rawPaths = pEnv.split(
QDir::listSeparator(), Qt::SkipEmptyParts);
searchPaths.reserve(rawPaths.size());
for (const QString &rawPath : rawPaths) {
QString cleanPath = QDir::cleanPath(rawPath);
searchPaths.reserve(pEnv.count(QDir::listSeparator()));
auto tokenizer = qTokenize(pEnv, QDir::listSeparator(), Qt::SkipEmptyParts);
for (QStringView rawPath : tokenizer) {
QString cleanPath = QDir::cleanPath(rawPath.toString());
if (cleanPath.size() > 1 && cleanPath.endsWith(u'/'))
cleanPath.truncate(cleanPath.size() - 1);
searchPaths.push_back(cleanPath);