summaryrefslogtreecommitdiffstats
path: root/src/declarative/qml
diff options
context:
space:
mode:
authormae <qt-info@nokia.com>2010-03-31 10:27:55 (GMT)
committermae <qt-info@nokia.com>2010-03-31 10:40:29 (GMT)
commit93ee746f5b63670af280dfe2e8acaebeb48723b8 (patch)
treef21a94e4cec681dee6060c8e9611e0ca8d36f164 /src/declarative/qml
parente28f10e0d8dfc7d34ead2725eac8ed852b61f070 (diff)
downloadQt-93ee746f5b63670af280dfe2e8acaebeb48723b8.zip
Qt-93ee746f5b63670af280dfe2e8acaebeb48723b8.tar.gz
Qt-93ee746f5b63670af280dfe2e8acaebeb48723b8.tar.bz2
Optimize QDeclarativeEngine::importExtension
Avoid double initialization of QPluginLoader and assert that modules are imported with a stable uri
Diffstat (limited to 'src/declarative/qml')
-rw-r--r--src/declarative/qml/qdeclarativeengine.cpp51
1 files changed, 31 insertions, 20 deletions
diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp
index bb742ee..5058d4d 100644
--- a/src/declarative/qml/qdeclarativeengine.cpp
+++ b/src/declarative/qml/qdeclarativeengine.cpp
@@ -81,6 +81,7 @@
#include <QDebug>
#include <QMetaObject>
#include <QStack>
+#include <QMap>
#include <QPluginLoader>
#include <QtCore/qlibraryinfo.h>
#include <QtCore/qthreadstorage.h>
@@ -342,7 +343,8 @@ void QDeclarativeEnginePrivate::clear(SimpleList<QDeclarativeParserStatus> &pss)
}
Q_GLOBAL_STATIC(QDeclarativeEngineDebugServer, qmlEngineDebugServer);
-Q_GLOBAL_STATIC(QSet<QString>, qmlEnginePluginsWithRegisteredTypes);
+typedef QMap<QString, QString> StringStringMap;
+Q_GLOBAL_STATIC(StringStringMap, qmlEnginePluginsWithRegisteredTypes); // stores the uri
void QDeclarativeEnginePrivate::init()
{
@@ -1838,34 +1840,43 @@ bool QDeclarativeEngine::importExtension(const QString &fileName, const QString
qDebug() << "QDeclarativeEngine::importExtension" << uri << "from" << fileName;
QFileInfo fileInfo(fileName);
const QString absoluteFilePath = fileInfo.absoluteFilePath();
- QPluginLoader loader(absoluteFilePath);
- if (QDeclarativeExtensionInterface *iface = qobject_cast<QDeclarativeExtensionInterface *>(loader.instance())) {
- const QByteArray bytes = uri.toUtf8();
- const char *moduleId = bytes.constData();
+ QDeclarativeEnginePrivate *d = QDeclarativeEnginePrivate::get(this);
+ bool engineInitialized = d->initializedPlugins.contains(absoluteFilePath);
+ bool typesRegistered = qmlEnginePluginsWithRegisteredTypes()->contains(absoluteFilePath);
- // ### this code should probably be protected with a mutex.
- if (! qmlEnginePluginsWithRegisteredTypes()->contains(absoluteFilePath)) {
- // types should only be registered once (they're global).
+ if (typesRegistered) {
+ Q_ASSERT_X(qmlEnginePluginsWithRegisteredTypes()->value(absoluteFilePath) == uri,
+ "QDeclarativeEngine::importExtension",
+ "Internal error: Plugin imported previously with different uri");
+ }
- qmlEnginePluginsWithRegisteredTypes()->insert(absoluteFilePath);
- iface->registerTypes(moduleId);
- }
+ if (!engineInitialized || !typesRegistered) {
+ QPluginLoader loader(absoluteFilePath);
- QDeclarativeEnginePrivate *d = QDeclarativeEnginePrivate::get(this);
+ if (QDeclarativeExtensionInterface *iface = qobject_cast<QDeclarativeExtensionInterface *>(loader.instance())) {
- if (! d->initializedPlugins.contains(absoluteFilePath)) {
- // things on the engine (eg. adding new global objects) have to be done for every engine.
+ const QByteArray bytes = uri.toUtf8();
+ const char *moduleId = bytes.constData();
+ if (!typesRegistered) {
- // protect against double initialization
- d->initializedPlugins.insert(absoluteFilePath);
- iface->initializeEngine(this, moduleId);
- }
+ // ### this code should probably be protected with a mutex.
+ qmlEnginePluginsWithRegisteredTypes()->insert(absoluteFilePath, uri);
+ iface->registerTypes(moduleId);
+ }
+ if (!engineInitialized) {
+ // things on the engine (eg. adding new global objects) have to be done for every engine.
- return true;
+ // protect against double initialization
+ d->initializedPlugins.insert(absoluteFilePath);
+ iface->initializeEngine(this, moduleId);
+ }
+ } else {
+ return false;
+ }
}
- return false;
+ return true;
}
/*!