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:
@@ -774,10 +774,8 @@ QSet<FilePath> Snapshot::allIncludesForDocument(const FilePath &filePath) const
|
||||
if (Document::Ptr doc = document(file)) {
|
||||
const FilePaths includedFiles = doc->includedFiles(Document::Duplicates::Keep);
|
||||
for (const FilePath &inc : includedFiles) {
|
||||
if (!result.contains(inc)) {
|
||||
result.insert(inc);
|
||||
if (Utils::insert(result, inc))
|
||||
files.push(inc);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -6,6 +6,8 @@
|
||||
#include <cplusplus/Literals.h>
|
||||
#include <cplusplus/TranslationUnit.h>
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
|
||||
#include <QDir>
|
||||
|
||||
using namespace Utils;
|
||||
@@ -65,9 +67,7 @@ void FastPreprocessor::sourceNeeded(int line, const FilePath &filePath, IncludeT
|
||||
|
||||
void FastPreprocessor::mergeEnvironment(const FilePath &filePath)
|
||||
{
|
||||
if (! _merged.contains(filePath)) {
|
||||
_merged.insert(filePath);
|
||||
|
||||
if (Utils::insert(_merged, filePath)) {
|
||||
if (Document::Ptr doc = _snapshot.document(filePath)) {
|
||||
const QList<Document::Include> includes = doc->resolvedIncludes();
|
||||
for (const Document::Include &i : includes)
|
||||
|
@@ -78,8 +78,7 @@ static bool isNestedInstantiationEnclosingTemplate(
|
||||
{
|
||||
QSet<ClassOrNamespace *> processed;
|
||||
while (enclosingTemplateClassInstantiation
|
||||
&& !processed.contains(enclosingTemplateClassInstantiation)) {
|
||||
processed.insert(enclosingTemplateClassInstantiation);
|
||||
&& Utils::insert(processed, enclosingTemplateClassInstantiation)) {
|
||||
if (enclosingTemplateClassInstantiation == nestedClassOrNamespaceInstantiation)
|
||||
return false;
|
||||
enclosingTemplateClassInstantiation = enclosingTemplateClassInstantiation->parent();
|
||||
@@ -389,11 +388,10 @@ ClassOrNamespace *LookupContext::lookupType(const Name *name, Scope *scope,
|
||||
}
|
||||
if (const NamedType *namedTy = d->type()->asNamedType()) {
|
||||
// Stop on recursive typedef declarations
|
||||
if (typedefsBeingResolved.contains(d))
|
||||
if (!Utils::insert(typedefsBeingResolved, d))
|
||||
return nullptr;
|
||||
return lookupType(namedTy->name(), scope, nullptr,
|
||||
QSet<const Declaration *>(typedefsBeingResolved)
|
||||
<< d);
|
||||
typedefsBeingResolved);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -504,9 +502,8 @@ QList<LookupItem> LookupContext::lookup(const Name *name, Scope *scope) const
|
||||
// try find this name in parent class
|
||||
QSet<ClassOrNamespace *> processed;
|
||||
while (candidates.isEmpty() && (binding = binding->parent())) {
|
||||
if (processed.contains(binding))
|
||||
if (!Utils::insert(processed, binding))
|
||||
break;
|
||||
processed.insert(binding);
|
||||
candidates = binding->find(name);
|
||||
}
|
||||
|
||||
@@ -683,9 +680,8 @@ QList<LookupItem> ClassOrNamespace::lookup_helper(const Name *name, bool searchI
|
||||
for (ClassOrNamespace *parentBinding = binding->parent();
|
||||
parentBinding && !match;
|
||||
parentBinding = parentBinding->parent()) {
|
||||
if (processed.contains(parentBinding))
|
||||
if (!Utils::insert(processed, parentBinding))
|
||||
break;
|
||||
processed.insert(parentBinding);
|
||||
match = parentBinding->lookupInScope(fullName);
|
||||
}
|
||||
|
||||
@@ -704,9 +700,8 @@ QList<LookupItem> ClassOrNamespace::lookup_helper(const Name *name, bool searchI
|
||||
QSet<ClassOrNamespace *> processedOwnParents;
|
||||
ClassOrNamespace *binding = this;
|
||||
do {
|
||||
if (processedOwnParents.contains(binding))
|
||||
if (!Utils::insert(processedOwnParents, binding))
|
||||
break;
|
||||
processedOwnParents.insert(binding);
|
||||
lookup_helper(name, binding, &result, &processed, /*templateId = */ nullptr);
|
||||
binding = binding->_parent;
|
||||
} while (searchInEnclosingScope && binding);
|
||||
@@ -720,9 +715,7 @@ void ClassOrNamespace::lookup_helper(const Name *name, ClassOrNamespace *binding
|
||||
QSet<ClassOrNamespace *> *processed,
|
||||
const TemplateNameId *templateId)
|
||||
{
|
||||
if (binding && ! processed->contains(binding)) {
|
||||
processed->insert(binding);
|
||||
|
||||
if (binding && Utils::insert(*processed, binding)) {
|
||||
const Identifier *nameId = name->identifier();
|
||||
|
||||
const QList<Symbol *> symbols = binding->symbols();
|
||||
@@ -902,9 +895,8 @@ ClassOrNamespace *ClassOrNamespace::findBlock_helper(Block *block,
|
||||
bool searchInEnclosingScope)
|
||||
{
|
||||
for (ClassOrNamespace *binding = this; binding; binding = binding->_parent) {
|
||||
if (processed->contains(binding))
|
||||
if (!Utils::insert(*processed, binding))
|
||||
break;
|
||||
processed->insert(binding);
|
||||
binding->flush();
|
||||
auto end = binding->_blocks.end();
|
||||
auto citBlock = binding->_blocks.find(block);
|
||||
@@ -977,9 +969,7 @@ ClassOrNamespace *ClassOrNamespace::lookupType_helper(const Name *name,
|
||||
|
||||
return nullptr;
|
||||
|
||||
} else if (! processed->contains(this)) {
|
||||
processed->insert(this);
|
||||
|
||||
} else if (Utils::insert(*processed, this)) {
|
||||
if (name->asNameId() || name->asTemplateNameId() || name->asAnonymousNameId()) {
|
||||
flush();
|
||||
|
||||
@@ -1260,9 +1250,8 @@ ClassOrNamespace *ClassOrNamespace::nestedType(const Name *name,
|
||||
|
||||
QSet<ClassOrNamespace *> otherProcessed;
|
||||
while (!origin->_symbols.isEmpty() && origin->_symbols[0]->asBlock()) {
|
||||
if (otherProcessed.contains(origin))
|
||||
if (!Utils::insert(otherProcessed, origin))
|
||||
break;
|
||||
otherProcessed.insert(origin);
|
||||
origin = origin->parent();
|
||||
}
|
||||
|
||||
@@ -1489,9 +1478,8 @@ void ClassOrNamespace::NestedClassInstantiator::instantiate(ClassOrNamespace *en
|
||||
{
|
||||
if (_alreadyConsideredNestedClassInstantiations.size() >= 3)
|
||||
return;
|
||||
if (_alreadyConsideredNestedClassInstantiations.contains(enclosingTemplateClass))
|
||||
if (!Utils::insert(_alreadyConsideredNestedClassInstantiations, enclosingTemplateClass))
|
||||
return;
|
||||
_alreadyConsideredNestedClassInstantiations.insert(enclosingTemplateClass);
|
||||
ClassOrNamespace::Table::const_iterator cit = enclosingTemplateClass->_classOrNamespaces.begin();
|
||||
for (; cit != enclosingTemplateClass->_classOrNamespaces.end(); ++cit) {
|
||||
const Name *nestedName = cit->first;
|
||||
@@ -1720,9 +1708,7 @@ void CreateBindings::process(Document::Ptr doc)
|
||||
return;
|
||||
|
||||
if (Namespace *globalNamespace = doc->globalNamespace()) {
|
||||
if (! _processed.contains(globalNamespace)) {
|
||||
_processed.insert(globalNamespace);
|
||||
|
||||
if (Utils::insert(_processed, globalNamespace)) {
|
||||
const QList<Document::Include> includes = doc->resolvedIncludes();
|
||||
for (const Document::Include &i : includes) {
|
||||
if (Document::Ptr incl = _snapshot.document(i.resolvedFileName()))
|
||||
|
@@ -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()) {
|
||||
|
@@ -5,6 +5,8 @@
|
||||
|
||||
#include <cplusplus/Symbols.h>
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
|
||||
using namespace CPlusPlus;
|
||||
|
||||
SnapshotSymbolVisitor::SnapshotSymbolVisitor(const Snapshot &snapshot)
|
||||
@@ -20,9 +22,7 @@ void SnapshotSymbolVisitor::accept(Document::Ptr doc)
|
||||
|
||||
void SnapshotSymbolVisitor::accept(Document::Ptr doc, QSet<QString> *processed)
|
||||
{
|
||||
if (doc && doc->globalNamespace() && ! processed->contains(doc->filePath().path())) {
|
||||
processed->insert(doc->filePath().path());
|
||||
|
||||
if (doc && doc->globalNamespace() && Utils::insert(*processed, doc->filePath().path())) {
|
||||
const QList<Document::Include> includes = doc->resolvedIncludes();
|
||||
for (const Document::Include &i : includes) {
|
||||
if (Document::Ptr incl = _snapshot.document(i.resolvedFileName()))
|
||||
|
@@ -11,6 +11,8 @@
|
||||
#include <cplusplus/Symbol.h>
|
||||
#include <cplusplus/TranslationUnit.h>
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
|
||||
#include <QSet>
|
||||
|
||||
using namespace Utils;
|
||||
@@ -134,9 +136,7 @@ ExpressionAST *TypeOfExpression::expressionAST() const
|
||||
void TypeOfExpression::processEnvironment(Document::Ptr doc, Environment *env,
|
||||
QSet<QString> *processed) const
|
||||
{
|
||||
if (doc && ! processed->contains(doc->filePath().path())) {
|
||||
processed->insert(doc->filePath().path());
|
||||
|
||||
if (doc && Utils::insert(*processed, doc->filePath().path())) {
|
||||
const QList<Document::Include> includes = doc->resolvedIncludes();
|
||||
for (const Document::Include &incl : includes)
|
||||
processEnvironment(m_snapshot.document(incl.resolvedFileName()), env, processed);
|
||||
|
@@ -373,10 +373,8 @@ const QSet<PluginSpec *> PluginManager::pluginsRequiredByPlugin(PluginSpec *spec
|
||||
if (depIt.key().type != PluginDependency::Required)
|
||||
continue;
|
||||
PluginSpec *depSpec = depIt.value();
|
||||
if (!recursiveDependencies.contains(depSpec)) {
|
||||
recursiveDependencies.insert(depSpec);
|
||||
if (Utils::insert(recursiveDependencies, depSpec))
|
||||
queue.push(depSpec);
|
||||
}
|
||||
}
|
||||
}
|
||||
recursiveDependencies.remove(spec);
|
||||
|
@@ -656,14 +656,12 @@ void LinkPrivate::loadQmldirComponents(ObjectValue *import,
|
||||
QSet<QString> importedTypes;
|
||||
const auto components = libraryInfo.components();
|
||||
for (const QmlDirParser::Component &component : components) {
|
||||
if (importedTypes.contains(component.typeName))
|
||||
continue;
|
||||
|
||||
ComponentVersion componentVersion(component.majorVersion, component.minorVersion);
|
||||
if (version < componentVersion)
|
||||
continue;
|
||||
|
||||
importedTypes.insert(component.typeName);
|
||||
if (!Utils::insert(importedTypes, component.typeName))
|
||||
continue;
|
||||
if (Document::Ptr importedDoc = m_snapshot.document(
|
||||
libraryPath.pathAppended(component.fileName))) {
|
||||
if (ObjectValue *v = importedDoc->bind()->rootObjectValue())
|
||||
|
@@ -734,10 +734,9 @@ static void findNewImplicitImports(const Document::Ptr &doc,
|
||||
// scan files that could be implicitly imported
|
||||
// it's important we also do this for JS files, otherwise the isEmpty check will fail
|
||||
if (snapshot.documentsInDirectory(doc->path()).isEmpty()) {
|
||||
if (!scannedPaths->contains(doc->path())) {
|
||||
if (Utils::insert(*scannedPaths, doc->path())) {
|
||||
*importedFiles += filesInDirectoryForLanguages(doc->path(),
|
||||
doc->language().companionLanguages());
|
||||
scannedPaths->insert(doc->path());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -757,11 +756,10 @@ static void findNewFileImports(const Document::Ptr &doc,
|
||||
*importedFiles += importPath;
|
||||
} else if (import.type() == ImportType::Directory) {
|
||||
if (snapshot.documentsInDirectory(importPath).isEmpty()) {
|
||||
if (!scannedPaths->contains(importPath)) {
|
||||
if (Utils::insert(*scannedPaths, importPath)) {
|
||||
*importedFiles
|
||||
+= filesInDirectoryForLanguages(importPath,
|
||||
doc->language().companionLanguages());
|
||||
scannedPaths->insert(importPath);
|
||||
}
|
||||
}
|
||||
} else if (import.type() == ImportType::QrcFile) {
|
||||
@@ -890,10 +888,9 @@ static bool findNewQmlLibraryInPath(const Utils::FilePath &path,
|
||||
if (!component.fileName.isEmpty()) {
|
||||
const FilePath componentFile = path.pathAppended(component.fileName);
|
||||
const FilePath path = componentFile.absolutePath().cleanPath();
|
||||
if (!scannedPaths->contains(path)) {
|
||||
if (Utils::insert(*scannedPaths, path)) {
|
||||
*importedFiles += filesInDirectoryForLanguages(path, Dialect(Dialect::AnyLanguage)
|
||||
.companionLanguages());
|
||||
scannedPaths->insert(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1110,10 +1107,9 @@ void ModelManagerInterface::importScanAsync(QPromise<void> &promise, const Worki
|
||||
QMutexLocker l(&modelManager->m_mutex);
|
||||
for (const auto &path : paths) {
|
||||
Utils::FilePath cPath = path.path().cleanPath();
|
||||
if (!forceRescan && modelManager->m_scannedPaths.contains(cPath))
|
||||
if (!forceRescan && !Utils::insert(modelManager->m_scannedPaths, cPath))
|
||||
continue;
|
||||
pathsToScan.append({cPath, 0, path.language()});
|
||||
modelManager->m_scannedPaths.insert(cPath);
|
||||
}
|
||||
}
|
||||
const int maxScanDepth = 5;
|
||||
|
@@ -1437,4 +1437,13 @@ void addToHash(QHash<Key, T> *result, const QHash<Key, T> &additionalContents)
|
||||
result->insert(additionalContents);
|
||||
}
|
||||
|
||||
// Workaround for missing information from QSet::insert()
|
||||
// Return type could be a pair like for std::set, but we never use the iterator anyway.
|
||||
template<typename T, typename U> [[nodiscard]] bool insert(QSet<T> &s, const U &v)
|
||||
{
|
||||
const int oldSize = s.size();
|
||||
s.insert(v);
|
||||
return s.size() > oldSize;
|
||||
}
|
||||
|
||||
} // namespace Utils
|
||||
|
@@ -3,7 +3,7 @@
|
||||
|
||||
#include "namevaluesdialog.h"
|
||||
|
||||
#include "environment.h"
|
||||
#include "algorithm.h"
|
||||
#include "hostosinfo.h"
|
||||
#include "utilstr.h"
|
||||
|
||||
@@ -29,10 +29,8 @@ static EnvironmentItems cleanUp(const EnvironmentItems &items)
|
||||
const QString &itemName = item.name;
|
||||
QString emptyName = itemName;
|
||||
emptyName.remove(QLatin1Char(' '));
|
||||
if (!emptyName.isEmpty() && !uniqueSet.contains(itemName)) {
|
||||
if (!emptyName.isEmpty() && Utils::insert(uniqueSet, itemName))
|
||||
uniqueItems.prepend(item);
|
||||
uniqueSet.insert(itemName);
|
||||
}
|
||||
}
|
||||
return uniqueItems;
|
||||
}
|
||||
|
@@ -10,6 +10,7 @@
|
||||
#include "testtreemodel.h"
|
||||
|
||||
#include <projectexplorer/projectexplorericons.h>
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#include <QFontMetrics>
|
||||
@@ -202,10 +203,7 @@ bool TestResultItem::updateDescendantTypes(ResultType t)
|
||||
if (t == ResultType::TestStart || t == ResultType::TestEnd) // these are special
|
||||
return false;
|
||||
|
||||
if (m_descendantsTypes.contains(t))
|
||||
return false;
|
||||
m_descendantsTypes.insert(t);
|
||||
return true;
|
||||
return Utils::insert(m_descendantsTypes, t);
|
||||
}
|
||||
|
||||
bool TestResultItem::descendantTypesContainsAnyOf(const QSet<ResultType> &types) const
|
||||
@@ -467,8 +465,7 @@ void TestResultFilterModel::enableAllResultTypes(bool enabled)
|
||||
|
||||
void TestResultFilterModel::toggleTestResultType(ResultType type)
|
||||
{
|
||||
if (m_enabled.contains(type)) {
|
||||
m_enabled.remove(type);
|
||||
if (m_enabled.remove(type)) {
|
||||
if (type == ResultType::MessageInternal)
|
||||
m_enabled.remove(ResultType::TestEnd);
|
||||
if (type == ResultType::MessageDebug)
|
||||
|
@@ -18,6 +18,7 @@
|
||||
#include <texteditor/texteditorconstants.h>
|
||||
#include <texteditor/texteditorsettings.h>
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/fadingindicator.h>
|
||||
#include <utils/fileutils.h>
|
||||
#include <utils/qtcassert.h>
|
||||
@@ -222,9 +223,8 @@ bool BinEditorWidget::requestDataAt(qint64 pos) const
|
||||
it = m_data.find(block);
|
||||
if (it != m_data.end())
|
||||
return true;
|
||||
if (m_requests.contains(block))
|
||||
if (!Utils::insert(m_requests, block))
|
||||
return false;
|
||||
m_requests.insert(block);
|
||||
d->fetchData((m_baseAddr / m_blockSize + block) * m_blockSize);
|
||||
return true;
|
||||
}
|
||||
|
@@ -1301,9 +1301,8 @@ void CMakeBuildSystem::runCTest()
|
||||
std::function<QJsonObject(int)> findAncestor = [&](int index){
|
||||
const QJsonObject node = nodes.at(index).toObject();
|
||||
const int parent = node.value("parent").toInt(-1);
|
||||
if (seen.contains(parent) || parent < 0)
|
||||
if (parent < 0 || !Utils::insert(seen, parent))
|
||||
return node;
|
||||
seen << parent;
|
||||
return findAncestor(parent);
|
||||
};
|
||||
const QJsonObject btRef = findAncestor(bt);
|
||||
|
@@ -470,10 +470,8 @@ void DocumentModelPrivate::removeAllSuspendedEntries(PinnedFileRemovalPolicy pin
|
||||
QSet<QString> displayNames;
|
||||
for (DocumentModel::Entry *entry : std::as_const(d->m_entries)) {
|
||||
const QString displayName = entry->plainDisplayName();
|
||||
if (displayNames.contains(displayName))
|
||||
continue;
|
||||
displayNames.insert(displayName);
|
||||
d->disambiguateDisplayNames(entry);
|
||||
if (Utils::insert(displayNames, displayName))
|
||||
d->disambiguateDisplayNames(entry);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -9,6 +9,7 @@
|
||||
#include "../coreplugintr.h"
|
||||
#include "../idocument.h"
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/fsengine/fileiconprovider.h>
|
||||
#include <utils/hostosinfo.h>
|
||||
#include <utils/qtcassert.h>
|
||||
@@ -219,9 +220,8 @@ void OpenEditorsWindow::addItem(DocumentModel::Entry *entry,
|
||||
QSet<const DocumentModel::Entry *> &entriesDone,
|
||||
EditorView *view)
|
||||
{
|
||||
if (entriesDone.contains(entry))
|
||||
if (!Utils::insert(entriesDone, entry))
|
||||
return;
|
||||
entriesDone.insert(entry);
|
||||
QString title = entry->displayName();
|
||||
QTC_ASSERT(!title.isEmpty(), return);
|
||||
auto item = new QTreeWidgetItem();
|
||||
|
@@ -7,6 +7,7 @@
|
||||
|
||||
#include <debugger/analyzer/diagnosticlocation.h>
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/fsengine/fileiconprovider.h>
|
||||
#include <utils/utilsicons.h>
|
||||
|
||||
@@ -99,12 +100,10 @@ void DiagnosticsModel::clear()
|
||||
|
||||
void DiagnosticsModel::add(const Diagnostic &diagnostic)
|
||||
{
|
||||
if (m_diagnostics.contains(diagnostic))
|
||||
if (!Utils::insert(m_diagnostics, diagnostic))
|
||||
return;
|
||||
|
||||
const auto hasData = !m_diagnostics.isEmpty();
|
||||
m_diagnostics.insert(diagnostic);
|
||||
if (!hasData)
|
||||
if (m_diagnostics.size() == 1)
|
||||
emit hasDataChanged(true);
|
||||
|
||||
const QString filePath = diagnostic.fileName.toString();
|
||||
|
@@ -73,9 +73,7 @@ protected:
|
||||
{
|
||||
if (!doc)
|
||||
return;
|
||||
if (!processed->contains(doc->globalNamespace())) {
|
||||
processed->insert(doc->globalNamespace());
|
||||
|
||||
if (Utils::insert(*processed, doc->globalNamespace())) {
|
||||
const QList<Document::Include> includes = doc->resolvedIncludes();
|
||||
for (const Document::Include &i : includes)
|
||||
process(_snapshot.document(i.resolvedFileName()), processed);
|
||||
@@ -806,8 +804,7 @@ bool CheckSymbols::hasVirtualDestructor(ClassOrNamespace *binding) const
|
||||
|
||||
while (!todo.isEmpty()) {
|
||||
ClassOrNamespace *b = todo.takeFirst();
|
||||
if (b && !processed.contains(b)) {
|
||||
processed.insert(b);
|
||||
if (b && Utils::insert(processed, b)) {
|
||||
const QList<Symbol *> symbols = b->symbols();
|
||||
for (Symbol *s : symbols) {
|
||||
if (Class *k = s->asClass()) {
|
||||
|
@@ -20,6 +20,7 @@
|
||||
#include <texteditor/texteditorsettings.h>
|
||||
#include <texteditor/completionsettings.h>
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/mimeutils.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/textutils.h>
|
||||
@@ -1459,9 +1460,8 @@ bool InternalCppCompletionAssistProcessor::globalCompletion(Scope *currentScope)
|
||||
|
||||
QSet<ClassOrNamespace *> processed;
|
||||
for (; currentBinding; currentBinding = currentBinding->parent()) {
|
||||
if (processed.contains(currentBinding))
|
||||
if (!Utils::insert(processed, currentBinding))
|
||||
break;
|
||||
processed.insert(currentBinding);
|
||||
|
||||
const QList<ClassOrNamespace*> usings = currentBinding->usings();
|
||||
for (ClassOrNamespace* u : usings)
|
||||
@@ -1598,10 +1598,9 @@ void InternalCppCompletionAssistProcessor::completeNamespace(ClassOrNamespace *b
|
||||
|
||||
while (!bindingsToVisit.isEmpty()) {
|
||||
ClassOrNamespace *binding = bindingsToVisit.takeFirst();
|
||||
if (!binding || bindingsVisited.contains(binding))
|
||||
if (!binding || !Utils::insert(bindingsVisited, binding))
|
||||
continue;
|
||||
|
||||
bindingsVisited.insert(binding);
|
||||
bindingsToVisit += binding->usings();
|
||||
|
||||
QList<Scope *> scopesToVisit;
|
||||
@@ -1619,11 +1618,9 @@ void InternalCppCompletionAssistProcessor::completeNamespace(ClassOrNamespace *b
|
||||
|
||||
while (!scopesToVisit.isEmpty()) {
|
||||
Scope *scope = scopesToVisit.takeFirst();
|
||||
if (!scope || scopesVisited.contains(scope))
|
||||
if (!scope || !Utils::insert(scopesVisited, scope))
|
||||
continue;
|
||||
|
||||
scopesVisited.insert(scope);
|
||||
|
||||
for (Scope::iterator it = scope->memberBegin(); it != scope->memberEnd(); ++it) {
|
||||
Symbol *member = *it;
|
||||
addCompletionItem(member);
|
||||
@@ -1640,10 +1637,9 @@ void InternalCppCompletionAssistProcessor::completeClass(ClassOrNamespace *b, bo
|
||||
|
||||
while (!bindingsToVisit.isEmpty()) {
|
||||
ClassOrNamespace *binding = bindingsToVisit.takeFirst();
|
||||
if (!binding || bindingsVisited.contains(binding))
|
||||
if (!binding || !Utils::insert(bindingsVisited, binding))
|
||||
continue;
|
||||
|
||||
bindingsVisited.insert(binding);
|
||||
bindingsToVisit += binding->usings();
|
||||
|
||||
QList<Scope *> scopesToVisit;
|
||||
@@ -1663,11 +1659,9 @@ void InternalCppCompletionAssistProcessor::completeClass(ClassOrNamespace *b, bo
|
||||
|
||||
while (!scopesToVisit.isEmpty()) {
|
||||
Scope *scope = scopesToVisit.takeFirst();
|
||||
if (!scope || scopesVisited.contains(scope))
|
||||
if (!scope || !Utils::insert(scopesVisited, scope))
|
||||
continue;
|
||||
|
||||
scopesVisited.insert(scope);
|
||||
|
||||
if (staticLookup)
|
||||
addCompletionItem(scope, InjectedClassNameOrder); // add a completion item for the injected class name.
|
||||
|
||||
@@ -1737,9 +1731,7 @@ bool InternalCppCompletionAssistProcessor::completeQtMethod(const QList<LookupIt
|
||||
todo.append(b);
|
||||
while (!todo.isEmpty()) {
|
||||
ClassOrNamespace *binding = todo.takeLast();
|
||||
if (!processed.contains(binding)) {
|
||||
processed.insert(binding);
|
||||
|
||||
if (Utils::insert(processed, binding)) {
|
||||
const QList<Symbol *> symbols = binding->symbols();
|
||||
for (Symbol *s : symbols)
|
||||
if (Class *clazz = s->asClass())
|
||||
@@ -1862,11 +1854,9 @@ void InternalCppCompletionAssistProcessor::addMacros_helper(const Snapshot &snap
|
||||
{
|
||||
Document::Ptr doc = snapshot.document(filePath);
|
||||
|
||||
if (!doc || processed->contains(doc->filePath()))
|
||||
if (!doc || !Utils::insert(*processed, doc->filePath()))
|
||||
return;
|
||||
|
||||
processed->insert(doc->filePath());
|
||||
|
||||
const QList<Document::Include> includes = doc->resolvedIncludes();
|
||||
for (const Document::Include &i : includes)
|
||||
addMacros_helper(snapshot, i.resolvedFileName(), processed, definedMacros);
|
||||
|
@@ -17,6 +17,7 @@
|
||||
#include <cplusplus/SimpleLexer.h>
|
||||
#include <cplusplus/TypeOfExpression.h>
|
||||
#include <texteditor/textdocumentlayout.h>
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/textutils.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
@@ -181,9 +182,7 @@ Class *VirtualFunctionHelper::staticClassOfFunctionCallExpression_internal() con
|
||||
Link findMacroLink_helper(const QByteArray &name, Document::Ptr doc, const Snapshot &snapshot,
|
||||
QSet<QString> *processed)
|
||||
{
|
||||
if (doc && !name.startsWith('<') && !processed->contains(doc->filePath().path())) {
|
||||
processed->insert(doc->filePath().path());
|
||||
|
||||
if (doc && !name.startsWith('<') && Utils::insert(*processed, doc->filePath().path())) {
|
||||
for (const Macro ¯o : doc->definedMacros()) {
|
||||
if (macro.name() == name) {
|
||||
Link link;
|
||||
|
@@ -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();
|
||||
|
@@ -8342,14 +8342,13 @@ private:
|
||||
QList<Snapshot::IncludeLocation>
|
||||
includeLocationsOfDocument = refactoring.snapshot().includeLocationsOfDocument(filePath);
|
||||
for (Snapshot::IncludeLocation &loc : includeLocationsOfDocument) {
|
||||
if (m_processed.contains(loc.first))
|
||||
if (!Utils::insert(m_processed, loc.first))
|
||||
continue;
|
||||
|
||||
CppRefactoringFilePtr file = refactoring.file(loc.first->filePath());
|
||||
const bool noGlobalUsing = refactorFile(file,
|
||||
refactoring.snapshot(),
|
||||
file->position(loc.second, 1));
|
||||
m_processed.insert(loc.first);
|
||||
if (noGlobalUsing)
|
||||
processIncludes(refactoring, loc.first->filePath());
|
||||
}
|
||||
|
@@ -9,6 +9,7 @@
|
||||
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/filepath.h>
|
||||
#include <utils/hostosinfo.h>
|
||||
#include <utils/qtcassert.h>
|
||||
@@ -365,11 +366,9 @@ void CppSourceProcessor::mergeEnvironment(Document::Ptr doc)
|
||||
|
||||
const QString fn = doc->filePath().path();
|
||||
|
||||
if (m_processed.contains(fn))
|
||||
if (!Utils::insert(m_processed, fn))
|
||||
return;
|
||||
|
||||
m_processed.insert(fn);
|
||||
|
||||
const QList<Document::Include> includes = doc->resolvedIncludes();
|
||||
for (const Document::Include &incl : includes) {
|
||||
const FilePath includedFile = incl.resolvedFileName();
|
||||
|
@@ -5,6 +5,8 @@
|
||||
|
||||
#include <cplusplus/FindUsages.h>
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
|
||||
using namespace CPlusPlus;
|
||||
using namespace Utils;
|
||||
|
||||
@@ -170,11 +172,9 @@ void TypeHierarchyBuilder::buildDerived(const std::optional<QFuture<void>> &futu
|
||||
QHash<QString, QHash<QString, QString>> &cache)
|
||||
{
|
||||
Symbol *symbol = typeHierarchy->_symbol;
|
||||
if (_visited.contains(symbol))
|
||||
if (!Utils::insert(_visited, symbol))
|
||||
return;
|
||||
|
||||
_visited.insert(symbol);
|
||||
|
||||
const QString &symbolName = _overview.prettyName(LookupContext::fullyQualifiedName(symbol));
|
||||
DerivedHierarchyVisitor visitor(symbolName, cache);
|
||||
|
||||
|
@@ -45,6 +45,7 @@
|
||||
#include <texteditor/textmark.h>
|
||||
#include <texteditor/typingsettings.h>
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/aspects.h>
|
||||
#include <utils/fancylineedit.h>
|
||||
#include <utils/hostosinfo.h>
|
||||
@@ -944,9 +945,8 @@ public:
|
||||
QString found = sel.selectedText();
|
||||
// Only add "real" completions.
|
||||
if (found.startsWith(needle)
|
||||
&& !seen.contains(found)
|
||||
&& sel.anchor() != basePosition) {
|
||||
seen.insert(found);
|
||||
&& sel.anchor() != basePosition
|
||||
&& Utils::insert(seen, found)) {
|
||||
auto item = new FakeVimAssistProposalItem(m_provider);
|
||||
item->setText(found);
|
||||
items.append(item);
|
||||
|
@@ -269,11 +269,9 @@ void GlslEditorWidget::updateDocumentNow()
|
||||
for (const DiagnosticMessage &m : messages) {
|
||||
if (! m.line())
|
||||
continue;
|
||||
else if (errors.contains(m.line()))
|
||||
if (!Utils::insert(errors, m.line()))
|
||||
continue;
|
||||
|
||||
errors.insert(m.line());
|
||||
|
||||
QTextCursor cursor(document()->findBlockByNumber(m.line() - 1));
|
||||
cursor.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor);
|
||||
|
||||
|
@@ -10,6 +10,7 @@
|
||||
#include <texteditor/syntaxhighlighter.h>
|
||||
#include <texteditor/texteditor.h>
|
||||
#include <texteditor/texteditorsettings.h>
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/mimeutils.h>
|
||||
|
||||
#include <QTextDocument>
|
||||
@@ -165,9 +166,8 @@ void SemanticTokenSupport::updateSemanticTokensImpl(TextDocument *textDocument,
|
||||
|
||||
void SemanticTokenSupport::queueDocumentReload(TextEditor::TextDocument *doc)
|
||||
{
|
||||
if (m_docReloadQueue.contains(doc))
|
||||
if (!Utils::insert(m_docReloadQueue, doc))
|
||||
return;
|
||||
m_docReloadQueue << doc;
|
||||
connect(
|
||||
m_client,
|
||||
&Client::initialized,
|
||||
|
@@ -13,6 +13,8 @@
|
||||
|
||||
#include <texteditor/texteditorconstants.h>
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
|
||||
#include <QAction>
|
||||
#include <QEvent>
|
||||
|
||||
@@ -55,8 +57,7 @@ bool ActionMacroHandler::executeEvent(const MacroEvent ¯oEvent)
|
||||
|
||||
void ActionMacroHandler::registerCommand(Id id)
|
||||
{
|
||||
if (!m_commandIds.contains(id)) {
|
||||
m_commandIds.insert(id);
|
||||
if (Utils::insert(m_commandIds, id)) {
|
||||
const Command *command = ActionManager::command(id);
|
||||
if (QAction *action = command->action()) {
|
||||
connect(action, &QAction::triggered, this, [this, id, command]() {
|
||||
|
@@ -21,6 +21,7 @@
|
||||
#include <projectexplorer/projectmanager.h>
|
||||
#include <projectexplorer/projectnodes.h>
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/mimeutils.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
@@ -288,8 +289,7 @@ void ModelIndexer::IndexerThread::onFilesQueued()
|
||||
// collect all diagrams of model
|
||||
DiagramsCollectorVisitor visitor(indexedModel);
|
||||
project.rootPackage()->accept(&visitor);
|
||||
if (m_indexer->d->defaultModelFiles.contains(queuedFile)) {
|
||||
m_indexer->d->defaultModelFiles.remove(queuedFile);
|
||||
if (m_indexer->d->defaultModelFiles.remove(queuedFile)) {
|
||||
// check if model has a diagram which could be opened
|
||||
qmt::FindRootDiagramVisitor diagramVisitor;
|
||||
project.rootPackage()->accept(&diagramVisitor);
|
||||
@@ -426,10 +426,9 @@ void ModelIndexer::scanProject(ProjectExplorer::Project *project)
|
||||
// queue files
|
||||
while (!filesQueue.isEmpty()) {
|
||||
QueuedFile queuedFile = filesQueue.takeFirst();
|
||||
if (!d->queuedFilesSet.contains(queuedFile)) {
|
||||
if (Utils::insert(d->queuedFilesSet, queuedFile)) {
|
||||
QMT_CHECK(!d->filesQueue.contains(queuedFile));
|
||||
d->filesQueue.append(queuedFile);
|
||||
d->queuedFilesSet.insert(queuedFile);
|
||||
filesAreQueued = true;
|
||||
}
|
||||
}
|
||||
@@ -474,11 +473,10 @@ void ModelIndexer::forgetProject(ProjectExplorer::Project *project)
|
||||
const QString fileString = file.toString();
|
||||
// remove file from queue
|
||||
QueuedFile queuedFile(fileString, project);
|
||||
if (d->queuedFilesSet.contains(queuedFile)) {
|
||||
if (d->queuedFilesSet.remove(queuedFile)) {
|
||||
QMT_CHECK(d->filesQueue.contains(queuedFile));
|
||||
d->filesQueue.removeOne(queuedFile);
|
||||
QMT_CHECK(!d->filesQueue.contains(queuedFile));
|
||||
d->queuedFilesSet.remove(queuedFile);
|
||||
}
|
||||
removeModelFile(fileString, project);
|
||||
removeDiagramReferenceFile(fileString, project);
|
||||
|
@@ -521,8 +521,7 @@ void FlatModel::addFolderNode(WrapperNode *parent, FolderNode *folderNode, QSet<
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!isHidden && !seen->contains(subFolderNode)) {
|
||||
seen->insert(subFolderNode);
|
||||
if (!isHidden && Utils::insert(*seen, subFolderNode)) {
|
||||
auto node = new WrapperNode(subFolderNode);
|
||||
parent->appendChild(node);
|
||||
addFolderNode(node, subFolderNode, seen);
|
||||
@@ -531,10 +530,8 @@ void FlatModel::addFolderNode(WrapperNode *parent, FolderNode *folderNode, QSet<
|
||||
addFolderNode(parent, subFolderNode, seen);
|
||||
}
|
||||
} else if (FileNode *fileNode = node->asFileNode()) {
|
||||
if (!seen->contains(fileNode)) {
|
||||
seen->insert(fileNode);
|
||||
if (Utils::insert(*seen, fileNode))
|
||||
parent->appendChild(new WrapperNode(fileNode));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -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;
|
||||
|
@@ -17,6 +17,7 @@
|
||||
#include <projectexplorer/projectexplorerconstants.h>
|
||||
#include <projectexplorer/toolchain.h>
|
||||
#include <qtsupport/qtkitinformation.h>
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/filepath.h>
|
||||
#include <utils/hostosinfo.h>
|
||||
|
||||
@@ -100,10 +101,8 @@ FilePaths QbsProjectImporter::importCandidates()
|
||||
for (Kit * const k : kits) {
|
||||
FilePath bdir = buildDir(projectFilePath(), k);
|
||||
const FilePath candidate = bdir.absolutePath();
|
||||
if (!seenCandidates.contains(candidate)) {
|
||||
seenCandidates.insert(candidate);
|
||||
if (Utils::insert(seenCandidates, candidate))
|
||||
candidates << candidatesForDirectory(candidate);
|
||||
}
|
||||
}
|
||||
qCDebug(qbsPmLog) << "build directory candidates:" << candidates;
|
||||
return candidates;
|
||||
|
@@ -16,6 +16,7 @@
|
||||
#include <texteditor/texteditorsettings.h>
|
||||
#include <texteditor/completionsettings.h>
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#include <qmljs/qmljsmodelmanagerinterface.h>
|
||||
@@ -261,10 +262,9 @@ private:
|
||||
|
||||
void processProperties(const ObjectValue *object)
|
||||
{
|
||||
if (! object || _processed.contains(object))
|
||||
if (! object || !Utils::insert(_processed, object))
|
||||
return;
|
||||
|
||||
_processed.insert(object);
|
||||
processProperties(object->prototype(_scopeChain->context()));
|
||||
|
||||
_currentObject = object;
|
||||
|
@@ -952,9 +952,8 @@ QList<FindReferences::Usage> FindReferences::findUsageOfType(const Utils::FilePa
|
||||
QSet<Utils::FilePath> docDone;
|
||||
for (const QmlJS::Document::Ptr &doc : std::as_const(snapshot)) {
|
||||
Utils::FilePath sourceFile = modelManager->fileToSource(doc->fileName());
|
||||
if (docDone.contains(sourceFile))
|
||||
if (!Utils::insert(docDone, sourceFile))
|
||||
continue;
|
||||
docDone.insert(sourceFile);
|
||||
QmlJS::Document::Ptr sourceDoc = doc;
|
||||
if (sourceFile != doc->fileName())
|
||||
sourceDoc = snapshot.document(sourceFile);
|
||||
|
@@ -533,10 +533,8 @@ QList<ToolChain*> QtOptionsPageWidget::toolChains(const QtVersion *version)
|
||||
for (const Abi &a : abis) {
|
||||
const Toolchains tcList = ToolChainManager::findToolChains(a);
|
||||
for (ToolChain *tc : tcList) {
|
||||
if (ids.contains(tc->id()))
|
||||
continue;
|
||||
ids.insert(tc->id());
|
||||
toolChains.append(tc);
|
||||
if (Utils::insert(ids, tc->id()))
|
||||
toolChains.append(tc);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -139,9 +139,7 @@ void SquishResultFilterModel::enableAllResultTypes()
|
||||
|
||||
void SquishResultFilterModel::toggleResultType(Result::Type type)
|
||||
{
|
||||
if (m_enabled.contains(type))
|
||||
m_enabled.remove(type);
|
||||
else
|
||||
if (!m_enabled.remove(type))
|
||||
m_enabled.insert(type);
|
||||
invalidateFilter();
|
||||
}
|
||||
|
@@ -570,9 +570,8 @@ FilePaths BaseFileFind::replaceAll(const QString &text, const SearchResultItems
|
||||
QSet<QPair<int, int>> processed;
|
||||
for (const SearchResultItem &item : changeItems) {
|
||||
const QPair<int, int> p{item.mainRange().begin.line, item.mainRange().begin.column};
|
||||
if (processed.contains(p))
|
||||
if (!Utils::insert(processed, p))
|
||||
continue;
|
||||
processed.insert(p);
|
||||
|
||||
QString replacement;
|
||||
if (item.userData().canConvert<QStringList>() && !item.userData().toStringList().isEmpty()) {
|
||||
|
@@ -96,11 +96,10 @@ IAssistProposal *DocumentContentCompletionProcessor::performAsync()
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!words.contains(word)) {
|
||||
if (Utils::insert(words, word)) {
|
||||
auto item = new AssistProposalItem();
|
||||
item->setText(word);
|
||||
items.append(item);
|
||||
words.insert(word);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -4416,9 +4416,8 @@ void TextEditorWidgetPrivate::paintCurrentLineHighlight(const PaintEventData &da
|
||||
QSet<int> seenLines;
|
||||
for (const QTextCursor &cursor : cursorsForBlock) {
|
||||
QTextLine line = data.block.layout()->lineForTextPosition(cursor.positionInBlock());
|
||||
if (seenLines.contains(line.lineNumber()))
|
||||
if (!Utils::insert(seenLines, line.lineNumber()))
|
||||
continue;
|
||||
seenLines << line.lineNumber();
|
||||
QRectF lineRect = line.rect();
|
||||
lineRect.moveTop(lineRect.top() + blockRect.top());
|
||||
lineRect.setLeft(0);
|
||||
@@ -5657,10 +5656,8 @@ void TextEditorWidgetPrivate::slotUpdateBlockNotify(const QTextBlock &block)
|
||||
if (blockContainsFindScope) {
|
||||
QTextBlock b = block.document()->findBlock(scope.selectionStart());
|
||||
do {
|
||||
if (!updatedBlocks.contains(b.blockNumber())) {
|
||||
updatedBlocks << b.blockNumber();
|
||||
if (Utils::insert(updatedBlocks, b.blockNumber()))
|
||||
emit q->requestBlockUpdate(b);
|
||||
}
|
||||
b = b.next();
|
||||
} while (b.isValid() && b.position() < scope.selectionEnd());
|
||||
}
|
||||
|
Reference in New Issue
Block a user