diff options
author | Christian Kamm <christian.d.kamm@nokia.com> | 2011-01-06 10:01:45 +0100 |
---|---|---|
committer | Christian Kamm <christian.d.kamm@nokia.com> | 2011-01-06 15:02:06 +0100 |
commit | 283a3d32cda68b0dcf7642d9ddbfb60dd88d9ccb (patch) | |
tree | 0e6a9ea92cb6c7dfa60bbe8d662b55a1872cc5dd /src/plugins/qmljstools | |
parent | c7070526ec34d0bea66bde2ada0cb2e52d1613db (diff) | |
download | qt-creator-283a3d32cda68b0dcf7642d9ddbfb60dd88d9ccb.tar.gz |
Qml/C++: Fix performance problem with type extraction.
By moving the offending code into a background thread.
Reviewed-by: Erik Verbruggen
Diffstat (limited to 'src/plugins/qmljstools')
-rw-r--r-- | src/plugins/qmljstools/qmljsmodelmanager.cpp | 45 | ||||
-rw-r--r-- | src/plugins/qmljstools/qmljsmodelmanager.h | 12 |
2 files changed, 52 insertions, 5 deletions
diff --git a/src/plugins/qmljstools/qmljsmodelmanager.cpp b/src/plugins/qmljstools/qmljsmodelmanager.cpp index 377d2540e5..6f0463470d 100644 --- a/src/plugins/qmljstools/qmljsmodelmanager.cpp +++ b/src/plugins/qmljstools/qmljsmodelmanager.cpp @@ -40,6 +40,9 @@ #include <coreplugin/progressmanager/progressmanager.h> #include <coreplugin/mimedatabase.h> #include <cplusplus/ModelManagerInterface.h> +#include <cplusplus/CppDocument.h> +#include <cplusplus/TypeOfExpression.h> +#include <cplusplus/Overview.h> #include <qmljs/qmljsinterpreter.h> #include <qmljs/qmljsbind.h> #include <qmljs/parser/qmldirparser_p.h> @@ -77,7 +80,7 @@ ModelManager::ModelManager(QObject *parent): m_updateCppQmlTypesTimer = new QTimer(this); m_updateCppQmlTypesTimer->setInterval(1000); m_updateCppQmlTypesTimer->setSingleShot(true); - connect(m_updateCppQmlTypesTimer, SIGNAL(timeout()), SLOT(updateCppQmlTypes())); + connect(m_updateCppQmlTypesTimer, SIGNAL(timeout()), SLOT(startCppQmlTypeUpdate())); qRegisterMetaType<QmlJS::Document::Ptr>("QmlJS::Document::Ptr"); qRegisterMetaType<QmlJS::LibraryInfo>("QmlJS::LibraryInfo"); @@ -94,7 +97,7 @@ void ModelManager::delayedInitialization() CPlusPlus::CppModelManagerInterface::instance(); if (cppModelManager) { connect(cppModelManager, SIGNAL(documentUpdated(CPlusPlus::Document::Ptr)), - m_updateCppQmlTypesTimer, SLOT(start())); + this, SLOT(queueCppQmlTypeUpdate(CPlusPlus::Document::Ptr))); } } @@ -555,12 +558,46 @@ void ModelManager::loadPluginTypes(const QString &libraryPath, const QString &im m_pluginDumper->loadPluginTypes(libraryPath, importPath, importUri); } -void ModelManager::updateCppQmlTypes() +void ModelManager::queueCppQmlTypeUpdate(const CPlusPlus::Document::Ptr &doc) +{ + m_queuedCppDocuments.insert(doc->fileName()); + m_updateCppQmlTypesTimer->start(); +} + +void ModelManager::startCppQmlTypeUpdate() { CPlusPlus::CppModelManagerInterface *cppModelManager = CPlusPlus::CppModelManagerInterface::instance(); if (!cppModelManager) return; - Interpreter::CppQmlTypesLoader::cppObjects = cppModelManager->exportedQmlObjects(); + QtConcurrent::run(&ModelManager::updateCppQmlTypes, + this, cppModelManager, m_queuedCppDocuments); + m_queuedCppDocuments.clear(); +} + +void ModelManager::updateCppQmlTypes(ModelManager *qmlModelManager, CPlusPlus::CppModelManagerInterface *cppModelManager, QSet<QString> files) +{ + CppQmlTypeHash newCppTypes = qmlModelManager->cppQmlTypes(); + CPlusPlus::Snapshot snapshot = cppModelManager->snapshot(); + + foreach (const QString &fileName, files) { + CPlusPlus::Document::Ptr doc = snapshot.document(fileName); + QList<LanguageUtils::FakeMetaObject::ConstPtr> exported; + if (doc) + exported = cppModelManager->exportedQmlObjects(doc); + if (!exported.isEmpty()) + newCppTypes[fileName] = exported; + else + newCppTypes.remove(fileName); + } + + QMutexLocker locker(&qmlModelManager->m_cppTypesMutex); + qmlModelManager->m_cppTypes = newCppTypes; +} + +ModelManagerInterface::CppQmlTypeHash ModelManager::cppQmlTypes() const +{ + QMutexLocker locker(&m_cppTypesMutex); + return m_cppTypes; } diff --git a/src/plugins/qmljstools/qmljsmodelmanager.h b/src/plugins/qmljstools/qmljsmodelmanager.h index 1a0b4c2833..b4a98cabce 100644 --- a/src/plugins/qmljstools/qmljsmodelmanager.h +++ b/src/plugins/qmljstools/qmljsmodelmanager.h @@ -38,6 +38,8 @@ #include <qmljs/qmljsmodelmanagerinterface.h> #include <qmljs/qmljsdocument.h> +#include <cplusplus/CppDocument.h> +#include <cplusplus/ModelManagerInterface.h> #include <QFuture> #include <QFutureSynchronizer> @@ -85,6 +87,8 @@ public: virtual void loadPluginTypes(const QString &libraryPath, const QString &importPath, const QString &importUri); + virtual CppQmlTypeHash cppQmlTypes() const; + Q_SIGNALS: void projectPathChanged(const QString &projectPath); @@ -104,10 +108,12 @@ protected: void updateImportPaths(); private slots: - void updateCppQmlTypes(); + void queueCppQmlTypeUpdate(const CPlusPlus::Document::Ptr &doc); + void startCppQmlTypeUpdate(); private: static bool matchesMimeType(const Core::MimeType &fileMimeType, const Core::MimeType &knownMimeType); + static void updateCppQmlTypes(ModelManager *qmlModelManager, CPlusPlus::CppModelManagerInterface *cppModelManager, QSet<QString> files); mutable QMutex m_mutex; Core::ICore *m_core; @@ -116,7 +122,11 @@ private: QStringList m_defaultImportPaths; QFutureSynchronizer<void> m_synchronizer; + QTimer *m_updateCppQmlTypesTimer; + QSet<QString> m_queuedCppDocuments; + CppQmlTypeHash m_cppTypes; + mutable QMutex m_cppTypesMutex; // project integration QMap<ProjectExplorer::Project *, ProjectInfo> m_projects; |