aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml/qqmlvaluetypewrapper_p.h
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2022-09-27 10:21:55 +0200
committerUlf Hermann <ulf.hermann@qt.io>2022-10-13 00:18:35 +0200
commite1a0596924766d62459740ed0271114a7bb99851 (patch)
tree5ac17c73668016ca0c3870fa799c3497537cf671 /src/qml/qml/qqmlvaluetypewrapper_p.h
parent1a0c4094e0fce8693a4653a9b3cb80f832865495 (diff)
V4: Refactor QQmlValueType{Wrapper|Reference} and QV4::Sequence
Every QQmlValueTypeWrapper is potentially a reference now. Since most were already before, the overhead of checking the vtables at every step was dubious at best. Extract a common base class that handles the reading and writing of object properties employed in both value type references and sequences. Task-number: QTBUG-99766 Change-Id: Idf72d9a20a52366e5c2d0dcd4b3a18072c0ccc41 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qml/qml/qqmlvaluetypewrapper_p.h')
-rw-r--r--src/qml/qml/qqmlvaluetypewrapper_p.h63
1 files changed, 16 insertions, 47 deletions
diff --git a/src/qml/qml/qqmlvaluetypewrapper_p.h b/src/qml/qml/qqmlvaluetypewrapper_p.h
index 9d96d68c50..c57e385a00 100644
--- a/src/qml/qml/qqmlvaluetypewrapper_p.h
+++ b/src/qml/qml/qqmlvaluetypewrapper_p.h
@@ -20,6 +20,7 @@
#include <private/qv4value_p.h>
#include <private/qv4object_p.h>
+#include <private/qv4referenceobject_p.h>
#include <private/qqmlpropertycache_p.h>
QT_BEGIN_NAMESPACE
@@ -30,8 +31,11 @@ namespace QV4 {
namespace Heap {
-struct QQmlValueTypeWrapper : Object {
- void init() { Object::init(); }
+#define QQmlValueTypeWrapperMembers(class, Member)
+
+DECLARE_HEAP_OBJECT(QQmlValueTypeWrapper, ReferenceObject) {
+ DECLARE_MARKOBJECTS(QQmlValueTypeWrapper);
+
void destroy();
void setValueType(QQmlValueType *valueType)
@@ -69,56 +73,30 @@ struct QQmlValueTypeWrapper : Object {
void setValue(const QVariant &value) const;
QVariant toVariant() const;
+ void *storagePointer();
+ bool setVariant(const QVariant &variant);
+
+ bool readReference();
+ bool writeBack();
+
private:
mutable void *m_gadgetPtr;
QQmlValueType *m_valueType;
const QMetaObject *m_metaObject;
};
-struct QQmlValueTypeReference : QQmlValueTypeWrapper
-{
- void init() {
- QQmlValueTypeWrapper::init();
- object.init();
- }
- void destroy() {
- object.destroy();
- QQmlValueTypeWrapper::destroy();
- }
-
- void writeBack() {
- const QMetaProperty writebackProperty = object->metaObject()->property(property);
- if (!writebackProperty.isWritable())
- return;
-
- int flags = 0;
- int status = -1;
- if (writebackProperty.metaType() == QMetaType::fromType<QVariant>()) {
- QVariant variantReferenceValue = toVariant();
- void *a[] = { &variantReferenceValue, nullptr, &status, &flags };
- QMetaObject::metacall(object, QMetaObject::WriteProperty, property, a);
- } else {
- void *a[] = { gadgetPtr(), nullptr, &status, &flags };
- QMetaObject::metacall(object, QMetaObject::WriteProperty, property, a);
- }
- }
-
- QV4QPointer<QObject> object;
- int property;
-};
-
}
-struct Q_QML_EXPORT QQmlValueTypeWrapper : Object
+struct Q_QML_EXPORT QQmlValueTypeWrapper : public ReferenceObject
{
- V4_OBJECT2(QQmlValueTypeWrapper, Object)
+ V4_OBJECT2(QQmlValueTypeWrapper, ReferenceObject)
V4_PROTOTYPE(valueTypeWrapperPrototype)
V4_NEEDS_DESTROY
public:
static ReturnedValue create(ExecutionEngine *engine, QObject *, int, const QMetaObject *metaObject, QMetaType type);
- static ReturnedValue create(ExecutionEngine *engine, const QVariant &, const QMetaObject *metaObject, QMetaType type);
+ static ReturnedValue create(ExecutionEngine *engine, Heap::QQmlValueTypeWrapper *cloneFrom, QObject *object);
static ReturnedValue create(ExecutionEngine *engine, const void *, const QMetaObject *metaObject, QMetaType type);
QVariant toVariant() const;
@@ -127,6 +105,7 @@ public:
int typeId() const;
QMetaType type() const;
bool write(QObject *target, int propertyIndex) const;
+ bool readReferenceValue() const { return d()->readReference(); }
QQmlPropertyData dataForPropertyKey(PropertyKey id) const;
@@ -146,16 +125,6 @@ public:
static void initProto(ExecutionEngine *v4);
};
-struct QQmlValueTypeReference : public QQmlValueTypeWrapper
-{
- V4_OBJECT2(QQmlValueTypeReference, QQmlValueTypeWrapper)
- V4_NEEDS_DESTROY
-
- static ReturnedValue create(ExecutionEngine *engine, Heap::QQmlValueTypeReference *cloneFrom, QObject *object);
-
- bool readReferenceValue() const;
-};
-
}
QT_END_NAMESPACE