diff options
-rw-r--r-- | src/qml/qml/qqmlcontext.cpp | 17 | ||||
-rw-r--r-- | src/qml/qml/qqmlcontext_p.h | 12 | ||||
-rw-r--r-- | src/qml/qml/qqmlobjectcreator.cpp | 12 |
3 files changed, 13 insertions, 28 deletions
diff --git a/src/qml/qml/qqmlcontext.cpp b/src/qml/qml/qqmlcontext.cpp index 3e6ca6667e..f08f650913 100644 --- a/src/qml/qml/qqmlcontext.cpp +++ b/src/qml/qml/qqmlcontext.cpp @@ -760,10 +760,10 @@ void QQmlContextData::setIdProperty(int idx, QObject *obj) idValues[idx].context = this; } -void QQmlContextData::setIdPropertyData(const QVector<ObjectIdMapping> &data) +void QQmlContextData::setIdPropertyData(const QHash<int, int> &data) { - Q_ASSERT(idObjectNames.isEmpty()); - idObjectNames = data; + Q_ASSERT(objectIndexToId.isEmpty()); + objectIndexToId = data; Q_ASSERT(propertyNameCache.isEmpty()); idValueCount = data.count(); idValues = new ContextGuard[idValueCount]; @@ -808,10 +808,13 @@ QV4::IdentifierHash<int> &QQmlContextData::propertyNames() const { if (propertyNameCache.isEmpty()) { propertyNameCache = QV4::IdentifierHash<int>(QV8Engine::getV4(engine->handle())); - for (QVector<ObjectIdMapping>::ConstIterator it = idObjectNames.begin(), end = idObjectNames.end(); - it != end; ++it) - propertyNameCache.add(it->name, it->id); - idObjectNames.clear(); + for (QHash<int, int>::ConstIterator it = objectIndexToId.begin(), end = objectIndexToId.end(); + it != end; ++it) { + const QV4::CompiledData::Object *obj = typeCompilationUnit->data->objectAt(it.key()); + const QString name = typeCompilationUnit->data->stringAt(obj->idIndex); + propertyNameCache.add(name, it.value()); + } + objectIndexToId.clear(); } return propertyNameCache; } diff --git a/src/qml/qml/qqmlcontext_p.h b/src/qml/qml/qqmlcontext_p.h index 40bd310cb7..f5fd7d0a5c 100644 --- a/src/qml/qml/qqmlcontext_p.h +++ b/src/qml/qml/qqmlcontext_p.h @@ -144,15 +144,7 @@ public: // Compilation unit for contexts that belong to a compiled type. QQmlRefPointer<QV4::CompiledData::CompilationUnit> typeCompilationUnit; - struct ObjectIdMapping { - ObjectIdMapping() : id(-1) {} - ObjectIdMapping(const QString &name, int id) - : name(name), id(id) {} - QString name; - int id; - }; - - mutable QVector<ObjectIdMapping> idObjectNames; + mutable QHash<int, int> objectIndexToId; mutable QV4::IdentifierHash<int> propertyNameCache; QV4::IdentifierHash<int> &propertyNames() const; @@ -202,7 +194,7 @@ public: ContextGuard *idValues; int idValueCount; void setIdProperty(int, QObject *); - void setIdPropertyData(const QVector<ObjectIdMapping> &); + void setIdPropertyData(const QHash<int, int> &); // Linked contexts. this owns linkedContext. QQmlContextData *linkedContext; diff --git a/src/qml/qml/qqmlobjectcreator.cpp b/src/qml/qml/qqmlobjectcreator.cpp index e7a08773f4..4c86e6a307 100644 --- a/src/qml/qml/qqmlobjectcreator.cpp +++ b/src/qml/qml/qqmlobjectcreator.cpp @@ -192,17 +192,7 @@ QObject *QQmlObjectCreator::create(int subComponentIndex, QObject *parent, QQmlI if (topLevelCreator) sharedState->allJavaScriptObjects = scope.alloc(compiledData->totalObjectCount); - QVector<QQmlContextData::ObjectIdMapping> mapping(objectIndexToId.count()); - for (QHash<int, int>::ConstIterator it = objectIndexToId.constBegin(), end = objectIndexToId.constEnd(); - it != end; ++it) { - const QV4::CompiledData::Object *obj = qmlUnit->objectAt(it.key()); - - QQmlContextData::ObjectIdMapping m; - m.id = it.value(); - m.name = stringAt(obj->idIndex); - mapping[m.id] = m; - } - context->setIdPropertyData(mapping); + context->setIdPropertyData(objectIndexToId); if (subComponentIndex == -1 && compiledData->scripts.count()) { QV4::ScopedObject scripts(scope, v4->newArrayObject(compiledData->scripts.count())); |