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:
Christian Kandeler
2023-06-22 14:58:11 +02:00
parent ae33199d04
commit cf6bd7e012
39 changed files with 107 additions and 169 deletions

View File

@@ -6,7 +6,6 @@
#include "LookupContext.h"
#include "Overview.h"
#include "DeprecatedGenTemplateInstance.h"
#include "CppRewriter.h"
#include "TypeOfExpression.h"
#include <cplusplus/Control.h>
@@ -20,6 +19,8 @@
#include <cplusplus/NameVisitor.h>
#include <cplusplus/Templates.h>
#include <utils/algorithm.h>
#include <QList>
#include <QDebug>
#include <QSet>
@@ -142,9 +143,8 @@ private:
for (const LookupItem &it : namedTypeItems) {
Symbol *declaration = it.declaration();
if (declaration && declaration->isTypedef()) {
if (visited.contains(declaration))
if (!Utils::insert(visited, declaration))
break;
visited.insert(declaration);
// continue working with the typedefed type and scope
if (type->type()->asPointerType()) {