aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@theqtcompany.com>2015-04-10 15:17:51 +0200
committerSimon Hausmann <simon.hausmann@theqtcompany.com>2015-04-16 17:14:25 +0000
commit33aa21ab0430ae71f5ee44459e250091c09d56b1 (patch)
tree944b25bfb0b9eb76c549bd054584f03be706dddc
parent61f218b4e772c1d97e32ef8031de0043473ebbef (diff)
Speed up composite type instantiation with lots of IDs
We don't need to convert from a QHash to a QVector in order to populate the property name cache in QQmlContextData. Change-Id: Ifa8e4f64a1e174907e92684b2d38abaf0a4a705c Reviewed-by: Lars Knoll <lars.knoll@digia.com>
-rw-r--r--src/qml/qml/qqmlcontext.cpp17
-rw-r--r--src/qml/qml/qqmlcontext_p.h12
-rw-r--r--src/qml/qml/qqmlobjectcreator.cpp12
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()));