diff options
author | Alan Alpert <aalpert@rim.com> | 2012-12-03 08:48:18 -0800 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2012-12-05 19:20:51 +0100 |
commit | dc96bfd00152e25f007511f64bff7c413f657886 (patch) | |
tree | aa5ee99d99c5e8c64dbb36eb038398e2e399abab /src | |
parent | ad86cd24157cc6ded679f40807591981fe52d540 (diff) |
Delay loading implicit import
As a performance improvement to avoid accessing the filesystem
unecessarily, 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: I8a8f10f7a790e6a02fc2c07c443f7be1984fc979
Reviewed-by: Matthew Vogt <matthew.vogt@qinetic.com.au>
Reviewed-by: Christopher Adams <chris.adams@jollamobile.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/declarative/qml/qdeclarativeimport.cpp | 28 | ||||
-rw-r--r-- | src/declarative/qml/qdeclarativescriptparser_p.h | 2 | ||||
-rw-r--r-- | src/declarative/qml/qdeclarativetypeloader.cpp | 72 |
3 files changed, 66 insertions, 36 deletions
diff --git a/src/declarative/qml/qdeclarativeimport.cpp b/src/declarative/qml/qdeclarativeimport.cpp index 20331786..db062e47 100644 --- a/src/declarative/qml/qdeclarativeimport.cpp +++ b/src/declarative/qml/qdeclarativeimport.cpp @@ -441,6 +441,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) { @@ -588,12 +595,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 671326a2..0d02aba5 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 012afb39..135bff89 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) { |