diff options
author | Simon Hausmann <simon.hausmann@digia.com> | 2013-07-01 08:20:15 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-07-02 15:36:54 +0200 |
commit | d7134b8b68f0b3530269f7d087bdecfc8986be6b (patch) | |
tree | 09a36f3a3cfc24b1d4e85b11090b78cb07f3e17c /src/qml/qml | |
parent | 35deea613e96f9fced4fc48b1c5e59a4f7ee8e38 (diff) |
Replace us of v4 identifiers for object id mapping in qml compiler
The compiler is executed in a separate thread, at which point it doesn't work
very well to access the identifiers data structures of the engine on the main
thread, allocate new strings and potentially also trigger GC.
This patch moves the data into an intermediate QVector and constructs the
identifier hash on the receiving end in QQmlContextData::setIdPropertyData.
Change-Id: I676cf633cf1c55ee2e8f818e6963368ad55913cd
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src/qml/qml')
-rw-r--r-- | src/qml/qml/qqmlcompiler.cpp | 8 | ||||
-rw-r--r-- | src/qml/qml/qqmlcompiler_p.h | 2 | ||||
-rw-r--r-- | src/qml/qml/qqmlcontext.cpp | 7 | ||||
-rw-r--r-- | src/qml/qml/qqmlcontext_p.h | 9 |
4 files changed, 18 insertions, 8 deletions
diff --git a/src/qml/qml/qqmlcompiler.cpp b/src/qml/qml/qqmlcompiler.cpp index 386255a89b..ee0d37b6d8 100644 --- a/src/qml/qml/qqmlcompiler.cpp +++ b/src/qml/qml/qqmlcompiler.cpp @@ -3554,10 +3554,10 @@ int QQmlCompiler::genContextCache() if (compileState->ids.count() == 0) return -1; - QV4::IdentifierHash<int> cache(QV8Engine::getV4(engine->handle())); - cache.reserve(compileState->ids.count()); - for (Object *o = compileState->ids.first(); o; o = compileState->ids.next(o)) - cache.add(o->id, o->idIndex); + QVector<QQmlContextData::ObjectIdMapping> cache(compileState->ids.count()); + int i = 0; + for (Object *o = compileState->ids.first(); o; o = compileState->ids.next(o), ++i) + cache[i] = QQmlContextData::ObjectIdMapping(o->id, o->idIndex); output->contextCaches.append(cache); return output->contextCaches.count() - 1; diff --git a/src/qml/qml/qqmlcompiler_p.h b/src/qml/qml/qqmlcompiler_p.h index 6158ec3f6d..6a008a436c 100644 --- a/src/qml/qml/qqmlcompiler_p.h +++ b/src/qml/qml/qqmlcompiler_p.h @@ -121,7 +121,7 @@ public: QList<QByteArray> datas; QByteArray bytecode; QList<QQmlPropertyCache *> propertyCaches; - QList<QV4::IdentifierHash<int> > contextCaches; + QList<QVector<QQmlContextData::ObjectIdMapping> > contextCaches; QList<QQmlScriptData *> scripts; QList<QUrl> urls; diff --git a/src/qml/qml/qqmlcontext.cpp b/src/qml/qml/qqmlcontext.cpp index 55cfbc0654..7731935b75 100644 --- a/src/qml/qml/qqmlcontext.cpp +++ b/src/qml/qml/qqmlcontext.cpp @@ -770,10 +770,13 @@ void QQmlContextData::setIdProperty(int idx, QObject *obj) idValues[idx].context = this; } -void QQmlContextData::setIdPropertyData(const QV4::IdentifierHash<int> &data) +void QQmlContextData::setIdPropertyData(const QVector<ObjectIdMapping> &data) { Q_ASSERT(propertyNames.isEmpty()); - propertyNames = data; + propertyNames = QV4::IdentifierHash<int>(QV8Engine::getV4(engine->handle())); + for (QVector<ObjectIdMapping>::ConstIterator it = data.begin(), end = data.end(); + it != end; ++it) + propertyNames.add(it->name, it->id); idValueCount = data.count(); idValues = new ContextGuard[idValueCount]; diff --git a/src/qml/qml/qqmlcontext_p.h b/src/qml/qml/qqmlcontext_p.h index 3d31e47707..a5c3886af1 100644 --- a/src/qml/qml/qqmlcontext_p.h +++ b/src/qml/qml/qqmlcontext_p.h @@ -195,10 +195,17 @@ public: QFlagPointer<QQmlContextData> context; QQmlNotifier bindings; }; + struct ObjectIdMapping { + ObjectIdMapping() : id(-1) {} + ObjectIdMapping(const QString &name, int id) + : name(name), id(id) {} + QString name; + int id; + }; ContextGuard *idValues; int idValueCount; void setIdProperty(int, QObject *); - void setIdPropertyData(const QV4::IdentifierHash<int> &); + void setIdPropertyData(const QVector<ObjectIdMapping> &); // Linked contexts. this owns linkedContext. QQmlContextData *linkedContext; |