summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlan Alpert <aalpert@rim.com>2012-12-05 19:36:37 (GMT)
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-01-08 21:59:24 (GMT)
commit6e939f63b4e7b8ed678f4d551ada35dfb2e76e11 (patch)
treede6ab6e7f01c3013ffa6865d856b84ffb222eff6 /src
parentf5b9d1817c798227fd6be688f11b7159d5b0492f (diff)
downloadQt-6e939f63b4e7b8ed678f4d551ada35dfb2e76e11.zip
Qt-6e939f63b4e7b8ed678f4d551ada35dfb2e76e11.tar.gz
Qt-6e939f63b4e7b8ed678f4d551ada35dfb2e76e11.tar.bz2
Delay loading implicit import
As a performance improvement to avoid accessing the filesystem unnecessarily, only import "." implicitly if types cannot be found in the existing imports. This is not a behavior change for type resolution, because "." already has the lowest precedence for type resolution. Change-Id: I5ac2a9fac85559eb96cba93c29d17068fe8171da Manual cherry-pick of qtquick1/dc96bfd00152e25f007511f64bff7c413f657886 Reviewed-by: Christopher Adams <chris.adams@jollamobile.com>
Diffstat (limited to 'src')
-rw-r--r--src/declarative/qml/qdeclarativeimport.cpp28
-rw-r--r--src/declarative/qml/qdeclarativescriptparser_p.h2
-rw-r--r--src/declarative/qml/qdeclarativetypeloader.cpp72
3 files changed, 66 insertions, 36 deletions
diff --git a/src/declarative/qml/qdeclarativeimport.cpp b/src/declarative/qml/qdeclarativeimport.cpp
index c7a0d78..0518bcb 100644
--- a/src/declarative/qml/qdeclarativeimport.cpp
+++ b/src/declarative/qml/qdeclarativeimport.cpp
@@ -452,6 +452,13 @@ bool QDeclarativeImportsPrivate::add(const QDeclarativeDirComponents &qmldircomp
set.insert(prefix,(s=new QDeclarativeImportedNamespace));
}
+ bool appendInstead = false;
+ if (importType == QDeclarativeScriptParser::Import::Implicit) {
+ //Treat same as a File import, but lower precedence
+ appendInstead = true;
+ importType = QDeclarativeScriptParser::Import::File;
+ }
+
QString url = uri;
bool versionFound = false;
if (importType == QDeclarativeScriptParser::Import::Library) {
@@ -599,12 +606,21 @@ bool QDeclarativeImportsPrivate::add(const QDeclarativeDirComponents &qmldircomp
}
}
- s->uris.prepend(uri);
- s->urls.prepend(url);
- s->majversions.prepend(vmaj);
- s->minversions.prepend(vmin);
- s->isLibrary.prepend(importType == QDeclarativeScriptParser::Import::Library);
- s->qmlDirComponents.prepend(qmldircomponents);
+ if (appendInstead) {
+ s->uris.append(uri);
+ s->urls.append(url);
+ s->majversions.append(vmaj);
+ s->minversions.append(vmin);
+ s->isLibrary.append(importType == QDeclarativeScriptParser::Import::Library);
+ s->qmlDirComponents.append(qmldircomponents);
+ } else {
+ s->uris.prepend(uri);
+ s->urls.prepend(url);
+ s->majversions.prepend(vmaj);
+ s->minversions.prepend(vmin);
+ s->isLibrary.prepend(importType == QDeclarativeScriptParser::Import::Library);
+ s->qmlDirComponents.prepend(qmldircomponents);
+ }
return true;
}
diff --git a/src/declarative/qml/qdeclarativescriptparser_p.h b/src/declarative/qml/qdeclarativescriptparser_p.h
index 671326a..0d02aba 100644
--- a/src/declarative/qml/qdeclarativescriptparser_p.h
+++ b/src/declarative/qml/qdeclarativescriptparser_p.h
@@ -75,7 +75,7 @@ public:
public:
Import() : type(Library) {}
- enum Type { Library, File, Script };
+ enum Type { Library, File, Script, Implicit }; //Implicit is only used internally
Type type;
QString uri;
diff --git a/src/declarative/qml/qdeclarativetypeloader.cpp b/src/declarative/qml/qdeclarativetypeloader.cpp
index 5cce995..50c3639 100644
--- a/src/declarative/qml/qdeclarativetypeloader.cpp
+++ b/src/declarative/qml/qdeclarativetypeloader.cpp
@@ -1055,19 +1055,6 @@ void QDeclarativeTypeData::resolveTypes()
QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(m_typeLoader->engine());
QDeclarativeImportDatabase *importDatabase = &ep->importDatabase;
- // For local urls, add an implicit import "." as first (most overridden) lookup.
- // This will also trigger the loading of the qmldir and the import of any native
- // types from available plugins.
- if (QDeclarativeQmldirData *qmldir = qmldirForUrl(finalUrl().resolved(QUrl(QLatin1String("./qmldir"))))) {
- m_imports.addImport(importDatabase, QLatin1String("."),
- QString(), -1, -1, QDeclarativeScriptParser::Import::File,
- qmldir->dirComponents(), 0);
- } else {
- m_imports.addImport(importDatabase, QLatin1String("."),
- QString(), -1, -1, QDeclarativeScriptParser::Import::File,
- QDeclarativeDirComponents(), 0);
- }
-
foreach (const QDeclarativeScriptParser::Import &import, scriptParser.imports()) {
QDeclarativeDirComponents qmldircomponentsnetwork;
if (import.type == QDeclarativeScriptParser::Import::Script)
@@ -1107,6 +1094,7 @@ void QDeclarativeTypeData::resolveTypes()
}
}
+ bool implicitImportLoaded = false;
foreach (QDeclarativeScriptParser::TypeReference *parserRef, scriptParser.referencedTypes()) {
QByteArray typeName = parserRef->name.toUtf8();
@@ -1123,23 +1111,49 @@ void QDeclarativeTypeData::resolveTypes()
// Known to not be a type:
// - known to be a namespace (Namespace {})
// - type with unknown namespace (UnknownNamespace.SomeType {})
- QDeclarativeError error;
- error.setUrl(m_imports.baseUrl());
- QString userTypeName = parserRef->name;
- userTypeName.replace(QLatin1Char('/'),QLatin1Char('.'));
- if (typeNamespace)
- error.setDescription(QDeclarativeTypeLoader::tr("Namespace %1 cannot be used as a type").arg(userTypeName));
- else
- error.setDescription(QDeclarativeTypeLoader::tr("%1 %2").arg(userTypeName).arg(errorString));
-
- if (!parserRef->refObjects.isEmpty()) {
- QDeclarativeParser::Object *obj = parserRef->refObjects.first();
- error.setLine(obj->location.start.line);
- error.setColumn(obj->location.start.column);
+ bool typeFound = false;
+
+ if (!typeNamespace && !implicitImportLoaded) {
+ implicitImportLoaded = true;
+ // For local urls, add an implicit import "." as most overridden lookup.
+ // This will also trigger the loading of the qmldir and the import of any native
+ // types from available plugins.
+ // This is only done if the type is not otherwise found, side effects of plugin loading may be avoided
+ // ### This should be an acceptable variation because A) It's only side effects (and img providers) B) You shouldn't be doing that in "." anyways!
+ if (QDeclarativeQmldirData *qmldir = qmldirForUrl(finalUrl().resolved(QUrl(QLatin1String("./qmldir"))))) {
+ m_imports.addImport(importDatabase, QLatin1String("."),
+ QString(), -1, -1, QDeclarativeScriptParser::Import::Implicit,
+ qmldir->dirComponents(), 0);
+ } else {
+ m_imports.addImport(importDatabase, QLatin1String("."),
+ QString(), -1, -1, QDeclarativeScriptParser::Import::Implicit,
+ QDeclarativeDirComponents(), 0);
+ }
+ if (m_imports.resolveType(typeName, &ref.type, &url, &majorVersion, &minorVersion,
+ &typeNamespace, &errorString) || typeNamespace) {
+ typeFound = true;
+ }
+ }
+
+ if (!typeFound) {
+ QDeclarativeError error;
+ error.setUrl(m_imports.baseUrl());
+ QString userTypeName = parserRef->name;
+ userTypeName.replace(QLatin1Char('/'),QLatin1Char('.'));
+ if (typeNamespace)
+ error.setDescription(QDeclarativeTypeLoader::tr("Namespace %1 cannot be used as a type").arg(userTypeName));
+ else
+ error.setDescription(QDeclarativeTypeLoader::tr("%1 %2").arg(userTypeName).arg(errorString));
+
+ if (!parserRef->refObjects.isEmpty()) {
+ QDeclarativeParser::Object *obj = parserRef->refObjects.first();
+ error.setLine(obj->location.start.line);
+ error.setColumn(obj->location.start.column);
+ }
+
+ setError(error);
+ return;
}
-
- setError(error);
- return;
}
if (ref.type) {