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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user