QmlJS: Speed up ValueOwner construction.

* Don't build all default values (including the global object)
  separately for each ValueOwner instance.
* Instead, keep all global, immutable values in a single, shared
  instance.

While refactoring, some cases where we *modified* the global object had
to be removed:

* C++ context properties no longer get injected into the global object,
  instead they now have their own scope just above the global one.
* The Qt object's prototype no longer gets modified in Link. Instead,
  it's now a reference to the "Qt" object provided in a qmltypes file.
* The whole concept of a function 'Activation' that could potentially
  affect the global object was removed.

Change-Id: Id382faf965efa747fcc7a9b0bc2c90429d84d61b
Reviewed-by: Leandro Melo <leandro.melo@nokia.com>
This commit is contained in:
Christian Kamm
2011-11-21 14:51:03 +01:00
parent e2b0835b58
commit 097850c842
8 changed files with 408 additions and 728 deletions

View File

@@ -154,8 +154,8 @@ Link::Link(const Snapshot &snapshot, const QStringList &importPaths, const Libra
d->valueOwner->cppQmlTypes().load(cppData.exportedTypes);
}
// populate global object with context properties from C++
ObjectValue *global = d->valueOwner->globalObject();
// build an object with the context properties from C++
ObjectValue *cppContextProperties = d->valueOwner->newObject(/* prototype = */ 0);
foreach (const ModelManagerInterface::CppData &cppData, cppDataHash) {
QHashIterator<QString, QString> it(cppData.contextProperties);
while (it.hasNext()) {
@@ -166,9 +166,10 @@ Link::Link(const Snapshot &snapshot, const QStringList &importPaths, const Libra
value = d->valueOwner->cppQmlTypes().objectByCppName(cppTypeName);
if (!value)
value = d->valueOwner->unknownValue();
global->setMember(it.key(), value);
cppContextProperties->setMember(it.key(), value);
}
}
d->valueOwner->cppQmlTypes().setCppContextProperties(cppContextProperties);
}
}
@@ -205,11 +206,6 @@ Context::ImportsPerDocument LinkPrivate::linkImports()
// load library objects shipped with Creator
valueOwner->cppQmlTypes().load(CppQmlTypesLoader::defaultLibraryObjects);
// the 'Qt' object is dumped even though it is not exported
// it contains useful information, in particular on enums - add the
// object as a prototype to our custom Qt object to offer these for completion
const_cast<ObjectValue *>(valueOwner->qtObject())->setPrototype(valueOwner->cppQmlTypes().objectByCppName(QLatin1String("Qt")));
if (document) {
// do it on document first, to make sure import errors are shown
Imports *imports = new Imports(valueOwner);