From 2024df6604dbb78f5eee6f61e73fb0d2fc3bb008 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Thu, 4 Jul 2019 14:07:16 +0200 Subject: Streamline Var property handling in QQmlVMEMetaObject::metaCall Fold the Var handling into the general type switch. That allows decreasing the level of indentation for a large chunk of code in the function. Change-Id: I04d4efd310b798b28e7946924accdaf2e775c5aa Reviewed-by: Ulf Hermann --- src/qml/qml/qqmlvmemetaobject.cpp | 311 +++++++++++++++++++------------------- 1 file changed, 153 insertions(+), 158 deletions(-) (limited to 'src/qml/qml/qqmlvmemetaobject.cpp') diff --git a/src/qml/qml/qqmlvmemetaobject.cpp b/src/qml/qml/qqmlvmemetaobject.cpp index 4505de1ce7..e26dc4d9aa 100644 --- a/src/qml/qml/qqmlvmemetaobject.cpp +++ b/src/qml/qml/qqmlvmemetaobject.cpp @@ -641,172 +641,167 @@ int QQmlVMEMetaObject::metaCall(QObject *o, QMetaObject::Call c, int _id, void * if (id < propertyCount) { const QV4::CompiledData::Property::Type t = static_cast(qint32(compiledObject->propertyTable()[id].type)); - if (t == QV4::CompiledData::Property::Var) { - // the context can be null if accessing var properties from cpp after re-parenting an item. - QQmlEnginePrivate *ep = (ctxt == nullptr || ctxt->engine == nullptr) ? nullptr : QQmlEnginePrivate::get(ctxt->engine); - if (ep) { - if (c == QMetaObject::ReadProperty) { + // the context can be null if accessing var properties from cpp after re-parenting an item. + QQmlEnginePrivate *ep = (ctxt == nullptr || ctxt->engine == nullptr) ? nullptr : QQmlEnginePrivate::get(ctxt->engine); + + const int fallbackMetaType = QQmlPropertyCacheCreatorBase::metaTypeForPropertyType(t); + + if (c == QMetaObject::ReadProperty) { + switch (t) { + case QV4::CompiledData::Property::Int: + *reinterpret_cast(a[0]) = readPropertyAsInt(id); + break; + case QV4::CompiledData::Property::Bool: + *reinterpret_cast(a[0]) = readPropertyAsBool(id); + break; + case QV4::CompiledData::Property::Real: + *reinterpret_cast(a[0]) = readPropertyAsDouble(id); + break; + case QV4::CompiledData::Property::String: + *reinterpret_cast(a[0]) = readPropertyAsString(id); + break; + case QV4::CompiledData::Property::Url: + *reinterpret_cast(a[0]) = readPropertyAsUrl(id); + break; + case QV4::CompiledData::Property::Date: + *reinterpret_cast(a[0]) = readPropertyAsDate(id); + break; + case QV4::CompiledData::Property::DateTime: + *reinterpret_cast(a[0]) = readPropertyAsDateTime(id); + break; + case QV4::CompiledData::Property::Rect: + *reinterpret_cast(a[0]) = readPropertyAsRectF(id); + break; + case QV4::CompiledData::Property::Size: + *reinterpret_cast(a[0]) = readPropertyAsSizeF(id); + break; + case QV4::CompiledData::Property::Point: + *reinterpret_cast(a[0]) = readPropertyAsPointF(id); + break; + case QV4::CompiledData::Property::Custom: + *reinterpret_cast(a[0]) = readPropertyAsQObject(id); + break; + case QV4::CompiledData::Property::Variant: + *reinterpret_cast(a[0]) = readPropertyAsVariant(id); + break; + case QV4::CompiledData::Property::CustomList: { + QList *list = readPropertyAsList(id); + QQmlListProperty *p = static_cast *>(a[0]); + *p = QQmlListProperty(object, list, + list_append, list_count, list_at, + list_clear); + p->dummy1 = this; + p->dummy2 = reinterpret_cast(quintptr(methodOffset() + id)); + break; + } + case QV4::CompiledData::Property::Font: + case QV4::CompiledData::Property::Time: + case QV4::CompiledData::Property::Color: + case QV4::CompiledData::Property::Vector2D: + case QV4::CompiledData::Property::Vector3D: + case QV4::CompiledData::Property::Vector4D: + case QV4::CompiledData::Property::Matrix4x4: + case QV4::CompiledData::Property::Quaternion: + Q_ASSERT(fallbackMetaType != QMetaType::UnknownType); + if (QV4::MemberData *md = propertyAndMethodStorageAsMemberData()) { + QVariant propertyAsVariant; + if (const QV4::VariantObject *v = (md->data() + id)->as()) + propertyAsVariant = v->d()->data(); + QQml_valueTypeProvider()->readValueType(propertyAsVariant, a[0], fallbackMetaType); + } + break; + case QV4::CompiledData::Property::Var: + if (ep) { *reinterpret_cast(a[0]) = readPropertyAsVariant(id); - } else if (c == QMetaObject::WriteProperty) { - writeProperty(id, *reinterpret_cast(a[0])); + } else { + // if the context was disposed, we just return an invalid variant from read. + *reinterpret_cast(a[0]) = QVariant(); } - } else if (c == QMetaObject::ReadProperty) { - // if the context was disposed, we just return an invalid variant from read. - *reinterpret_cast(a[0]) = QVariant(); + break; } - } else { - const int fallbackMetaType = QQmlPropertyCacheCreatorBase::metaTypeForPropertyType(t); - - if (c == QMetaObject::ReadProperty) { - switch (t) { - case QV4::CompiledData::Property::Int: - *reinterpret_cast(a[0]) = readPropertyAsInt(id); - break; - case QV4::CompiledData::Property::Bool: - *reinterpret_cast(a[0]) = readPropertyAsBool(id); - break; - case QV4::CompiledData::Property::Real: - *reinterpret_cast(a[0]) = readPropertyAsDouble(id); - break; - case QV4::CompiledData::Property::String: - *reinterpret_cast(a[0]) = readPropertyAsString(id); - break; - case QV4::CompiledData::Property::Url: - *reinterpret_cast(a[0]) = readPropertyAsUrl(id); - break; - case QV4::CompiledData::Property::Date: - *reinterpret_cast(a[0]) = readPropertyAsDate(id); - break; - case QV4::CompiledData::Property::DateTime: - *reinterpret_cast(a[0]) = readPropertyAsDateTime(id); - break; - case QV4::CompiledData::Property::Rect: - *reinterpret_cast(a[0]) = readPropertyAsRectF(id); - break; - case QV4::CompiledData::Property::Size: - *reinterpret_cast(a[0]) = readPropertyAsSizeF(id); - break; - case QV4::CompiledData::Property::Point: - *reinterpret_cast(a[0]) = readPropertyAsPointF(id); - break; - case QV4::CompiledData::Property::Custom: - *reinterpret_cast(a[0]) = readPropertyAsQObject(id); - break; - case QV4::CompiledData::Property::Variant: - *reinterpret_cast(a[0]) = readPropertyAsVariant(id); - break; - case QV4::CompiledData::Property::CustomList: { - QList *list = readPropertyAsList(id); - QQmlListProperty *p = static_cast *>(a[0]); - *p = QQmlListProperty(object, list, - list_append, list_count, list_at, - list_clear); - p->dummy1 = this; - p->dummy2 = reinterpret_cast(quintptr(methodOffset() + id)); - break; - } - case QV4::CompiledData::Property::Font: - case QV4::CompiledData::Property::Time: - case QV4::CompiledData::Property::Color: - case QV4::CompiledData::Property::Vector2D: - case QV4::CompiledData::Property::Vector3D: - case QV4::CompiledData::Property::Vector4D: - case QV4::CompiledData::Property::Matrix4x4: - case QV4::CompiledData::Property::Quaternion: - Q_ASSERT(fallbackMetaType != QMetaType::UnknownType); - if (QV4::MemberData *md = propertyAndMethodStorageAsMemberData()) { - QVariant propertyAsVariant; - if (const QV4::VariantObject *v = (md->data() + id)->as()) - propertyAsVariant = v->d()->data(); - QQml_valueTypeProvider()->readValueType(propertyAsVariant, a[0], fallbackMetaType); + } else if (c == QMetaObject::WriteProperty) { + bool needActivate = false; + switch (t) { + case QV4::CompiledData::Property::Int: + needActivate = *reinterpret_cast(a[0]) != readPropertyAsInt(id); + writeProperty(id, *reinterpret_cast(a[0])); + break; + case QV4::CompiledData::Property::Bool: + needActivate = *reinterpret_cast(a[0]) != readPropertyAsBool(id); + writeProperty(id, *reinterpret_cast(a[0])); + break; + case QV4::CompiledData::Property::Real: + needActivate = *reinterpret_cast(a[0]) != readPropertyAsDouble(id); + writeProperty(id, *reinterpret_cast(a[0])); + break; + case QV4::CompiledData::Property::String: + needActivate = *reinterpret_cast(a[0]) != readPropertyAsString(id); + writeProperty(id, *reinterpret_cast(a[0])); + break; + case QV4::CompiledData::Property::Url: + needActivate = *reinterpret_cast(a[0]) != readPropertyAsUrl(id); + writeProperty(id, *reinterpret_cast(a[0])); + break; + case QV4::CompiledData::Property::Date: + needActivate = *reinterpret_cast(a[0]) != readPropertyAsDate(id); + writeProperty(id, *reinterpret_cast(a[0])); + break; + case QV4::CompiledData::Property::DateTime: + needActivate = *reinterpret_cast(a[0]) != readPropertyAsDateTime(id); + writeProperty(id, *reinterpret_cast(a[0])); + break; + case QV4::CompiledData::Property::Rect: + needActivate = *reinterpret_cast(a[0]) != readPropertyAsRectF(id); + writeProperty(id, *reinterpret_cast(a[0])); + break; + case QV4::CompiledData::Property::Size: + needActivate = *reinterpret_cast(a[0]) != readPropertyAsSizeF(id); + writeProperty(id, *reinterpret_cast(a[0])); + break; + case QV4::CompiledData::Property::Point: + needActivate = *reinterpret_cast(a[0]) != readPropertyAsPointF(id); + writeProperty(id, *reinterpret_cast(a[0])); + break; + case QV4::CompiledData::Property::Custom: + needActivate = *reinterpret_cast(a[0]) != readPropertyAsQObject(id); + writeProperty(id, *reinterpret_cast(a[0])); + break; + case QV4::CompiledData::Property::Variant: + writeProperty(id, *reinterpret_cast(a[0])); + break; + case QV4::CompiledData::Property::CustomList: + // Writing such a property is not supported. Content is added through the list property + // methods. + break; + case QV4::CompiledData::Property::Font: + case QV4::CompiledData::Property::Time: + case QV4::CompiledData::Property::Color: + case QV4::CompiledData::Property::Vector2D: + case QV4::CompiledData::Property::Vector3D: + case QV4::CompiledData::Property::Vector4D: + case QV4::CompiledData::Property::Matrix4x4: + case QV4::CompiledData::Property::Quaternion: + Q_ASSERT(fallbackMetaType != QMetaType::UnknownType); + if (QV4::MemberData *md = propertyAndMethodStorageAsMemberData()) { + const QV4::VariantObject *v = (md->data() + id)->as(); + if (!v) { + md->set(engine, id, engine->newVariantObject(QVariant())); + v = (md->data() + id)->as(); + QQml_valueTypeProvider()->initValueType(fallbackMetaType, v->d()->data()); } - break; - case QV4::CompiledData::Property::Var: - Q_UNREACHABLE(); + needActivate = !QQml_valueTypeProvider()->equalValueType(fallbackMetaType, a[0], v->d()->data()); + QQml_valueTypeProvider()->writeValueType(fallbackMetaType, a[0], v->d()->data()); } - - } else if (c == QMetaObject::WriteProperty) { - bool needActivate = false; - switch(t) { - case QV4::CompiledData::Property::Int: - needActivate = *reinterpret_cast(a[0]) != readPropertyAsInt(id); - writeProperty(id, *reinterpret_cast(a[0])); - break; - case QV4::CompiledData::Property::Bool: - needActivate = *reinterpret_cast(a[0]) != readPropertyAsBool(id); - writeProperty(id, *reinterpret_cast(a[0])); - break; - case QV4::CompiledData::Property::Real: - needActivate = *reinterpret_cast(a[0]) != readPropertyAsDouble(id); - writeProperty(id, *reinterpret_cast(a[0])); - break; - case QV4::CompiledData::Property::String: - needActivate = *reinterpret_cast(a[0]) != readPropertyAsString(id); - writeProperty(id, *reinterpret_cast(a[0])); - break; - case QV4::CompiledData::Property::Url: - needActivate = *reinterpret_cast(a[0]) != readPropertyAsUrl(id); - writeProperty(id, *reinterpret_cast(a[0])); - break; - case QV4::CompiledData::Property::Date: - needActivate = *reinterpret_cast(a[0]) != readPropertyAsDate(id); - writeProperty(id, *reinterpret_cast(a[0])); - break; - case QV4::CompiledData::Property::DateTime: - needActivate = *reinterpret_cast(a[0]) != readPropertyAsDateTime(id); - writeProperty(id, *reinterpret_cast(a[0])); - break; - case QV4::CompiledData::Property::Rect: - needActivate = *reinterpret_cast(a[0]) != readPropertyAsRectF(id); - writeProperty(id, *reinterpret_cast(a[0])); - break; - case QV4::CompiledData::Property::Size: - needActivate = *reinterpret_cast(a[0]) != readPropertyAsSizeF(id); - writeProperty(id, *reinterpret_cast(a[0])); - break; - case QV4::CompiledData::Property::Point: - needActivate = *reinterpret_cast(a[0]) != readPropertyAsPointF(id); - writeProperty(id, *reinterpret_cast(a[0])); - break; - case QV4::CompiledData::Property::Custom: - needActivate = *reinterpret_cast(a[0]) != readPropertyAsQObject(id); - writeProperty(id, *reinterpret_cast(a[0])); - break; - case QV4::CompiledData::Property::Variant: + break; + case QV4::CompiledData::Property::Var: + if (ep) writeProperty(id, *reinterpret_cast(a[0])); - break; - case QV4::CompiledData::Property::CustomList: - // Writing such a property is not supported. Content is added through the list property - // methods. - break; - case QV4::CompiledData::Property::Font: - case QV4::CompiledData::Property::Time: - case QV4::CompiledData::Property::Color: - case QV4::CompiledData::Property::Vector2D: - case QV4::CompiledData::Property::Vector3D: - case QV4::CompiledData::Property::Vector4D: - case QV4::CompiledData::Property::Matrix4x4: - case QV4::CompiledData::Property::Quaternion: - Q_ASSERT(fallbackMetaType != QMetaType::UnknownType); - if (QV4::MemberData *md = propertyAndMethodStorageAsMemberData()) { - const QV4::VariantObject *v = (md->data() + id)->as(); - if (!v) { - md->set(engine, id, engine->newVariantObject(QVariant())); - v = (md->data() + id)->as(); - QQml_valueTypeProvider()->initValueType(fallbackMetaType, v->d()->data()); - } - needActivate = !QQml_valueTypeProvider()->equalValueType(fallbackMetaType, a[0], v->d()->data()); - QQml_valueTypeProvider()->writeValueType(fallbackMetaType, a[0], v->d()->data()); - } - break; - case QV4::CompiledData::Property::Var: - Q_UNREACHABLE(); - } - - if (needActivate) - activate(object, methodOffset() + id, nullptr); + break; } + + if (needActivate) + activate(object, methodOffset() + id, nullptr); } return -1; -- cgit v1.2.3