diff options
| author | Christian Kandeler <christian.kandeler@qt.io> | 2023-06-22 14:58:11 +0200 |
|---|---|---|
| committer | Christian Kandeler <christian.kandeler@qt.io> | 2023-06-23 09:51:54 +0000 |
| commit | cf6bd7e0124f31374f3a4abd05d14199d201961b (patch) | |
| tree | 90ce2081bdea0b7bece256bd00c0d0476171e00f /src/plugins/python/pythonproject.cpp | |
| parent | ae33199d046902bb9877810df2dbc590b083ef3c (diff) | |
Fix occurrences of the contains/insert anti-pattern
Introduce and make use of Utils::insert() for QSet with a return value
that indicates whether insertion actually happened.
Change-Id: I655e4bc3553b74fea5ae8956205e4d8070118d63
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Diffstat (limited to 'src/plugins/python/pythonproject.cpp')
| -rw-r--r-- | src/plugins/python/pythonproject.cpp | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/src/plugins/python/pythonproject.cpp b/src/plugins/python/pythonproject.cpp index c9bb0f0b6ce..85110be4863 100644 --- a/src/plugins/python/pythonproject.cpp +++ b/src/plugins/python/pythonproject.cpp @@ -131,10 +131,9 @@ static QStringList readLines(const FilePath &projectFile) const QString line = stream.readLine(); if (line.isNull()) break; - if (visited.contains(line)) + if (!Utils::insert(visited, line)) continue; lines.append(line); - visited.insert(line); } } @@ -149,10 +148,8 @@ static QStringList readLinesJson(const FilePath &projectFile, QString *errorMess const QJsonObject obj = readObjJson(projectFile, errorMessage); for (const QJsonValue &file : obj.value("files").toArray()) { const QString fileName = file.toString(); - if (visited.contains(fileName)) - continue; - lines.append(fileName); - visited.insert(fileName); + if (Utils::insert(visited, fileName)) + lines.append(fileName); } return lines; |
