Commit 18082f4c authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧

Reduce comparisons as category vectors are sorted

parent cd06be7b
......@@ -151,39 +151,37 @@ bool Category::categoryLessThan(Category *c1, const Category *c2)
return (!c1->isAddons() && c2->isAddons()) || (c1->isAddons()==c2->isAddons() && QString::localeAwareCompare(c1->name(), c2->name()) < 0);
}
//TODO: maybe it would be interesting to apply some rules to a said backend...
void Category::addSubcategory(QVector< Category* >& list, Category* newcat)
{
Q_FOREACH (Category* c, list) {
if(c->name() == newcat->name()) {
if(c->icon() != newcat->icon()
|| c->m_andFilters != newcat->m_andFilters
|| c->m_isAddons != newcat->m_isAddons
)
{
qWarning() << "the following categories seem to be the same but they're not entirely"
<< c->name() << newcat->name() << "--"
<< c->andFilters() << newcat->andFilters() << "--"
<< c->isAddons() << newcat->isAddons();
break;
} else {
c->m_orFilters += newcat->orFilters();
c->m_notFilters += newcat->notFilters();
c->m_plugins.unite(newcat->m_plugins);
Q_FOREACH (Category* nc, newcat->subCategories()) {
addSubcategory(c->m_subCategories, nc);
}
return;
}
}
auto it = std::lower_bound(list.begin(), list.end(), newcat, &categoryLessThan);
if (it == list.end()) {
list << newcat;
return;
}
for(auto it = list.begin(), itEnd = list.end(); it!=itEnd; ++it) {
if (!categoryLessThan(*it, newcat)) {
list.insert(it, newcat);
auto c = *it;
if(c->name() == newcat->name()) {
if(c->icon() != newcat->icon()
|| c->m_andFilters != newcat->m_andFilters
|| c->m_isAddons != newcat->m_isAddons
)
{
qWarning() << "the following categories seem to be the same but they're not entirely"
<< c->name() << newcat->name() << "--"
<< c->andFilters() << newcat->andFilters() << "--"
<< c->isAddons() << newcat->isAddons();
} else {
c->m_orFilters += newcat->orFilters();
c->m_notFilters += newcat->notFilters();
c->m_plugins.unite(newcat->m_plugins);
Q_FOREACH (Category* nc, newcat->subCategories()) {
addSubcategory(c->m_subCategories, nc);
}
return;
}
}
list << newcat;
list.insert(it, newcat);
}
bool Category::blacklistPluginsInVector(const QSet<QString>& pluginNames, QVector<Category *>& subCategories)
......
......@@ -58,7 +58,6 @@ void CategoryModel::populateCategories()
Category::addSubcategory(ret, c);
}
}
qSort(ret.begin(), ret.end(), Category::categoryLessThan);
if (m_rootCategories != ret) {
m_rootCategories = ret;
Q_EMIT rootCategoriesChanged();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment