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
......@@ -123,10 +123,7 @@ TextEditor::Indenter *CppCodeStylePreferencesFactory::createIndenter() const
TextEditor::SnippetProvider *CppCodeStylePreferencesFactory::snippetProvider() const
{
return ExtensionSystem::PluginManager::getObject<TextEditor::SnippetProvider>(
[](TextEditor::SnippetProvider *provider) {
return provider->groupId() == QLatin1String(CppEditor::Constants::CPP_SNIPPETS_GROUP_ID);
});
return TextEditor::SnippetProvider::snippetProviderForGroupId(CppEditor::Constants::CPP_SNIPPETS_GROUP_ID);
}
QString CppCodeStylePreferencesFactory::previewText() const
......
......@@ -493,10 +493,8 @@ void CppCodeStylePreferencesWidget::updatePreview()
void CppCodeStylePreferencesWidget::decorateEditors(const FontSettings &fontSettings)
{
const SnippetProvider *provider = ExtensionSystem::PluginManager::getObject<SnippetProvider>(
[](SnippetProvider *current) {
return current->groupId() == QLatin1String(CppEditor::Constants::CPP_SNIPPETS_GROUP_ID);
});
const SnippetProvider *provider =
SnippetProvider::snippetProviderForGroupId(CppEditor::Constants::CPP_SNIPPETS_GROUP_ID);
foreach (SnippetEditorWidget *editor, m_previews) {
editor->textDocument()->setFontSettings(fontSettings);
......
......@@ -30,13 +30,15 @@
#include "../editor/nimindenter.h"
#include <coreplugin/id.h>
#include <texteditor/simplecodestylepreferences.h>
#include <texteditor/snippets/snippetprovider.h>
#include <extensionsystem/pluginmanager.h>
#include <QWidget>
#include <QLayout>
using namespace TextEditor;
namespace Nim {
NimCodeStylePreferencesFactory::NimCodeStylePreferencesFactory()
......@@ -71,12 +73,9 @@ TextEditor::Indenter *NimCodeStylePreferencesFactory::createIndenter() const
return new NimIndenter();
}
TextEditor::SnippetProvider *NimCodeStylePreferencesFactory::snippetProvider() const
SnippetProvider *NimCodeStylePreferencesFactory::snippetProvider() const
{
return ExtensionSystem::PluginManager::getObject<TextEditor::SnippetProvider>(
[](TextEditor::SnippetProvider *provider) {
return provider->groupId() == Nim::Constants::C_NIMSNIPPETSGROUP_ID;
});
return SnippetProvider::snippetProviderForGroupId(Nim::Constants::C_NIMSNIPPETSGROUP_ID);
}
QString NimCodeStylePreferencesFactory::previewText() const
......
......@@ -38,7 +38,7 @@
#include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/projectmacroexpander.h>
#include <projectexplorer/target.h>
#include <extensionsystem/pluginmanager.h>
#include <coreplugin/idocument.h>
#include <utils/qtcassert.h>
......@@ -318,6 +318,18 @@ void BuildConfiguration::prependCompilerPathToEnvironment(Kit *k, Utils::Environ
// IBuildConfigurationFactory
///
static QList<IBuildConfigurationFactory *> g_buildConfigurationFactories;
IBuildConfigurationFactory::IBuildConfigurationFactory()
{
g_buildConfigurationFactories.append(this);
}
IBuildConfigurationFactory::~IBuildConfigurationFactory()
{
g_buildConfigurationFactories.removeOne(this);
}
int IBuildConfigurationFactory::priority(const Target *parent) const
{
return canHandle(parent) ? 0 : -1;
......@@ -334,19 +346,15 @@ int IBuildConfigurationFactory::priority(const Kit *k, const QString &projectPat
// restore
IBuildConfigurationFactory *IBuildConfigurationFactory::find(Target *parent, const QVariantMap &map)
{
QList<IBuildConfigurationFactory *> factories
= ExtensionSystem::PluginManager::getObjects<IBuildConfigurationFactory>(
[&parent, map](IBuildConfigurationFactory *factory) {
return factory->canRestore(parent, map);
});
IBuildConfigurationFactory *factory = 0;
int priority = -1;
foreach (IBuildConfigurationFactory *i, factories) {
int iPriority = i->priority(parent);
if (iPriority > priority) {
factory = i;
priority = iPriority;
for (IBuildConfigurationFactory *i : g_buildConfigurationFactories) {
if (i->canRestore(parent, map)) {
int iPriority = i->priority(parent);
if (iPriority > priority) {
factory = i;
priority = iPriority;
}
}
}
return factory;
......@@ -355,11 +363,9 @@ IBuildConfigurationFactory *IBuildConfigurationFactory::find(Target *parent, con
// setup
IBuildConfigurationFactory *IBuildConfigurationFactory::find(const Kit *k, const QString &projectPath)
{
QList<IBuildConfigurationFactory *> factories
= ExtensionSystem::PluginManager::instance()->getObjects<IBuildConfigurationFactory>();
IBuildConfigurationFactory *factory = 0;
int priority = -1;
foreach (IBuildConfigurationFactory *i, factories) {
for (IBuildConfigurationFactory *i : g_buildConfigurationFactories) {
int iPriority = i->priority(k, projectPath);
if (iPriority > priority) {
factory = i;
......@@ -372,11 +378,9 @@ IBuildConfigurationFactory *IBuildConfigurationFactory::find(const Kit *k, const
// create
IBuildConfigurationFactory * IBuildConfigurationFactory::find(Target *parent)
{
QList<IBuildConfigurationFactory *> factories
= ExtensionSystem::PluginManager::instance()->getObjects<IBuildConfigurationFactory>();
IBuildConfigurationFactory *factory = 0;
int priority = -1;
foreach (IBuildConfigurationFactory *i, factories) {
for (IBuildConfigurationFactory *i : g_buildConfigurationFactories) {
int iPriority = i->priority(parent);
if (iPriority > priority) {
factory = i;
......@@ -389,19 +393,15 @@ IBuildConfigurationFactory * IBuildConfigurationFactory::find(Target *parent)
// clone
IBuildConfigurationFactory *IBuildConfigurationFactory::find(Target *parent, BuildConfiguration *bc)
{
QList<IBuildConfigurationFactory *> factories
= ExtensionSystem::PluginManager::getObjects<IBuildConfigurationFactory>(
[&parent, &bc](IBuildConfigurationFactory *factory) {
return factory->canClone(parent, bc);
});
IBuildConfigurationFactory *factory = 0;
int priority = -1;
foreach (IBuildConfigurationFactory *i, factories) {
int iPriority = i->priority(parent);
if (iPriority > priority) {
factory = i;
priority = iPriority;
for (IBuildConfigurationFactory *i : g_buildConfigurationFactories) {
if (i->canClone(parent, bc)) {
int iPriority = i->priority(parent);
if (iPriority > priority) {
factory = i;
priority = iPriority;
}
}
}
return factory;
......
......@@ -121,7 +121,8 @@ class PROJECTEXPLORER_EXPORT IBuildConfigurationFactory : public QObject
Q_OBJECT
protected:
IBuildConfigurationFactory() = default;
IBuildConfigurationFactory();
~IBuildConfigurationFactory();
public:
// The priority is negative if this factory can not create anything for the target.
......
......@@ -114,6 +114,8 @@ static const char buildStepEnabledKey[] = "ProjectExplorer.BuildStep.Enabled";
namespace ProjectExplorer {
static QList<BuildStepFactory *> g_buildStepFactories;
BuildStep::BuildStep(BuildStepList *bsl, Core::Id id) :
ProjectConfiguration(bsl, id)
{
......@@ -213,7 +215,19 @@ bool BuildStep::enabled() const
}
BuildStepFactory::BuildStepFactory()
{ }
{
g_buildStepFactories.append(this);
}
BuildStepFactory::~BuildStepFactory()
{
g_buildStepFactories.removeOne(this);
}
const QList<BuildStepFactory *> BuildStepFactory::allBuildStepFactories()
{
return g_buildStepFactories;
}
bool BuildStepFactory::canHandle(BuildStepList *bsl) const
{
......
......@@ -124,6 +124,9 @@ class PROJECTEXPLORER_EXPORT BuildStepFactory : public QObject
public:
BuildStepFactory();
~BuildStepFactory();
static const QList<BuildStepFactory *> allBuildStepFactories();
BuildStepInfo stepInfo() const;
Core::Id stepId() const;
......
......@@ -32,7 +32,6 @@
#include "projectexplorer.h"
#include "target.h"
#include <extensionsystem/pluginmanager.h>
#include <utils/algorithm.h>
using namespace ProjectExplorer;
......@@ -108,8 +107,7 @@ bool BuildStepList::fromMap(const QVariantMap &map)
if (!ProjectConfiguration::fromMap(map))
return false;
const QList<BuildStepFactory *> factories
= ExtensionSystem::PluginManager::getObjects<BuildStepFactory>();
const QList<BuildStepFactory *> factories = BuildStepFactory::allBuildStepFactories();
int maxSteps = map.value(QString::fromLatin1(STEPS_COUNT_KEY), 0).toInt();
for (int i = 0; i < maxSteps; ++i) {
......
......@@ -32,7 +32,7 @@
#include <coreplugin/icore.h>
#include <coreplugin/coreicons.h>
#include <extensionsystem/pluginmanager.h>
#include <utils/qtcassert.h>
#include <utils/detailswidget.h>
#include <utils/hostosinfo.h>
......@@ -288,8 +288,7 @@ void BuildStepListWidget::updateAddBuildStepMenu()
{
QMap<QString, QPair<Core::Id, BuildStepFactory *> > map;
//Build up a list of possible steps and save map the display names to the (internal) name and factories.
QList<BuildStepFactory *> factories = ExtensionSystem::PluginManager::getObjects<BuildStepFactory>();
foreach (BuildStepFactory *factory, factories) {
for (BuildStepFactory *factory : BuildStepFactory::allBuildStepFactories()) {
if (factory->canHandle(m_buildStepList)) {
const BuildStepInfo &info = factory->stepInfo();
if (info.flags & BuildStepInfo::Uncreatable)
......
......@@ -65,6 +65,19 @@ bool enableLoadTemplateFiles()
namespace ProjectExplorer {
static QList<ICustomWizardMetaFactory *> g_customWizardMetaFactories;
ICustomWizardMetaFactory::ICustomWizardMetaFactory(const QString &klass, Core::IWizardFactory::WizardKind kind) :
m_klass(klass), m_kind(kind)
{
g_customWizardMetaFactories.append(this);
}
ICustomWizardMetaFactory::~ICustomWizardMetaFactory()
{
g_customWizardMetaFactories.removeOne(this);
}
namespace Internal {
/*!
\class ProjectExplorer::ICustomWizardFactory
......@@ -338,7 +351,7 @@ CustomWizard::CustomWizardContextPtr CustomWizard::context() const
CustomWizard *CustomWizard::createWizard(const CustomProjectWizard::CustomWizardParametersPtr &p)
{
ICustomWizardMetaFactory *factory = ExtensionSystem::PluginManager::getObject<ICustomWizardMetaFactory>(
ICustomWizardMetaFactory *factory = Utils::findOrDefault(g_customWizardMetaFactories,
[&p](ICustomWizardMetaFactory *factory) {
return p->klass.isEmpty() ? (p->kind == factory->kind()) : (p->klass == factory->klass());
});
......
......@@ -55,9 +55,8 @@ class PROJECTEXPLORER_EXPORT ICustomWizardMetaFactory : public QObject
Q_OBJECT
public:
ICustomWizardMetaFactory(const QString &klass, Core::IWizardFactory::WizardKind kind) :
m_klass(klass), m_kind(kind)
{ }
ICustomWizardMetaFactory(const QString &klass, Core::IWizardFactory::WizardKind kind);
~ICustomWizardMetaFactory();
virtual CustomWizard *create() const = 0;
QString klass() const { return m_klass; }
......
......@@ -32,8 +32,6 @@
#include "projectexplorer.h"
#include "target.h"
#include <extensionsystem/pluginmanager.h>
#include <utils/algorithm.h>
namespace ProjectExplorer {
......@@ -142,9 +140,22 @@ bool DeployConfiguration::isActive() const
// DeployConfigurationFactory
///
static QList<DeployConfigurationFactory *> g_deployConfigurationFactories;
DeployConfigurationFactory::DeployConfigurationFactory()
{
setObjectName("DeployConfigurationFactory");
g_deployConfigurationFactories.append(this);
}
DeployConfigurationFactory::~DeployConfigurationFactory()
{
g_deployConfigurationFactories.removeOne(this);
}
QList<DeployConfigurationFactory *> DeployConfigurationFactory::allDeployConfigurationFactories()
{
return g_deployConfigurationFactories;
}
QList<Core::Id> DeployConfigurationFactory::availableCreationIds(Target *parent) const
......@@ -256,7 +267,7 @@ bool DeployConfigurationFactory::canRestore(Target *parent, const QVariantMap &m
DeployConfigurationFactory *DeployConfigurationFactory::find(Target *parent, const QVariantMap &map)
{
return ExtensionSystem::PluginManager::getObject<DeployConfigurationFactory>(
return Utils::findOrDefault(g_deployConfigurationFactories,
[&parent, &map](DeployConfigurationFactory *factory) {
return factory->canRestore(parent, map);
});
......@@ -264,7 +275,7 @@ DeployConfigurationFactory *DeployConfigurationFactory::find(Target *parent, con
QList<DeployConfigurationFactory *> DeployConfigurationFactory::find(Target *parent)
{
return ExtensionSystem::PluginManager::getObjects<DeployConfigurationFactory>(
return Utils::filtered(g_deployConfigurationFactories,
[&parent](DeployConfigurationFactory *factory) {
return !factory->availableCreationIds(parent).isEmpty();
});
......@@ -272,7 +283,7 @@ QList<DeployConfigurationFactory *> DeployConfigurationFactory::find(Target *par
DeployConfigurationFactory *DeployConfigurationFactory::find(Target *parent, DeployConfiguration *dc)
{
return ExtensionSystem::PluginManager::getObject<DeployConfigurationFactory>(
return Utils::findOrDefault(g_deployConfigurationFactories,
[&parent, &dc](DeployConfigurationFactory *factory) {
return factory->canClone(parent, dc);
});
......
......@@ -78,6 +78,9 @@ class PROJECTEXPLORER_EXPORT DeployConfigurationFactory : public QObject
public:
DeployConfigurationFactory();
~DeployConfigurationFactory();
static QList<DeployConfigurationFactory *> allDeployConfigurationFactories();
// used to show the list of possible additons to a target, returns a list of types
QList<Core::Id> availableCreationIds(Target *parent) const;
......
......@@ -31,8 +31,6 @@
#include <coreplugin/id.h>
#include <extensionsystem/pluginmanager.h>
#include <QPushButton>
namespace ProjectExplorer {
......@@ -44,9 +42,7 @@ DeviceFactorySelectionDialog::DeviceFactorySelectionDialog(QWidget *parent) :
ui->setupUi(this);
ui->buttonBox->button(QDialogButtonBox::Ok)->setText(tr("Start Wizard"));
const QList<IDeviceFactory *> &factories
= ExtensionSystem::PluginManager::getObjects<IDeviceFactory>();
foreach (const IDeviceFactory * const factory, factories) {
for (const IDeviceFactory * const factory : IDeviceFactory::allDeviceFactories()) {
if (!factory->canCreate())
continue;
foreach (Core::Id id, factory->availableCreationIds()) {
......
......@@ -29,7 +29,7 @@
#include <coreplugin/icore.h>
#include <coreplugin/messagemanager.h>
#include <extensionsystem/pluginmanager.h>
#include <projectexplorer/project.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <ssh/sshhostkeydatabase.h>
......@@ -338,7 +338,7 @@ void DeviceManager::setDefaultDevice(Core::Id id)
const IDeviceFactory *DeviceManager::restoreFactory(const QVariantMap &map)
{
IDeviceFactory *factory = ExtensionSystem::PluginManager::getObject<IDeviceFactory>(
IDeviceFactory *factory = Utils::findOrDefault(IDeviceFactory::allDeviceFactories(),
[&map](IDeviceFactory *factory) {
return factory->canRestore(map);
});
......
......@@ -38,7 +38,7 @@
#include <projectexplorer/projectexplorericons.h>
#include <coreplugin/icore.h>
#include <extensionsystem/pluginmanager.h>
#include <utils/qtcassert.h>
#include <utils/algorithm.h>
......@@ -111,10 +111,8 @@ void DeviceSettingsWidget::initGui()
m_ui->configurationComboBox->setModel(m_deviceManagerModel);
m_ui->nameLineEdit->setValidator(m_nameValidator);
const QList<IDeviceFactory *> &factories
= ExtensionSystem::PluginManager::getObjects<IDeviceFactory>();
bool hasDeviceFactories = Utils::anyOf(factories, &IDeviceFactory::canCreate);
bool hasDeviceFactories = Utils::anyOf(IDeviceFactory::allDeviceFactories(),
&IDeviceFactory::canCreate);
m_ui->addConfigButton->setEnabled(hasDeviceFactories);
......
......@@ -25,7 +25,7 @@
#include "idevicefactory.h"
#include <extensionsystem/pluginmanager.h>
#include <utils/algorithm.h>
namespace ProjectExplorer {
......@@ -83,15 +83,29 @@ bool IDeviceFactory::canCreate() const
return !availableCreationIds().isEmpty();
}
static QList<IDeviceFactory *> g_deviceFactories;
IDeviceFactory *IDeviceFactory::find(Core::Id type)
{
return ExtensionSystem::PluginManager::getObject<IDeviceFactory>(
return Utils::findOrDefault(g_deviceFactories,
[&type](IDeviceFactory *factory) {
return factory->availableCreationIds().contains(type);
});
}
IDeviceFactory::IDeviceFactory(QObject *parent) : QObject(parent)
{ }
{
g_deviceFactories.append(this);
}
IDeviceFactory::~IDeviceFactory()
{
g_deviceFactories.removeOne(this);
}
const QList<IDeviceFactory *> IDeviceFactory::allDeviceFactories()
{
return g_deviceFactories;
}
} // namespace ProjectExplorer
......@@ -44,6 +44,8 @@ class PROJECTEXPLORER_EXPORT IDeviceFactory : public QObject
Q_OBJECT
public:
~IDeviceFactory();
static const QList<IDeviceFactory *> allDeviceFactories();
virtual QString displayNameForId(Core::Id type) const = 0;
......
......@@ -34,7 +34,11 @@ namespace ProjectExplorer {
class PROJECTEXPLORER_EXPORT IPotentialKit : public QObject
{
Q_OBJECT
public:
IPotentialKit();
~IPotentialKit() override;
virtual QString displayName() const = 0;
virtual void executeFromMenu() = 0;
virtual QWidget *createWidget(QWidget *parent) const = 0;
......
......@@ -44,7 +44,8 @@ class PROJECTEXPLORER_EXPORT ITaskHandler : public QObject
Q_OBJECT
public:
virtual ~ITaskHandler() { }
ITaskHandler();
~ITaskHandler() override;
virtual bool isDefaultHandler() const { return false; }
virtual bool canHandle(const Task &) const = 0;
......
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