diff options
author | Simon Hausmann <simon.hausmann@qt.io> | 2016-05-25 14:55:44 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@qt.io> | 2016-05-26 19:57:55 +0000 |
commit | e850416fcffe48cc19cdbf6a01f759964815681c (patch) | |
tree | 87afa793953710a74c530900ab7cbf93fd6cb3cb /src/qml/qml/qqmlcontext.cpp | |
parent | 6f84a09dfbd15aac023580cf06e7b8c24f3b524c (diff) |
Optimize named object handling
By storing the object indices of named objects in the CompiledData::Object of a component,
we can achieve two things:
(1) We can eliminate the hash of vectors in QQmlCompiledData for the object-to-id mapping
(2) We can store the mapping from object name to integer object id in the CompilationUnit and
share it across different QQmlContextData instances (as long as it is not modified).
Also added a new test that verifies the functionality of a .qml file starting
with Component{} itself with object names, something that was previously only
implicitly tested through some of the examples (corkboards.qml for example).
Change-Id: I28c70217222dc0e5252bf5247b7e3fc4def47446
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
Diffstat (limited to 'src/qml/qml/qqmlcontext.cpp')
-rw-r--r-- | src/qml/qml/qqmlcontext.cpp | 44 |
1 files changed, 24 insertions, 20 deletions
diff --git a/src/qml/qml/qqmlcontext.cpp b/src/qml/qml/qqmlcontext.cpp index 11a8e81d8f..b3081ddbe6 100644 --- a/src/qml/qml/qqmlcontext.cpp +++ b/src/qml/qml/qqmlcontext.cpp @@ -310,7 +310,7 @@ void QQmlContext::setContextProperty(const QString &name, const QVariant &value) } } - QV4::IdentifierHash<int> &properties = data->propertyNames(); + QV4::IdentifierHash<int> &properties = data->detachedPropertyNames(); int idx = properties.value(name); if (idx == -1) { properties.add(name, data->idValueCount + d->propertyValues.count()); @@ -346,7 +346,7 @@ void QQmlContext::setContextProperty(const QString &name, QObject *value) return; } - QV4::IdentifierHash<int> &properties = data->propertyNames(); + QV4::IdentifierHash<int> &properties = data->detachedPropertyNames(); int idx = properties.value(name); if (idx == -1) { @@ -523,7 +523,7 @@ QQmlContextData::QQmlContextData() QQmlContextData::QQmlContextData(QQmlContext *ctxt) : parent(0), engine(0), isInternal(false), ownedByParent(false), isJSContext(false), isPragmaLibraryContext(false), unresolvedNames(false), hasEmittedDestruction(false), isRootObjectInCreation(false), - publicContext(ctxt), activeVMEData(0), + publicContext(ctxt), activeVMEData(0), componentObjectIndex(-1), contextObject(0), imports(0), childContexts(0), nextChild(0), prevChild(0), expressions(0), contextObjects(0), contextGuards(0), idValues(0), idValueCount(0), linkedContext(0), componentAttached(0) @@ -760,15 +760,6 @@ void QQmlContextData::setIdProperty(int idx, QObject *obj) idValues[idx].context = this; } -void QQmlContextData::setNamedObjects(const QVector<quint32> &objects) -{ - Q_ASSERT(namedObjects.isEmpty()); - namedObjects = objects; - Q_ASSERT(propertyNameCache.isEmpty()); - idValueCount = objects.count(); - idValues = new ContextGuard[idValueCount]; -} - QString QQmlContextData::findObjectId(const QObject *obj) const { const QV4::IdentifierHash<int> &properties = propertyNames(); @@ -804,20 +795,33 @@ QQmlContextPrivate *QQmlContextData::asQQmlContextPrivate() return QQmlContextPrivate::get(asQQmlContext()); } -QV4::IdentifierHash<int> &QQmlContextData::propertyNames() const +void QQmlContextData::initFromTypeCompilationUnit(const QQmlRefPointer<QV4::CompiledData::CompilationUnit> &unit, int subComponentIndex) +{ + typeCompilationUnit = unit; + componentObjectIndex = subComponentIndex == -1 ? typeCompilationUnit->data->indexOfRootObject : subComponentIndex; + Q_ASSERT(!idValues); + idValueCount = typeCompilationUnit->data->objectAt(componentObjectIndex)->nNamedObjectsInComponent; + idValues = new ContextGuard[idValueCount]; +} + +const QV4::IdentifierHash<int> &QQmlContextData::propertyNames() const { if (propertyNameCache.isEmpty()) { - propertyNameCache = QV4::IdentifierHash<int>(QV8Engine::getV4(engine->handle())); - for (int i = 0; i < namedObjects.count(); ++i) { - const QV4::CompiledData::Object *obj = typeCompilationUnit->data->objectAt(namedObjects.at(i)); - const QString name = typeCompilationUnit->data->stringAt(obj->idNameIndex); - propertyNameCache.add(name, obj->id); - } - namedObjects.clear(); + if (typeCompilationUnit) + propertyNameCache = typeCompilationUnit->namedObjectsPerComponent(componentObjectIndex); + else + propertyNameCache = QV4::IdentifierHash<int>(QV8Engine::getV4(engine)); } return propertyNameCache; } +QV4::IdentifierHash<int> &QQmlContextData::detachedPropertyNames() +{ + propertyNames(); + propertyNameCache.detach(); + return propertyNameCache; +} + QUrl QQmlContextData::url() const { if (typeCompilationUnit) |