forked from qt-creator/qt-creator
CppEditor: Improve createContentProposal()
- Limit iterator scope - Replace if-else chain with early continue - Save an unneeded look-up Change-Id: If90f726ddb21a516ed3d438379382a2e4cd248a9 Reviewed-by: David Schulz <david.schulz@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -37,6 +37,8 @@
|
||||
#include <QTextDocument>
|
||||
#include <QIcon>
|
||||
|
||||
#include <set>
|
||||
|
||||
using namespace CPlusPlus;
|
||||
using namespace CppEditor;
|
||||
using namespace TextEditor;
|
||||
@@ -847,14 +849,18 @@ bool InternalCppCompletionAssistProcessor::accepts() const
|
||||
IAssistProposal *InternalCppCompletionAssistProcessor::createContentProposal()
|
||||
{
|
||||
// Duplicates are kept only if they are snippets.
|
||||
QSet<QString> processed;
|
||||
auto it = m_completions.begin();
|
||||
while (it != m_completions.end()) {
|
||||
std::set<QString> processed;
|
||||
for (auto it = m_completions.begin(); it != m_completions.end();) {
|
||||
if ((*it)->isSnippet()) {
|
||||
++it;
|
||||
} else if (!processed.contains((*it)->text())) {
|
||||
continue;
|
||||
}
|
||||
if (!processed.insert((*it)->text()).second) {
|
||||
delete *it;
|
||||
it = m_completions.erase(it);
|
||||
continue;
|
||||
}
|
||||
auto item = static_cast<CppAssistProposalItem *>(*it);
|
||||
processed.insert(item->text());
|
||||
if (!item->isOverloaded()) {
|
||||
if (auto symbol = qvariant_cast<Symbol *>(item->data())) {
|
||||
if (Function *funTy = symbol->type()->asFunctionType()) {
|
||||
@@ -864,10 +870,6 @@ IAssistProposal *InternalCppCompletionAssistProcessor::createContentProposal()
|
||||
}
|
||||
}
|
||||
++it;
|
||||
} else {
|
||||
delete *it;
|
||||
it = m_completions.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
m_model->loadContent(m_completions);
|
||||
|
Reference in New Issue
Block a user