Commit cc883023 authored by hjk's avatar hjk
Browse files

De-emphasize PluginManager::getObjects<Type>()



... by additionally keeping local (currently non-owning) pools per
"interesting" type.

Current situation:
  - The global object pool does not scale well for looking up
    objects, as iteration plus qobject_cast typically iterates
    over all pooled objects.
  - User code that can use typed results from the object
    pool need to have access to the full type definition anyway,
    i.e.  depend on the plugin of the target class anyway.

The patch here solves the scaling problem is to have local
type-specific pools to which objects register in their
constructors and deregister in their destructors.

This patch here does *not* change the ownership model of the
pooled objects, however, it opens the possibility to change
the ownership model per type (e.g. by not putting things into
the global pool at all anymore and make the local pool 'owning')
and the intent is to handle that in later patchs.

Even without the follow-up patches this here is a performance
improvement for the cases that access the local pools instead
the global one, i.e. "practically all".

Change-Id: Ib11a42df2c4ecf5e1155534730083a520dd1995b
Reviewed-by: Eike Ziller's avatarEike Ziller <eike.ziller@qt.io>
Reviewed-by: Christian Kandeler's avatarChristian Kandeler <christian.kandeler@qt.io>
parent 32762e27
......@@ -32,8 +32,6 @@
#include "osparser.h"
#include "projectexplorerconstants.h"
#include <extensionsystem/pluginmanager.h>
#include <utils/algorithm.h>
#include <utils/fileutils.h>
#include <utils/icon.h>
......@@ -369,7 +367,7 @@ Id Kit::id() const
static QIcon iconForDeviceType(Core::Id deviceType)
{
const IDeviceFactory *factory = ExtensionSystem::PluginManager::getObject<IDeviceFactory>(
const IDeviceFactory *factory = Utils::findOrDefault(IDeviceFactory::allDeviceFactories(),
[&deviceType](const IDeviceFactory *factory) {
return factory->availableCreationIds().contains(deviceType);
});
......
......@@ -25,6 +25,7 @@
#include "kitinformation.h"
#include "abi.h"
#include "devicesupport/desktopdevice.h"
#include "devicesupport/devicemanager.h"
#include "projectexplorerconstants.h"
......@@ -33,8 +34,6 @@
#include "toolchain.h"
#include "toolchainmanager.h"
#include <extensionsystem/pluginmanager.h>
#include <projectexplorer/abi.h>
#include <ssh/sshconnection.h>
#include <utils/algorithm.h>
......@@ -566,7 +565,7 @@ KitInformation::ItemList DeviceTypeKitInformation::toUserOutput(const Kit *k) co
Core::Id type = deviceTypeId(k);
QString typeDisplayName = tr("Unknown device type");
if (type.isValid()) {
IDeviceFactory *factory = ExtensionSystem::PluginManager::getObject<IDeviceFactory>(
IDeviceFactory *factory = Utils::findOrDefault(IDeviceFactory::allDeviceFactories(),
[&type](IDeviceFactory *factory) {
return factory->availableCreationIds().contains(type);
});
......
......@@ -37,7 +37,7 @@
#include <coreplugin/icore.h>
#include <coreplugin/variablechooser.h>
#include <extensionsystem/pluginmanager.h>
#include <utils/algorithm.h>
#include <utils/fancylineedit.h>
#include <utils/environment.h>
......@@ -261,9 +261,7 @@ int ToolChainInformationConfigWidget::indexOf(QComboBox *cb, const ToolChain *tc
DeviceTypeInformationConfigWidget::DeviceTypeInformationConfigWidget(Kit *workingCopy, const KitInformation *ki) :
KitConfigWidget(workingCopy, ki), m_comboBox(new QComboBox)
{
QList<IDeviceFactory *> factories
= ExtensionSystem::PluginManager::getObjects<IDeviceFactory>();
foreach (IDeviceFactory *factory, factories) {
for (IDeviceFactory *factory : IDeviceFactory::allDeviceFactories()) {
foreach (Id id, factory->availableCreationIds())
m_comboBox->addItem(factory->displayNameForId(id), id.toSetting());
}
......
......@@ -34,8 +34,6 @@
#include <coreplugin/icore.h>
#include <extensionsystem/pluginmanager.h>
#include <utils/persistentsettings.h>
#include <utils/qtcassert.h>
#include <utils/stringutils.h>
......@@ -560,7 +558,7 @@ QSet<Id> KitFeatureProvider::availablePlatforms() const
QString KitFeatureProvider::displayNameForPlatform(Id id) const
{
foreach (IDeviceFactory *f, ExtensionSystem::PluginManager::getObjects<IDeviceFactory>()) {
for (IDeviceFactory *f : IDeviceFactory::allDeviceFactories()) {
if (f->availableCreationIds().contains(id)) {
const QString dn = f->displayNameForId(id);
QTC_ASSERT(!dn.isEmpty(), continue);
......
......@@ -37,8 +37,6 @@
#include <coreplugin/icore.h>
#include <extensionsystem/pluginmanager.h>
#include <utils/algorithm.h>
#include <utils/qtcassert.h>
......@@ -374,11 +372,9 @@ bool ProjectImporter::hasKitWithTemporaryData(Core::Id id, const QVariant &data)
static ProjectImporter::ToolChainData
createToolChains(const Utils::FileName &toolChainPath, const Core::Id &language)
{
const QList<ToolChainFactory *> factories
= ExtensionSystem::PluginManager::getObjects<ToolChainFactory>();
ProjectImporter::ToolChainData data;
for (ToolChainFactory *factory : factories) {
for (ToolChainFactory *factory : ToolChainFactory::allToolChainFactories()) {
data.tcs = factory->autoDetect(toolChainPath, language);
if (data.tcs.isEmpty())
continue;
......
......@@ -36,8 +36,6 @@
#include "session.h"
#include "kitinformation.h"
#include <extensionsystem/pluginmanager.h>
#include <utils/algorithm.h>
#include <utils/checkablemessagebox.h>
#include <utils/outputformatter.h>
......@@ -432,9 +430,22 @@ Utils::OutputFormatter *RunConfiguration::createOutputFormatter() const
Translates the types to names to display to the user.
*/
static QList<IRunConfigurationFactory *> g_runConfigurationFactories;
IRunConfigurationFactory::IRunConfigurationFactory(QObject *parent) :
QObject(parent)
{
g_runConfigurationFactories.append(this);
}
IRunConfigurationFactory::~IRunConfigurationFactory()
{
g_runConfigurationFactories.removeOne(this);
}
const QList<IRunConfigurationFactory *> IRunConfigurationFactory::allRunConfigurationFactories()
{
return g_runConfigurationFactories;
}
QList<RunConfigurationCreationInfo>
......@@ -556,7 +567,7 @@ RunConfiguration *IRunConfigurationFactory::clone(Target *parent, RunConfigurati
IRunConfigurationFactory *IRunConfigurationFactory::find(Target *parent, const QVariantMap &map)
{
return ExtensionSystem::PluginManager::getObject<IRunConfigurationFactory>(
return Utils::findOrDefault(g_runConfigurationFactories,
[&parent, &map](IRunConfigurationFactory *factory) {
return factory->canRestore(parent, map);
});
......@@ -564,7 +575,7 @@ IRunConfigurationFactory *IRunConfigurationFactory::find(Target *parent, const Q
IRunConfigurationFactory *IRunConfigurationFactory::find(Target *parent, RunConfiguration *rc)
{
return ExtensionSystem::PluginManager::getObject<IRunConfigurationFactory>(
return Utils::findOrDefault(g_runConfigurationFactories,
[&parent, rc](IRunConfigurationFactory *factory) {
return factory->canClone(parent, rc);
});
......@@ -572,7 +583,7 @@ IRunConfigurationFactory *IRunConfigurationFactory::find(Target *parent, RunConf
QList<IRunConfigurationFactory *> IRunConfigurationFactory::find(Target *parent)
{
return ExtensionSystem::PluginManager::getObjects<IRunConfigurationFactory>(
return Utils::filtered(g_runConfigurationFactories,
[&parent](IRunConfigurationFactory *factory) {
return !factory->availableCreators(parent).isEmpty();
});
......
......@@ -295,6 +295,9 @@ class PROJECTEXPLORER_EXPORT IRunConfigurationFactory : public QObject
public:
explicit IRunConfigurationFactory(QObject *parent = nullptr);
~IRunConfigurationFactory();
static const QList<IRunConfigurationFactory *> allRunConfigurationFactories();
enum CreationMode {UserCreate, AutoCreate};
......
......@@ -237,11 +237,8 @@ void RunSettingsWidget::aboutToShowAddMenu()
connect(cloneAction, &QAction::triggered,
this, &RunSettingsWidget::cloneRunConfiguration);
}
const QList<IRunConfigurationFactory *> factories =
ExtensionSystem::PluginManager::getObjects<IRunConfigurationFactory>();
QList<QAction *> menuActions;
for (IRunConfigurationFactory *factory : factories) {
for (IRunConfigurationFactory *factory : IRunConfigurationFactory::allRunConfigurationFactories()) {
const QList<RunConfigurationCreationInfo> items = factory->availableCreators(m_target);
for (const RunConfigurationCreationInfo &item : items) {
auto action = new QAction(item.displayName, m_addRunMenu);
......
......@@ -87,8 +87,6 @@ class TargetPrivate
public:
TargetPrivate(Kit *k);
QList<DeployConfigurationFactory *> deployFactories() const;
bool m_isEnabled = true;
QIcon m_overlayIcon;
......@@ -109,11 +107,6 @@ TargetPrivate::TargetPrivate(Kit *k) :
m_kit(k)
{ }
QList<DeployConfigurationFactory *> TargetPrivate::deployFactories() const
{
return ExtensionSystem::PluginManager::getObjects<DeployConfigurationFactory>();
}
Target::Target(Project *project, Kit *k) :
ProjectConfiguration(project, k->id()),
d(new TargetPrivate(k))
......@@ -269,7 +262,7 @@ void Target::addDeployConfiguration(DeployConfiguration *dc)
QTC_ASSERT(dc && !d->m_deployConfigurations.contains(dc), return);
Q_ASSERT(dc->target() == this);
if (d->deployFactories().isEmpty())
if (DeployConfigurationFactory::allDeployConfigurationFactories().isEmpty())
return;
// Check that we don't have a configuration with the same displayName
......
......@@ -36,8 +36,9 @@
#include "targetsetupwidget.h"
#include <coreplugin/icore.h>
#include <extensionsystem/pluginmanager.h>
#include <projectexplorer/ipotentialkit.h>
#include <utils/qtcassert.h>
#include <utils/qtcprocess.h>
#include <utils/wizard.h>
......@@ -52,6 +53,19 @@
#include <QCheckBox>
namespace ProjectExplorer {
static QList<IPotentialKit *> g_potentialKits;
IPotentialKit::IPotentialKit()
{
g_potentialKits.append(this);
}
IPotentialKit::~IPotentialKit()
{
g_potentialKits.removeOne(this);
}
namespace Internal {
static Utils::FileName importDirectory(const QString &projectPath)
{
......@@ -183,9 +197,7 @@ TargetSetupPage::TargetSetupPage(QWidget *parent) :
setTitle(tr("Kit Selection"));
QList<IPotentialKit *> potentialKits =
ExtensionSystem::PluginManager::instance()->getObjects<IPotentialKit>();
foreach (IPotentialKit *pk, potentialKits)
for (IPotentialKit *pk : g_potentialKits)
if (pk->isEnabled())
m_potentialWidgets.append(pk->createWidget(this));
......
......@@ -36,7 +36,7 @@
#include <coreplugin/actionmanager/command.h>
#include <coreplugin/icore.h>
#include <coreplugin/icontext.h>
#include <extensionsystem/pluginmanager.h>
#include <utils/algorithm.h>
#include <utils/qtcassert.h>
#include <utils/itemviews.h>
......@@ -56,6 +56,19 @@ const char SESSION_FILTER_WARNINGS[] = "TaskWindow.IncludeWarnings";
}
namespace ProjectExplorer {
static QList<ITaskHandler *> g_taskHandlers;
ITaskHandler::ITaskHandler()
{
g_taskHandlers.append(this);
}
ITaskHandler::~ITaskHandler()
{
g_taskHandlers.removeOne(this);
}
namespace Internal {
class TaskView : public Utils::ListView
......@@ -321,8 +334,7 @@ void TaskWindow::delayedInitialization()
alreadyDone = true;
QList<ITaskHandler *> handlers = ExtensionSystem::PluginManager::getObjects<ITaskHandler>();
foreach (ITaskHandler *h, handlers) {
for (ITaskHandler *h : g_taskHandlers) {
if (h->isDefaultHandler() && !d->m_defaultHandler)
d->m_defaultHandler = h;
......
......@@ -322,6 +322,23 @@ QList<Task> ToolChain::validateKit(const Kit *) const
Used by the tool chain manager to restore user-generated tool chains.
*/
static QList<ToolChainFactory *> g_toolChainFactories;
ToolChainFactory::ToolChainFactory()
{
g_toolChainFactories.append(this);
}
ToolChainFactory::~ToolChainFactory()
{
g_toolChainFactories.removeOne(this);
}
const QList<ToolChainFactory *> ToolChainFactory::allToolChainFactories()
{
return g_toolChainFactories;
}
QList<ToolChain *> ToolChainFactory::autoDetect(const QList<ToolChain *> &alreadyKnown)
{
Q_UNUSED(alreadyKnown);
......
......@@ -177,6 +177,11 @@ class PROJECTEXPLORER_EXPORT ToolChainFactory : public QObject
Q_OBJECT
public:
ToolChainFactory();
~ToolChainFactory();
static const QList<ToolChainFactory *> allToolChainFactories();
QString displayName() const { return m_displayName; }
virtual QList<ToolChain *> autoDetect(const QList<ToolChain *> &alreadyKnown);
......
......@@ -31,8 +31,6 @@
#include <coreplugin/icore.h>
#include <extensionsystem/pluginmanager.h>
#include <utils/fileutils.h>
#include <utils/persistentsettings.h>
#include <utils/qtcassert.h>
......@@ -139,7 +137,7 @@ static QList<ToolChain *> restoreFromFile(const FileName &fileName)
if (version < 1)
return result;
QList<ToolChainFactory *> factories = ExtensionSystem::PluginManager::getObjects<ToolChainFactory>();
const QList<ToolChainFactory *> factories = ToolChainFactory::allToolChainFactories();
int count = data.value(QLatin1String(TOOLCHAIN_COUNT_KEY), 0).toInt();
for (int i = 0; i < count; ++i) {
......@@ -150,7 +148,7 @@ static QList<ToolChain *> restoreFromFile(const FileName &fileName)
const QVariantMap tcMap = data.value(key).toMap();
bool restored = false;
foreach (ToolChainFactory *f, factories) {
for (ToolChainFactory *f : factories) {
if (f->canRestore(tcMap)) {
if (ToolChain *tc = f->restore(tcMap)) {
result.append(tc);
......@@ -172,9 +170,7 @@ static QList<ToolChain *> restoreFromFile(const FileName &fileName)
static QList<ToolChain *> autoDetectToolChains(const QList<ToolChain *> alreadyKnownTcs)
{
QList<ToolChain *> result;
const QList<ToolChainFactory *> factories
= ExtensionSystem::PluginManager::getObjects<ToolChainFactory>();
foreach (ToolChainFactory *f, factories)
for (ToolChainFactory *f : ToolChainFactory::allToolChainFactories())
result.append(f->autoDetect(alreadyKnownTcs));
// Remove invalid toolchains that might have sneaked in.
......
......@@ -110,7 +110,7 @@ class ToolChainOptionsWidget : public QWidget
public:
ToolChainOptionsWidget()
{
m_factories = ExtensionSystem::PluginManager::getObjects<ToolChainFactory>(
m_factories = Utils::filtered(ToolChainFactory::allToolChainFactories(),
[](ToolChainFactory *factory) { return factory->canCreate();});
m_model.setHeader({ToolChainOptionsPage::tr("Name"), ToolChainOptionsPage::tr("Type")});
......
......@@ -39,6 +39,9 @@ class QBSPROJECTMANAGER_EXPORT PropertyProvider : public QObject
Q_OBJECT
public:
PropertyProvider();
~PropertyProvider();
virtual bool canHandle(const ProjectExplorer::Kit *k) const = 0;
virtual QVariantMap properties(const ProjectExplorer::Kit *k, const QVariantMap &defaultData) const = 0;
};
......
......@@ -34,7 +34,7 @@
#include <coreplugin/icore.h>
#include <coreplugin/messagemanager.h>
#include <extensionsystem/pluginmanager.h>
#include <projectexplorer/kit.h>
#include <projectexplorer/kitmanager.h>
#include <projectexplorer/projectexplorer.h>
......@@ -54,6 +54,19 @@ static QString qtcProfileGroup() { return QLatin1String("preferences.qtcreator.k
static QString qtcProfilePrefix() { return qtcProfileGroup() + sep; }
namespace QbsProjectManager {
static QList<PropertyProvider *> g_propertyProviders;
PropertyProvider::PropertyProvider()
{
g_propertyProviders.append(this);
}
PropertyProvider::~PropertyProvider()
{
g_propertyProviders.removeOne(this);
}
namespace Internal {
qbs::Settings *QbsManager::m_settings = nullptr;
......@@ -200,8 +213,7 @@ void QbsManager::addProfileFromKit(const ProjectExplorer::Kit *k)
// set up properties:
QVariantMap data = m_defaultPropertyProvider->properties(k, QVariantMap());
QList<PropertyProvider *> providerList = ExtensionSystem::PluginManager::getObjects<PropertyProvider>();
foreach (PropertyProvider *provider, providerList) {
for (PropertyProvider *provider : g_propertyProviders) {
if (provider->canHandle(k))
data = provider->properties(k, data);
}
......
......@@ -25,7 +25,7 @@
#include "qmakerunconfigurationfactory.h"
#include <extensionsystem/pluginmanager.h>
using namespace ProjectExplorer;
namespace QmakeProjectManager {
......@@ -35,13 +35,15 @@ QmakeRunConfigurationFactory::QmakeRunConfigurationFactory(QObject *parent) :
QmakeRunConfigurationFactory *QmakeRunConfigurationFactory::find(ProjectExplorer::Target *t)
{
if (!t)
return nullptr;
return ExtensionSystem::PluginManager::getObject<QmakeRunConfigurationFactory>(
[&t](QmakeRunConfigurationFactory *factory) {
return factory->canHandle(t);
});
if (t) {
for (auto factory : IRunConfigurationFactory::allRunConfigurationFactories()) {
if (auto qmakeFactory = qobject_cast<QmakeRunConfigurationFactory *>(factory)) {
if (qmakeFactory->canHandle(t))
return qmakeFactory;
}
}
}
return nullptr;
}
} // namespace QmakeProjectManager
......@@ -30,7 +30,7 @@
//temp
#include "qmljsquickfix.h"
#include <extensionsystem/pluginmanager.h>
#include <utils/algorithm.h>
using namespace QmlJSTools;
using namespace TextEditor;
......@@ -85,10 +85,9 @@ IAssistProcessor *QmlJSQuickFixAssistProvider::createProcessor() const
QList<QuickFixFactory *> QmlJSQuickFixAssistProvider::quickFixFactories() const
{
QList<QuickFixFactory *> results;
foreach (QmlJSQuickFixFactory *f, ExtensionSystem::PluginManager::getObjects<QmlJSQuickFixFactory>())
results.append(f);
return results;
return Utils::filtered(QuickFixFactory::allQuickFixFactories(), [](QuickFixFactory *f) {
return qobject_cast<QmlJSQuickFixFactory *>(f) != nullptr;
});
}
} // namespace QmlJSEditor
......@@ -176,4 +176,22 @@ void BasicBundleProvider::mergeBundlesForKit(ProjectExplorer::Kit *kit
}
}
static QList<IBundleProvider *> g_bundleProviders;
IBundleProvider::IBundleProvider(QObject *parent)
: QObject(parent)
{
g_bundleProviders.append(this);
}
IBundleProvider::~IBundleProvider()
{
g_bundleProviders.removeOne(this);
}
const QList<IBundleProvider *> IBundleProvider::allBundleProviders()
{
return g_bundleProviders;
}
} // end namespace QmlJSTools
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