From: Frank Meerkoetter Date: Thu, 16 Jul 2015 20:04:39 +0000 (+0200) Subject: Port QUrl/QSizeF away from QQmlVmeVariant X-Git-Tag: v5.5.90+alpha1~59 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0cbab3b17fb70208476b910d7d82ae653a9a1050;p=platform%2Fupstream%2Fqtdeclarative.git Port QUrl/QSizeF away from QQmlVmeVariant Store QUrl/QSizeF in a javascript array. The values are wrapped inside a QV4::Variant. This is part of a series sliming down the memory usage of properties. Change-Id: I62338fe7fe101496340a8d89f33030d0df5121b7 Reviewed-by: Simon Hausmann --- diff --git a/src/qml/qml/qqmlvmemetaobject.cpp b/src/qml/qml/qqmlvmemetaobject.cpp index a359cb72b..60f56dff5 100644 --- a/src/qml/qml/qqmlvmemetaobject.cpp +++ b/src/qml/qml/qqmlvmemetaobject.cpp @@ -624,6 +624,28 @@ void QQmlVMEMetaObject::writeProperty(int id, const QString& v) vp->putIndexed(id, s); } +void QQmlVMEMetaObject::writeProperty(int id, const QUrl& v) +{ + if (!ensurePropertiesAllocated()) + return; + + QV4::Scope scope(properties.engine()); + QV4::ScopedObject vp(scope, properties.value()); + QV4::ScopedValue sv(scope, properties.engine()->newVariantObject(QVariant::fromValue(v))); + vp->putIndexed(id, sv); +} + +void QQmlVMEMetaObject::writeProperty(int id, const QPointF& v) +{ + if (!ensurePropertiesAllocated()) + return; + + QV4::Scope scope(properties.engine()); + QV4::ScopedObject vp(scope, properties.value()); + QV4::ScopedValue sv(scope, properties.engine()->newVariantObject(QVariant::fromValue(v))); + vp->putIndexed(id, sv); +} + void QQmlVMEMetaObject::writeProperty(int id, const QSizeF& v) { if (!ensurePropertiesAllocated()) @@ -695,6 +717,22 @@ QString QQmlVMEMetaObject::readPropertyAsString(int id) return sv->stringValue()->toQString(); } +QUrl QQmlVMEMetaObject::readPropertyAsUrl(int id) +{ + if (!ensurePropertiesAllocated()) + return QUrl(); + + QV4::Scope scope(properties.engine()); + QV4::ScopedObject vp(scope, properties.value()); + QV4::ScopedValue sv(scope, vp->getIndexed(id)); + const QV4::VariantObject *v = sv->as(); + if (!v || v->d()->data.type() != QVariant::Url) { + writeProperty(id, QUrl()); + return QUrl(); + } + return v->d()->data.value(); +} + QSizeF QQmlVMEMetaObject::readPropertyAsSizeF(int id) { if (!ensurePropertiesAllocated()) @@ -711,6 +749,23 @@ QSizeF QQmlVMEMetaObject::readPropertyAsSizeF(int id) return v->d()->data.value(); } +QPointF QQmlVMEMetaObject::readPropertyAsPointF(int id) +{ + if (!ensurePropertiesAllocated()) + return QPointF(); + + QV4::Scope scope(properties.engine()); + QV4::ScopedObject vp(scope, properties.value()); + QV4::ScopedValue sv(scope, vp->getIndexed(id)); + const QV4::VariantObject *v = sv->as(); + if (!v || v->d()->data.type() != QVariant::PointF) { + writeProperty(id, QPointF()); + return QPointF(); + } + return v->d()->data.value(); +} + + int QQmlVMEMetaObject::metaCall(QMetaObject::Call c, int _id, void **a) { int id = _id; @@ -829,7 +884,7 @@ int QQmlVMEMetaObject::metaCall(QMetaObject::Call c, int _id, void **a) *reinterpret_cast(a[0]) = readPropertyAsString(id); break; case QVariant::Url: - *reinterpret_cast(a[0]) = data[id].asQUrl(); + *reinterpret_cast(a[0]) = readPropertyAsUrl(id); break; case QVariant::Date: *reinterpret_cast(a[0]) = data[id].asQDate(); @@ -844,7 +899,7 @@ int QQmlVMEMetaObject::metaCall(QMetaObject::Call c, int _id, void **a) *reinterpret_cast(a[0]) = readPropertyAsSizeF(id); break; case QVariant::PointF: - *reinterpret_cast(a[0]) = data[id].asQPointF(); + *reinterpret_cast(a[0]) = readPropertyAsPointF(id); break; case QMetaType::QObjectStar: *reinterpret_cast(a[0]) = data[id].asQObject(); @@ -885,8 +940,8 @@ int QQmlVMEMetaObject::metaCall(QMetaObject::Call c, int _id, void **a) writeProperty(id, *reinterpret_cast(a[0])); break; case QVariant::Url: - needActivate = *reinterpret_cast(a[0]) != data[id].asQUrl(); - data[id].setValue(*reinterpret_cast(a[0])); + needActivate = *reinterpret_cast(a[0]) != readPropertyAsUrl(id); + writeProperty(id, *reinterpret_cast(a[0])); break; case QVariant::Date: needActivate = *reinterpret_cast(a[0]) != data[id].asQDate(); @@ -905,8 +960,8 @@ int QQmlVMEMetaObject::metaCall(QMetaObject::Call c, int _id, void **a) writeProperty(id, *reinterpret_cast(a[0])); break; case QVariant::PointF: - needActivate = *reinterpret_cast(a[0]) != data[id].asQPointF(); - data[id].setValue(*reinterpret_cast(a[0])); + needActivate = *reinterpret_cast(a[0]) != readPropertyAsPointF(id); + writeProperty(id, *reinterpret_cast(a[0])); break; case QMetaType::QObjectStar: needActivate = *reinterpret_cast(a[0]) != data[id].asQObject(); diff --git a/src/qml/qml/qqmlvmemetaobject_p.h b/src/qml/qml/qqmlvmemetaobject_p.h index c4ca128e8..445b54e61 100644 --- a/src/qml/qml/qqmlvmemetaobject_p.h +++ b/src/qml/qml/qqmlvmemetaobject_p.h @@ -209,12 +209,16 @@ public: double readPropertyAsDouble(int id); QString readPropertyAsString(int id); QSizeF readPropertyAsSizeF(int id); + QPointF readPropertyAsPointF(int id); + QUrl readPropertyAsUrl(int id); void writeProperty(int id, int v); void writeProperty(int id, bool v); void writeProperty(int id, double v); void writeProperty(int id, const QString& v); + void writeProperty(int id, const QPointF& v); void writeProperty(int id, const QSizeF& v); + void writeProperty(int id, const QUrl& v); void ensureQObjectWrapper();