diff --git a/autotests/libs/mimetypecheckertest.cpp b/autotests/libs/mimetypecheckertest.cpp --- a/autotests/libs/mimetypecheckertest.cpp +++ b/autotests/libs/mimetypecheckertest.cpp @@ -55,6 +55,7 @@ const QLatin1String textPlain = QLatin1String("text/plain"); mEmptyChecker.addWantedMimeType(textPlain); QVERIFY(!mEmptyChecker.wantedMimeTypes().isEmpty()); + QVERIFY(mEmptyChecker.hasWantedMimeTypes()); const QLatin1String textCalendar = QLatin1String("text/calendar"); calendarChecker.addWantedMimeType(textCalendar); @@ -74,6 +75,7 @@ mAliasChecker = aliasChecker; QVERIFY(mEmptyChecker.wantedMimeTypes().isEmpty()); + QVERIFY(!mEmptyChecker.hasWantedMimeTypes()); QCOMPARE(mCalendarChecker.wantedMimeTypes().count(), 1); QCOMPARE(mCalendarChecker.wantedMimeTypes(), QStringList() << textCalendar); diff --git a/src/core/mimetypechecker.h b/src/core/mimetypechecker.h --- a/src/core/mimetypechecker.h +++ b/src/core/mimetypechecker.h @@ -135,10 +135,22 @@ /** * Returns the list of wanted MIME types this instance checks against. * - * @see setWantedMimeTypes() + * @note Don't use this just to check whether there are any wanted mimetypes. + * It is much faster to call @c hasWantedMimeTypes() instead for that purpose. + * + * @see setWantedMimeTypes(), hasWantedMimeTypes() */ QStringList wantedMimeTypes() const; + /** + * Checks whether any wanted MIME types are set. + * + * @return @c true if any wanted MIME types are set, false otherwise. + * + * @since 5.6.43 + */ + bool hasWantedMimeTypes() const; + /** * Sets the list of wanted MIME types this instance checks against. * diff --git a/src/core/mimetypechecker.cpp b/src/core/mimetypechecker.cpp --- a/src/core/mimetypechecker.cpp +++ b/src/core/mimetypechecker.cpp @@ -54,6 +54,11 @@ return d->mWantedMimeTypes.values(); } +bool MimeTypeChecker::hasWantedMimeTypes() const +{ + return !d->mWantedMimeTypes.isEmpty(); +} + void MimeTypeChecker::setWantedMimeTypes(const QStringList &mimeTypes) { d->mWantedMimeTypes = QSet::fromList(mimeTypes); diff --git a/src/core/models/entitytreemodel_p.cpp b/src/core/models/entitytreemodel_p.cpp --- a/src/core/models/entitytreemodel_p.cpp +++ b/src/core/models/entitytreemodel_p.cpp @@ -471,7 +471,7 @@ if (m_itemPopulation == EntityTreeModel::ImmediatePopulation) { foreach (const Collection::Id &collectionId, collectionIt.value()) { const auto col = m_collections.value(collectionId); - if (m_mimeChecker.wantedMimeTypes().isEmpty() || m_mimeChecker.isWantedCollection(col)) { + if (!m_mimeChecker.hasWantedMimeTypes() || m_mimeChecker.isWantedCollection(col)) { fetchItems(m_collections.value(collectionId)); } else { // Consider collections that don't contain relevant mimetypes to be populated @@ -521,8 +521,7 @@ continue; } - if ((m_mimeChecker.wantedMimeTypes().isEmpty() || - m_mimeChecker.isWantedItem(item))) { + if ((!m_mimeChecker.hasWantedMimeTypes() || m_mimeChecker.isWantedItem(item))) { // When listing virtual collections we might get results for items which are already in // the model if their concrete collection has already been listed. // In that case the collectionId should be different though. @@ -773,7 +772,7 @@ } //We're explicitly monitoring collections, but didn't match the filter - if (m_mimeChecker.wantedMimeTypes().isEmpty() && !m_monitor->collectionsMonitored().isEmpty()) { + if (!m_mimeChecker.hasWantedMimeTypes() && !m_monitor->collectionsMonitored().isEmpty()) { //The collection should be included if one of the parents is monitored if (isAncestorMonitored(collection)) { return true; @@ -783,8 +782,7 @@ // Some collection trees contain multiple mimetypes. Even though server side filtering ensures we // only get the ones we're interested in from the job, we have to filter on collections received through signals too. - if (!m_mimeChecker.wantedMimeTypes().isEmpty() && - !m_mimeChecker.isWantedCollection(collection)) { + if (m_mimeChecker.hasWantedMimeTypes() && !m_mimeChecker.isWantedCollection(collection)) { return false; } @@ -1081,8 +1079,7 @@ Q_ASSERT(m_collectionFetchStrategy != EntityTreeModel::InvisibleCollectionFetch ? m_collections.contains(collection.id()) : true); - if (!m_mimeChecker.wantedMimeTypes().isEmpty() && - !m_mimeChecker.isWantedItem(item)) { + if (m_mimeChecker.hasWantedMimeTypes() && !m_mimeChecker.isWantedItem(item)) { return; } @@ -1271,8 +1268,7 @@ Q_ASSERT(m_collections.contains(collectionId)); - if (!m_mimeChecker.wantedMimeTypes().isEmpty() && - !m_mimeChecker.isWantedItem(item)) { + if (m_mimeChecker.hasWantedMimeTypes() && !m_mimeChecker.isWantedItem(item)) { return; } @@ -1485,7 +1481,7 @@ m_collections.insert(m_rootCollection.id(), m_rootCollection); } - const bool noMimetypes = m_mimeChecker.wantedMimeTypes().isEmpty(); + const bool noMimetypes = !m_mimeChecker.hasWantedMimeTypes(); const bool noResources = m_monitor->resourcesMonitored().isEmpty(); const bool multipleCollections = m_monitor->collectionsMonitored().size() > 1; const bool generalPopulation = !noMimetypes || (noMimetypes && noResources);