diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2021-03-24 15:36:37 +0100 |
---|---|---|
committer | Fabian Kosmale <fabian.kosmale@qt.io> | 2021-03-25 21:25:28 +0100 |
commit | d009c0088bac6da4d775345a60e33fee22af22ce (patch) | |
tree | ce420925f16f6fea77f9b6ee5e47e81b86011e4c /src/qml/qml | |
parent | 3ce1ee554b7c9cb9200a88071cb2d9e45dda90c0 (diff) |
QV4::Engine::toVariant: Use metatype instead of metatype id
This way, we can avoid the costly id to metatype lookup in case where we
actually need the full metatype.
Task-number: QTBUG-88766
Change-Id: Ibe29b323007f00d2f8d1807fb9b64f9a8f87e807
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Diffstat (limited to 'src/qml/qml')
-rw-r--r-- | src/qml/qml/qqmlbinding.cpp | 17 | ||||
-rw-r--r-- | src/qml/qml/qqmlexpression.cpp | 2 | ||||
-rw-r--r-- | src/qml/qml/qqmlpropertybinding.cpp | 2 | ||||
-rw-r--r-- | src/qml/qml/qqmlvaluetypewrapper.cpp | 2 | ||||
-rw-r--r-- | src/qml/qml/qqmlvmemetaobject.cpp | 2 |
5 files changed, 13 insertions, 12 deletions
diff --git a/src/qml/qml/qqmlbinding.cpp b/src/qml/qml/qqmlbinding.cpp index b54ac38b64..b21468951d 100644 --- a/src/qml/qml/qqmlbinding.cpp +++ b/src/qml/qml/qqmlbinding.cpp @@ -413,7 +413,8 @@ Q_NEVER_INLINE bool QQmlBinding::slowWrite(const QQmlPropertyData &core, QQmlEngine *qmlEngine = engine(); QV4::ExecutionEngine *v4engine = qmlEngine->handle(); - const int type = valueTypeData.isValid() ? valueTypeData.propType().id() : core.propType().id(); + const QMetaType metaType = valueTypeData.isValid() ? valueTypeData.propType() : core.propType(); + const int type = metaType.id(); QQmlJavaScriptExpression::DeleteWatcher watcher(this); @@ -422,13 +423,13 @@ Q_NEVER_INLINE bool QQmlBinding::slowWrite(const QQmlPropertyData &core, if (isUndefined) { } else if (core.isQList()) { - value = v4engine->toVariant(result, qMetaTypeId<QList<QObject *> >()); + value = v4engine->toVariant(result, QMetaType::fromType<QList<QObject *> >()); } else if (result.isNull() && core.isQObject()) { value = QVariant::fromValue((QObject *)nullptr); } else if (core.propType().id() == qMetaTypeId<QList<QUrl> >()) { - value = QQmlPropertyPrivate::urlSequence(v4engine->toVariant(result, qMetaTypeId<QList<QUrl>>())); - } else if (!isVarProperty && type != qMetaTypeId<QJSValue>()) { - value = v4engine->toVariant(result, type); + value = QQmlPropertyPrivate::urlSequence(v4engine->toVariant(result, QMetaType::fromType<QList<QUrl>>())); + } else if (!isVarProperty && metaType != QMetaType::fromType<QJSValue>()) { + value = v4engine->toVariant(result, metaType); } if (hasError()) { @@ -448,9 +449,9 @@ Q_NEVER_INLINE bool QQmlBinding::slowWrite(const QQmlPropertyData &core, } else if (isUndefined && core.isResettable()) { void *args[] = { nullptr }; QMetaObject::metacall(m_target.data(), QMetaObject::ResetProperty, core.coreIndex(), args); - } else if (isUndefined && type == qMetaTypeId<QVariant>()) { + } else if (isUndefined && type == QMetaType::QVariant) { QQmlPropertyPrivate::writeValueProperty(m_target.data(), core, valueTypeData, QVariant(), context(), flags); - } else if (type == qMetaTypeId<QJSValue>()) { + } else if (metaType == QMetaType::fromType<QJSValue>()) { const QV4::FunctionObject *f = result.as<QV4::FunctionObject>(); if (f && f->isBinding()) { delayedError()->setErrorDescription(QLatin1String("Invalid use of Qt.binding() in a binding declaration.")); @@ -526,7 +527,7 @@ QVariant QQmlBinding::evaluate() ep->dereferenceScarceResources(); - return scope.engine->toVariant(result, qMetaTypeId<QList<QObject*> >()); + return scope.engine->toVariant(result, QMetaType::fromType<QList<QObject*> >()); } void QQmlBinding::expressionChanged() diff --git a/src/qml/qml/qqmlexpression.cpp b/src/qml/qml/qqmlexpression.cpp index 5864c3245c..cb9096ae66 100644 --- a/src/qml/qml/qqmlexpression.cpp +++ b/src/qml/qml/qqmlexpression.cpp @@ -281,7 +281,7 @@ QVariant QQmlExpressionPrivate::value(bool *isUndefined) QV4::Scope scope(engine->handle()); QV4::ScopedValue result(scope, v4value(isUndefined)); if (!hasError()) - rv = scope.engine->toVariant(result, -1); + rv = scope.engine->toVariant(result, QMetaType {}); } ep->dereferenceScarceResources(); // "release" scarce resources if top-level expression evaluation is complete. diff --git a/src/qml/qml/qqmlpropertybinding.cpp b/src/qml/qml/qqmlpropertybinding.cpp index 987ca7f13c..24ee2441ce 100644 --- a/src/qml/qml/qqmlpropertybinding.cpp +++ b/src/qml/qml/qqmlpropertybinding.cpp @@ -284,7 +284,7 @@ bool QQmlPropertyBinding::evaluate(QMetaType metaType, void *dataPtr) break; } - QVariant resultVariant(scope.engine->toVariant(result, metaType.id())); + QVariant resultVariant(scope.engine->toVariant(result, metaType)); resultVariant.convert(metaType); const bool hasChanged = !metaType.equals(resultVariant.constData(), dataPtr); metaType.destruct(dataPtr); diff --git a/src/qml/qml/qqmlvaluetypewrapper.cpp b/src/qml/qml/qqmlvaluetypewrapper.cpp index c78686558b..9b2dda23e9 100644 --- a/src/qml/qml/qqmlvaluetypewrapper.cpp +++ b/src/qml/qml/qqmlvaluetypewrapper.cpp @@ -679,7 +679,7 @@ bool QQmlValueTypeWrapper::virtualPut(Managed *m, PropertyKey id, const Value &v QMetaProperty property = metaObject->property(pd.coreIndex()); Q_ASSERT(property.isValid()); - QVariant v = v4->toVariant(value, property.userType()); + QVariant v = v4->toVariant(value, property.metaType()); if (property.isEnumType() && (QMetaType::Type)v.userType() == QMetaType::Double) v = v.toInt(); diff --git a/src/qml/qml/qqmlvmemetaobject.cpp b/src/qml/qml/qqmlvmemetaobject.cpp index df3f2fd428..7580d45104 100644 --- a/src/qml/qml/qqmlvmemetaobject.cpp +++ b/src/qml/qml/qqmlvmemetaobject.cpp @@ -1062,7 +1062,7 @@ QVariant QQmlVMEMetaObject::readPropertyAsVariant(int id) const const QV4::VariantObject *v = (md->data() + id)->as<QV4::VariantObject>(); if (v) return v->d()->data(); - return engine->toVariant(*(md->data() + id), -1); + return engine->toVariant(*(md->data() + id), QMetaType {}); } return QVariant(); } |