forked from qt-creator/qt-creator
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>
This commit is contained in:
@@ -60,6 +60,7 @@
|
||||
|
||||
#include <texteditor/textdocument.h>
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/environment.h>
|
||||
#include <utils/fileutils.h>
|
||||
#include <utils/hostosinfo.h>
|
||||
@@ -1060,10 +1061,8 @@ static void addUnique(const Macros &newMacros, Macros ¯os,
|
||||
QSet<ProjectExplorer::Macro> &alreadyIn)
|
||||
{
|
||||
for (const ProjectExplorer::Macro ¯o : newMacros) {
|
||||
if (!alreadyIn.contains(macro)) {
|
||||
if (Utils::insert(alreadyIn, macro))
|
||||
macros += macro;
|
||||
alreadyIn.insert(macro);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1949,9 +1948,8 @@ void CppModelManager::GC()
|
||||
const FilePath filePath = todo.last();
|
||||
todo.removeLast();
|
||||
|
||||
if (reachableFiles.contains(filePath))
|
||||
if (!Utils::insert(reachableFiles, filePath))
|
||||
continue;
|
||||
reachableFiles.insert(filePath);
|
||||
|
||||
if (Document::Ptr doc = currentSnapshot.document(filePath))
|
||||
todo += doc->includedFiles();
|
||||
|
Reference in New Issue
Block a user