Commit fe9895aa authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧

Use upper_bound instead of find_if

The vector is already sorted so it turns every insertion O(log n) instead
of O(n)
parent fee58bff
......@@ -445,8 +445,8 @@ void ResourcesProxyModel::sortedInsertion(const QVector<AbstractResource*> & res
for(auto resource: resources) {
const auto finder = [this, resource](AbstractResource* res){ return lessThan(resource, res); };
const auto it = std::find_if(m_displayedResources.constBegin(), m_displayedResources.constEnd(), finder);
const auto finder = [this](AbstractResource* resource, AbstractResource* res){ return lessThan(resource, res); };
const auto it = std::upper_bound(m_displayedResources.constBegin(), m_displayedResources.constEnd(), resource, finder);
const auto newIdx = it == m_displayedResources.constEnd() ? m_displayedResources.count() : (it - m_displayedResources.constBegin());
if (it != m_displayedResources.constEnd() && *it == resource)
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