summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJarek Kobus <jaroslaw.kobus@qt.io>2024-02-09 00:22:53 +0100
committerJarek Kobus <jaroslaw.kobus@qt.io>2024-02-14 04:06:55 +0100
commita745ef8427b0ba5a7923a6cc8bb954b916d023ce (patch)
tree419d244e703e8c79a20fb2a8b8dd836d9d3e12b3
parent6b582d71c5b421e44759c1212d92fae9ba7d5ef7 (diff)
QtHelp: Avoid using contains()
Eliminate double lookups. Task-number: QTBUG-122025 Change-Id: I346c61e4e4c6e556405f70f33701c68ed2cf3172 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
-rw-r--r--src/assistant/help/qhelpcollectionhandler.cpp3
-rw-r--r--src/assistant/help/qhelpsearchindexreader.cpp17
-rw-r--r--src/assistant/help/qhelpsearchindexwriter.cpp20
3 files changed, 19 insertions, 21 deletions
diff --git a/src/assistant/help/qhelpcollectionhandler.cpp b/src/assistant/help/qhelpcollectionhandler.cpp
index 5f0649edc..1f40b2739 100644
--- a/src/assistant/help/qhelpcollectionhandler.cpp
+++ b/src/assistant/help/qhelpcollectionhandler.cpp
@@ -758,8 +758,7 @@ bool QHelpCollectionHandler::addCustomFilter(const QString &filterName,
// all old attributes
const QString attributeName = m_query->value(1).toString();
attributeMap.insert(attributeName, m_query->value(0).toInt());
- if (idsToInsert.contains(attributeName))
- idsToInsert.removeAll(attributeName);
+ idsToInsert.removeAll(attributeName);
}
for (const QString &id : std::as_const(idsToInsert)) {
diff --git a/src/assistant/help/qhelpsearchindexreader.cpp b/src/assistant/help/qhelpsearchindexreader.cpp
index 75e578324..8d7c16d7f 100644
--- a/src/assistant/help/qhelpsearchindexreader.cpp
+++ b/src/assistant/help/qhelpsearchindexreader.cpp
@@ -161,23 +161,18 @@ void Reader::searchInDB(const QString &searchInput)
// merge results form title and contents searches
m_searchResults.clear();
-
QSet<QUrl> urls;
-
for (const QHelpSearchResult &result : titleResults) {
- const QUrl &url = result.url();
- if (!urls.contains(url)) {
- urls.insert(url);
+ const auto size = urls.size();
+ urls.insert(result.url());
+ if (size != urls.size()) // insertion took place
m_searchResults.append(result);
- }
}
-
for (const QHelpSearchResult &result : contentResults) {
- const QUrl &url = result.url();
- if (!urls.contains(url)) {
- urls.insert(url);
+ const auto size = urls.size();
+ urls.insert(result.url());
+ if (size != urls.size()) // insertion took place
m_searchResults.append(result);
- }
}
}
}
diff --git a/src/assistant/help/qhelpsearchindexwriter.cpp b/src/assistant/help/qhelpsearchindexwriter.cpp
index ba2619f8c..f92237ac8 100644
--- a/src/assistant/help/qhelpsearchindexwriter.cpp
+++ b/src/assistant/help/qhelpsearchindexwriter.cpp
@@ -380,18 +380,19 @@ void QHelpSearchIndexWriter::run()
if (!reindex) {
for (const QString &namespaceName : registeredDocs) {
- if (indexMap.contains(namespaceName)) {
+ const auto it = indexMap.constFind(namespaceName);
+ if (it != indexMap.constEnd()) {
const QString path = engine.documentationFileName(namespaceName);
- if (indexMap.value(namespaceName) < QFileInfo(path).lastModified()) {
+ if (*it < QFileInfo(path).lastModified()) {
// Remove some outdated indexed stuff
- indexMap.remove(namespaceName);
+ indexMap.erase(it);
writer.removeNamespace(namespaceName);
} else if (!writer.hasNamespace(namespaceName)) {
// No data in fts db for namespace.
// The namespace could have been removed from fts db
// or the whole fts db have been removed
// without removing it from indexMap.
- indexMap.remove(namespaceName);
+ indexMap.erase(it);
}
} else {
// Needed in case namespaceName was removed from indexMap
@@ -407,10 +408,13 @@ void QHelpSearchIndexWriter::run()
indexMap.clear();
}
- for (const QString &namespaceName : indexMap.keys()) {
- if (!registeredDocs.contains(namespaceName)) {
- indexMap.remove(namespaceName);
- writer.removeNamespace(namespaceName);
+ auto it = indexMap.begin();
+ while (it != indexMap.end()) {
+ if (!registeredDocs.contains(it.key())) {
+ writer.removeNamespace(it.key());
+ it = indexMap.erase(it);
+ } else {
+ ++it;
}
}