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 <QTextDocument>
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
|
|
||||||
|
#include <set>
|
||||||
|
|
||||||
using namespace CPlusPlus;
|
using namespace CPlusPlus;
|
||||||
using namespace CppEditor;
|
using namespace CppEditor;
|
||||||
using namespace TextEditor;
|
using namespace TextEditor;
|
||||||
@@ -847,14 +849,18 @@ bool InternalCppCompletionAssistProcessor::accepts() const
|
|||||||
IAssistProposal *InternalCppCompletionAssistProcessor::createContentProposal()
|
IAssistProposal *InternalCppCompletionAssistProcessor::createContentProposal()
|
||||||
{
|
{
|
||||||
// Duplicates are kept only if they are snippets.
|
// Duplicates are kept only if they are snippets.
|
||||||
QSet<QString> processed;
|
std::set<QString> processed;
|
||||||
auto it = m_completions.begin();
|
for (auto it = m_completions.begin(); it != m_completions.end();) {
|
||||||
while (it != m_completions.end()) {
|
|
||||||
if ((*it)->isSnippet()) {
|
if ((*it)->isSnippet()) {
|
||||||
++it;
|
++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);
|
auto item = static_cast<CppAssistProposalItem *>(*it);
|
||||||
processed.insert(item->text());
|
|
||||||
if (!item->isOverloaded()) {
|
if (!item->isOverloaded()) {
|
||||||
if (auto symbol = qvariant_cast<Symbol *>(item->data())) {
|
if (auto symbol = qvariant_cast<Symbol *>(item->data())) {
|
||||||
if (Function *funTy = symbol->type()->asFunctionType()) {
|
if (Function *funTy = symbol->type()->asFunctionType()) {
|
||||||
@@ -864,10 +870,6 @@ IAssistProposal *InternalCppCompletionAssistProcessor::createContentProposal()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
++it;
|
++it;
|
||||||
} else {
|
|
||||||
delete *it;
|
|
||||||
it = m_completions.erase(it);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m_model->loadContent(m_completions);
|
m_model->loadContent(m_completions);
|
||||||
|
Reference in New Issue
Block a user