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
......@@ -47,9 +47,10 @@ class QMLJSTOOLS_EXPORT IBundleProvider : public QObject
{
Q_OBJECT
public:
explicit IBundleProvider(QObject *parent = 0)
: QObject(parent)
{ }
explicit IBundleProvider(QObject *parent = 0);
~IBundleProvider();
static const QList<IBundleProvider *> allBundleProviders();
virtual void mergeBundlesForKit(ProjectExplorer::Kit *kit, QmlJS::QmlLanguageBundles &bundles
, const QHash<QString,QString> &replacements) = 0;
......
......@@ -88,10 +88,8 @@ TextEditor::Indenter *QmlJSCodeStylePreferencesFactory::createIndenter() const
TextEditor::SnippetProvider *QmlJSCodeStylePreferencesFactory::snippetProvider() const
{
return ExtensionSystem::PluginManager::getObject<TextEditor::SnippetProvider>(
[](TextEditor::SnippetProvider *provider) {
return provider->groupId() == QLatin1String(QmlJSEditor::Constants::QML_SNIPPETS_GROUP_ID);
});
return TextEditor::SnippetProvider::snippetProviderForGroupId
(QmlJSEditor::Constants::QML_SNIPPETS_GROUP_ID);
}
QString QmlJSCodeStylePreferencesFactory::previewText() const
......
......@@ -80,13 +80,10 @@ void QmlJSCodeStylePreferencesWidget::setPreferences(ICodeStylePreferences *pref
updatePreview();
}
void QmlJSCodeStylePreferencesWidget::decorateEditor(const FontSettings &fontSettings)
{
const SnippetProvider *provider = ExtensionSystem::PluginManager::getObject<SnippetProvider>(
[](SnippetProvider *current) {
return current->groupId() == QLatin1String(QmlJSEditor::Constants::QML_SNIPPETS_GROUP_ID);
});
const SnippetProvider *provider =
SnippetProvider::snippetProviderForGroupId(QmlJSEditor::Constants::QML_SNIPPETS_GROUP_ID);
m_ui->previewTextEdit->textDocument()->setFontSettings(fontSettings);
if (provider)
......
......@@ -33,8 +33,9 @@
#include <coreplugin/editormanager/ieditor.h>
#include <coreplugin/messagemanager.h>
#include <coreplugin/progressmanager/progressmanager.h>
#include <cpptools/cppmodelmanager.h>
#include <extensionsystem/pluginmanager.h>
#include <projectexplorer/buildconfiguration.h>
#include <projectexplorer/project.h>
#include <projectexplorer/projectexplorerconstants.h>
......@@ -152,13 +153,9 @@ void setupProjectInfoQmlBundles(ModelManagerInterface::ProjectInfo &projectInfo)
replacements.insert(QLatin1String("$(QT_INSTALL_IMPORTS)"), projectInfo.qtImportsPath);
replacements.insert(QLatin1String("$(QT_INSTALL_QML)"), projectInfo.qtQmlPath);
QList<IBundleProvider *> bundleProviders =
ExtensionSystem::PluginManager::getObjects<IBundleProvider>();
for (IBundleProvider *bp : IBundleProvider::allBundleProviders())
bp->mergeBundlesForKit(activeKit, projectInfo.activeBundle, replacements);
foreach (IBundleProvider *bp, bundleProviders) {
if (bp)
bp->mergeBundlesForKit(activeKit, projectInfo.activeBundle, replacements);
}
projectInfo.extendedBundle = projectInfo.activeBundle;
if (projectInfo.project) {
......@@ -167,9 +164,8 @@ void setupProjectInfoQmlBundles(ModelManagerInterface::ProjectInfo &projectInfo)
currentKits.insert(t->kit());
currentKits.remove(activeKit);
foreach (Kit *kit, currentKits) {
foreach (IBundleProvider *bp, bundleProviders)
if (bp)
bp->mergeBundlesForKit(kit, projectInfo.extendedBundle, replacements);
for (IBundleProvider *bp : IBundleProvider::allBundleProviders())
bp->mergeBundlesForKit(kit, projectInfo.extendedBundle, replacements);
}
}
}
......
......@@ -36,13 +36,22 @@
using namespace QtSupport;
using namespace QtSupport::Internal;
static QList<QtVersionFactory *> g_qtVersionFactories;
QtVersionFactory::QtVersionFactory(QObject *parent) :
QObject(parent)
{
g_qtVersionFactories.append(this);
}
QtVersionFactory::~QtVersionFactory()
{
g_qtVersionFactories.removeOne(this);
}
const QList<QtVersionFactory *> QtVersionFactory::allQtVersionFactories()
{
return g_qtVersionFactories;
}
BaseQtVersion *QtVersionFactory::createQtVersionFromQMakePath(const Utils::FileName &qmakePath, bool isAutoDetected, const QString &autoDetectionSource, QString *error)
......@@ -62,7 +71,7 @@ BaseQtVersion *QtVersionFactory::createQtVersionFromQMakePath(const Utils::FileN
ProFileEvaluator evaluator(&globals, &parser, &vfs, &msgHandler);
evaluator.loadNamedSpec(mkspec.toString(), false);
QList<QtVersionFactory *> factories = ExtensionSystem::PluginManager::getObjects<QtVersionFactory>();
QList<QtVersionFactory *> factories = g_qtVersionFactories;
Utils::sort(factories, [](const QtVersionFactory *l, const QtVersionFactory *r) {
return l->priority() > r->priority();
});
......
......@@ -49,6 +49,8 @@ public:
explicit QtVersionFactory(QObject *parent = 0);
~QtVersionFactory();
static const QList<QtVersionFactory *> allQtVersionFactories();
virtual bool canRestore(const QString &type) = 0;
virtual BaseQtVersion *restore(const QString &type, const QVariantMap &data) = 0;
......
......@@ -179,7 +179,7 @@ static bool restoreQtVersions()
m_writer = new PersistentSettingsWriter(settingsFileName(QLatin1String(QTVERSION_FILENAME)),
QLatin1String("QtCreatorQtVersions"));
QList<QtVersionFactory *> factories = ExtensionSystem::PluginManager::getObjects<QtVersionFactory>();
const QList<QtVersionFactory *> factories = QtVersionFactory::allQtVersionFactories();
PersistentSettingsReader reader;
FileName filename = settingsFileName(QLatin1String(QTVERSION_FILENAME));
......@@ -208,7 +208,7 @@ static bool restoreQtVersions()
const QString type = qtversionMap.value(QLatin1String(QTVERSION_TYPE_KEY)).toString();
bool restored = false;
foreach (QtVersionFactory *f, factories) {
for (QtVersionFactory *f : factories) {
if (f->canRestore(type)) {
if (BaseQtVersion *qtv = f->restore(type, qtversionMap)) {
if (m_versions.contains(qtv->uniqueId())) {
......@@ -249,7 +249,7 @@ void QtVersionManager::updateFromInstaller(bool emitSignal)
QList<int> removed;
QList<int> changed;
QList<QtVersionFactory *> factories = ExtensionSystem::PluginManager::getObjects<QtVersionFactory>();
const QList<QtVersionFactory *> factories = QtVersionFactory::allQtVersionFactories();
PersistentSettingsReader reader;
QVariantMap data;
if (reader.load(path))
......
......@@ -46,9 +46,14 @@ public:
virtual QVariantMap settings() const { return QVariantMap(); }
};
class TEXTEDITOR_EXPORT IOutlineWidgetFactory : public QObject {
class TEXTEDITOR_EXPORT IOutlineWidgetFactory : public QObject
{
Q_OBJECT
public:
IOutlineWidgetFactory();
~IOutlineWidgetFactory() override;
virtual bool supportsEditor(Core::IEditor *editor) const = 0;
virtual IOutlineWidget *createWidget(Core::IEditor *editor) = 0;
};
......
......@@ -38,6 +38,19 @@
#include <QDebug>
namespace TextEditor {
static QList<IOutlineWidgetFactory *> g_outlineWidgetFactories;
IOutlineWidgetFactory::IOutlineWidgetFactory()
{
g_outlineWidgetFactories.append(this);
}
IOutlineWidgetFactory::~IOutlineWidgetFactory()
{
g_outlineWidgetFactories.removeOne(this);
}
namespace Internal {
OutlineWidgetStack::OutlineWidgetStack(OutlineFactory *factory) :
......@@ -153,7 +166,7 @@ void OutlineWidgetStack::updateCurrentEditor(Core::IEditor *editor)
IOutlineWidget *newWidget = 0;
if (editor) {
foreach (IOutlineWidgetFactory *widgetFactory, m_factory->widgetFactories()) {
for (IOutlineWidgetFactory *widgetFactory : g_outlineWidgetFactories) {
if (widgetFactory->supportsEditor(editor)) {
newWidget = widgetFactory->createWidget(editor);
break;
......@@ -189,16 +202,6 @@ OutlineFactory::OutlineFactory()
setPriority(600);
}
QList<IOutlineWidgetFactory*> OutlineFactory::widgetFactories() const
{
return m_factories;
}
void OutlineFactory::setWidgetFactories(QList<IOutlineWidgetFactory*> factories)
{
m_factories = factories;
}
Core::NavigationView OutlineFactory::createWidget()
{
Core::NavigationView n;
......
......@@ -72,15 +72,10 @@ class OutlineFactory : public Core::INavigationWidgetFactory
public:
OutlineFactory();
QList<IOutlineWidgetFactory*> widgetFactories() const;
void setWidgetFactories(QList<IOutlineWidgetFactory*> factories);
// from INavigationWidgetFactory
virtual Core::NavigationView createWidget();
virtual void saveSettings(QSettings *settings, int position, QWidget *widget);
virtual void restoreSettings(QSettings *settings, int position, QWidget *widget);
private:
QList<IOutlineWidgetFactory*> m_factories;
};
} // namespace Internal
......
......@@ -56,11 +56,20 @@ void QuickFixOperation::setDescription(const QString &description)
_description = description;
}
static QList<QuickFixFactory *> g_quickFixFactories;
QuickFixFactory::QuickFixFactory(QObject *parent)
: QObject(parent)
{
g_quickFixFactories.append(this);
}
QuickFixFactory::~QuickFixFactory()
{
g_quickFixFactories.removeOne(this);
}
const QList<QuickFixFactory *> QuickFixFactory::allQuickFixFactories()
{
return g_quickFixFactories;
}
......@@ -114,6 +114,8 @@ public:
QuickFixFactory(QObject *parent = 0);
~QuickFixFactory();
static const QList<QuickFixFactory *> allQuickFixFactories();
virtual void matchingOperations(const QuickFixInterface &interface, QuickFixOperations &result) = 0;
};
......
......@@ -27,8 +27,33 @@
#include "texteditorplugin.h"
#include <utils/algorithm.h>
using namespace TextEditor;
static QList<SnippetProvider *> g_snippetProviders;
const QList<SnippetProvider *> SnippetProvider::snippetProviders()
{
return g_snippetProviders;
}
SnippetProvider *SnippetProvider::snippetProviderForGroupId(const QString &groupId)
{
return Utils::findOrDefault(g_snippetProviders,
Utils::equal(&SnippetProvider::groupId, groupId));
}
SnippetProvider::SnippetProvider()
{
g_snippetProviders.append(this);
}
SnippetProvider::~SnippetProvider()
{
g_snippetProviders.removeOne(this);
}
/*!
\group Snippets
\title Snippets for Editors
......
......@@ -41,6 +41,9 @@ class TEXTEDITOR_EXPORT SnippetProvider : public QObject
public:
using EditorDecorator = std::function<void(TextEditorWidget *)>;
static const QList<SnippetProvider *> snippetProviders();
static SnippetProvider *snippetProviderForGroupId(const QString &groupId);
static void registerGroup(const QString &groupId, const QString &displayName,
EditorDecorator editorDecorator = EditorDecorator());
......@@ -51,7 +54,8 @@ public:
void decorateEditor(TextEditorWidget *editor) const;
private:
SnippetProvider() = default;
SnippetProvider();
~SnippetProvider() override;
QString m_groupId;
QString m_displayName;
......
......@@ -409,9 +409,7 @@ int SnippetsCollection::groupIndex(const QString &groupId) const
void SnippetsCollection::identifyGroups()
{
const QList<SnippetProvider *> &providers =
ExtensionSystem::PluginManager::getObjects<SnippetProvider>();
foreach (SnippetProvider *provider, providers) {
for (SnippetProvider *provider : SnippetProvider::snippetProviders()) {
const int groupIndex = m_groupIndexById.size();
m_groupIndexById.insert(provider->groupId(), groupIndex);
m_snippets.resize(groupIndex + 1);
......
......@@ -328,9 +328,8 @@ void SnippetsSettingsPagePrivate::configureUi(QWidget *w)
{
m_ui.setupUi(w);
const QList<SnippetProvider *> &providers =
ExtensionSystem::PluginManager::getObjects<SnippetProvider>();
foreach (SnippetProvider *provider, providers) {
const QList<SnippetProvider *> &providers = SnippetProvider::snippetProviders();
for (SnippetProvider *provider : providers) {
m_ui.groupCombo->addItem(provider->displayName(), provider->groupId());
SnippetEditorWidget *snippetEditor = new SnippetEditorWidget(w);
provider->decorateEditor(snippetEditor);
......@@ -537,8 +536,7 @@ void SnippetsSettingsPagePrivate::setSnippetContent()
void SnippetsSettingsPagePrivate::decorateEditors(const TextEditor::FontSettings &fontSettings)
{
const QList<SnippetProvider *> &providers =
ExtensionSystem::PluginManager::getObjects<SnippetProvider>();
const QList<SnippetProvider *> &providers = SnippetProvider::snippetProviders();
for (int i = 0; i < m_ui.groupCombo->count(); ++i) {
SnippetEditorWidget *snippetEditor = editorAt(i);
snippetEditor->textDocument()->setFontSettings(fontSettings);
......
......@@ -147,8 +147,6 @@ bool TextEditorPlugin::initialize(const QStringList &arguments, QString *errorMe
void TextEditorPlugin::extensionsInitialized()
{
m_outlineFactory->setWidgetFactories(ExtensionSystem::PluginManager::getObjects<TextEditor::IOutlineWidgetFactory>());
connect(m_settings, &TextEditorSettings::fontSettingsChanged,
this, &TextEditorPlugin::updateSearchResultsFont);
......
......@@ -83,10 +83,13 @@ VcsEditorFactory::VcsEditorFactory(const VcsBaseEditorParameters *parameters,
VcsBaseEditor *VcsEditorFactory::createEditorById(const char *id)
{
auto factory = ExtensionSystem::PluginManager::getObject<VcsEditorFactory>(
[id](QObject *ob) { return ob->property("VcsEditorFactoryName").toByteArray() == id; });
QTC_ASSERT(factory, return 0);
return qobject_cast<VcsBaseEditor *>(factory->createEditor());
for (IEditorFactory *factory : allEditorFactories()) {
if (auto vcsFactory = qobject_cast<VcsEditorFactory *>(factory)) {
if (vcsFactory->property("VcsEditorFactoryName").toByteArray() == id)
return qobject_cast<VcsBaseEditor *>(factory->createEditor());
}
}
return nullptr;
}
} // namespace VcsBase
......@@ -343,8 +343,7 @@ void WelcomeMode::initPlugins()
QSettings *settings = ICore::settings();
m_activePage = Id::fromSetting(settings->value(currentPageSettingsKeyC));
const QList<IWelcomePage *> availablePages = PluginManager::getObjects<IWelcomePage>();
for (IWelcomePage *page : availablePages)
for (IWelcomePage *page : IWelcomePage::allWelcomePages())
addPage(page);
// make sure later added pages are made available too:
......
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