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

@@ -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);