Commit 386f3029 authored by Tobias Hunger (external)'s avatar Tobias Hunger (external) Committed by hjk
Browse files

KitManager: Introduce sortedKits() method



This allows to delay the evaluation of displayNames (which might be
expensive now that we expand them) to when a sorted list is actually
needed, thus speeding up the start-up of Qt Creator.

Change-Id: I78273592bc0f8311372f8d799faf9e1289759013
Reviewed-by: default avatarhjk <hjk121@nokiamail.com>
parent 6c139bd6
......@@ -98,7 +98,7 @@ QString KitChooser::kitToolTip(Kit *k) const
void KitChooser::populate()
{
m_chooser->clear();
foreach (Kit *kit, KitManager::kits()) {
foreach (Kit *kit, KitManager::sortedKits()) {
if (kitMatches(kit)) {
m_chooser->addItem(kitText(kit), qVariantFromValue(kit->id()));
m_chooser->setItemData(m_chooser->count() - 1, kitToolTip(kit), Qt::ToolTipRole);
......
......@@ -77,36 +77,6 @@ public:
KitManagerPrivate();
~KitManagerPrivate();
void insertKit(Kit *k)
{
// Keep list of kits sorted by displayname:
int i =0;
for (; i < m_kitList.count(); ++i)
if (m_kitList.at(i)->displayName() > k->displayName())
break;
m_kitList.insert(i, k);
}
void moveKit(int pos)
{
if (pos < 0 || pos >= m_kitList.count())
return;
Kit *current = m_kitList.at(pos);
int prev = pos - 1;
int next = pos + 1;
if (prev >= 0
&& m_kitList.at(prev)->displayName() > current->displayName()) {
std::swap(m_kitList[prev], m_kitList[pos]);
moveKit(prev);
} else if (next < m_kitList.count()
&& m_kitList.at(next)->displayName() < current->displayName()) {
std::swap(m_kitList[pos], m_kitList[next]);
moveKit(next);
}
}
Kit *m_defaultKit;
bool m_initialized;
QList<KitInformation *> m_informationList;
......@@ -415,6 +385,21 @@ QList<Kit *> KitManager::kits()
return d->m_kitList;
}
QList<Kit *> KitManager::sortedKits()
{
// This method was added to delay the sorting of kits as long as possible.
// Since the displayName can contain variables it can be costly (e.g. involve
// calling executables to find version information, etc.) to call that
// method!
// Avoid lots of potentially expensive calls to Kit::displayName():
QList<QPair<QString, Kit *> > sortList
= Utils::transform(d->m_kitList, [](Kit *k) { return qMakePair(k->displayName(), k); });
Utils::sort(sortList, [](const QPair<QString, Kit *> &a, const QPair<QString, Kit *> &b) {
return a.first < b.first;
});
return Utils::transform(sortList, [](const QPair<QString, Kit *> &a) { return a.second; });
}
QList<Kit *> KitManager::matchingKits(const KitMatcher &matcher)
{
QList<Kit *> result;
......@@ -545,7 +530,7 @@ void KitManager::addKit(Kit *k)
}
}
d->insertKit(k);
d->m_kitList.append(k);
}
void KitInformation::addToEnvironment(const Kit *k, Environment &env) const
......
......@@ -133,6 +133,7 @@ public:
~KitManager();
static QList<Kit *> kits();
static QList<Kit *> sortedKits(); // Use kits() whenever possible as that is cheaper!
static QList<Kit *> matchingKits(const KitMatcher &matcher);
static Kit *find(Core::Id id);
static Kit *find(const KitMatcher &matcher);
......
......@@ -99,7 +99,7 @@ KitModel::KitModel(QBoxLayout *parentLayout, QObject *parent) :
m_autoRoot = new KitNode(m_root);
m_manualRoot = new KitNode(m_root);
foreach (Kit *k, KitManager::kits())
foreach (Kit *k, KitManager::sortedKits())
addKit(k);
changeDefaultKit();
......
......@@ -611,11 +611,7 @@ void TargetSettingsPanelWidget::updateTargetButtons()
this, SLOT(duplicateActionTriggered(QAction*)));
connect(removeAction, SIGNAL(triggered()), this, SLOT(removeTarget()));
QList<Kit *> kits = KitManager::kits();
Utils::sort(kits, [](const Kit *a, const Kit *b) {
return a->displayName() < b->displayName();
});
foreach (Kit *k, kits) {
foreach (Kit *k, KitManager::sortedKits()) {
if (m_project->target(k))
continue;
createAction(k, m_addMenu);
......
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