diff options
author | Lars Knoll <lars.knoll@theqtcompany.com> | 2015-01-15 11:36:57 +0100 |
---|---|---|
committer | Lars Knoll <lars.knoll@digia.com> | 2015-01-23 08:07:32 +0100 |
commit | 002a5d4303b3b182ae4abc4a752c49787c1c2821 (patch) | |
tree | 69c7666ed1061c7acacee1d76597c06405459c80 /src/qml/types | |
parent | fddc75e862032163af36d2282051758647b62d15 (diff) |
Get rid of most uses of ValueRef
Instead pass a const Value & into the functions
With our new inheritance structure, we can get rid of ValueRef
and instead simply pass a pointer to a Value again. Pointers to
Values are safe to use again now, as they are now guaranteed to
be in a place where the GC knows about them.
Change-Id: I44c606fde764db3993b8128fd6fb781d3a298e53
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src/qml/types')
-rw-r--r-- | src/qml/types/qqmldelegatemodel.cpp | 34 | ||||
-rw-r--r-- | src/qml/types/qqmldelegatemodel_p_p.h | 12 | ||||
-rw-r--r-- | src/qml/types/qqmllistmodel.cpp | 41 | ||||
-rw-r--r-- | src/qml/types/qqmllistmodel_p_p.h | 4 |
4 files changed, 42 insertions, 49 deletions
diff --git a/src/qml/types/qqmldelegatemodel.cpp b/src/qml/types/qqmldelegatemodel.cpp index 61c3e17c63..6db5765a34 100644 --- a/src/qml/types/qqmldelegatemodel.cpp +++ b/src/qml/types/qqmldelegatemodel.cpp @@ -57,10 +57,10 @@ namespace QV4 { namespace Heap { struct DelegateModelGroupFunction : FunctionObject { - DelegateModelGroupFunction(QV4::ExecutionContext *scope, uint flag, QV4::ReturnedValue (*code)(QQmlDelegateModelItem *item, uint flag, const QV4::ValueRef arg)); + DelegateModelGroupFunction(QV4::ExecutionContext *scope, uint flag, QV4::ReturnedValue (*code)(QQmlDelegateModelItem *item, uint flag, const QV4::Value &arg)); uint flag; - QV4::ReturnedValue (*code)(QQmlDelegateModelItem *item, uint flag, const QV4::ValueRef arg); + QV4::ReturnedValue (*code)(QQmlDelegateModelItem *item, uint flag, const QV4::Value &arg); }; struct QQmlDelegateModelGroupChange : Object { @@ -81,7 +81,7 @@ struct DelegateModelGroupFunction : QV4::FunctionObject { V4_OBJECT2(DelegateModelGroupFunction, FunctionObject) - static Heap::DelegateModelGroupFunction *create(QV4::ExecutionContext *scope, uint flag, QV4::ReturnedValue (*code)(QQmlDelegateModelItem *item, uint flag, const QV4::ValueRef arg)) + static Heap::DelegateModelGroupFunction *create(QV4::ExecutionContext *scope, uint flag, QV4::ReturnedValue (*code)(QQmlDelegateModelItem *item, uint flag, const QV4::Value &arg)) { return scope->engine()->memoryManager->alloc<DelegateModelGroupFunction>(scope, flag, code); } @@ -105,7 +105,7 @@ struct DelegateModelGroupFunction : QV4::FunctionObject } }; -Heap::DelegateModelGroupFunction::DelegateModelGroupFunction(QV4::ExecutionContext *scope, uint flag, QV4::ReturnedValue (*code)(QQmlDelegateModelItem *item, uint flag, const QV4::ValueRef arg)) +Heap::DelegateModelGroupFunction::DelegateModelGroupFunction(QV4::ExecutionContext *scope, uint flag, QV4::ReturnedValue (*code)(QQmlDelegateModelItem *item, uint flag, const QV4::Value &arg)) : QV4::Heap::FunctionObject(scope, QStringLiteral("DelegateModelGroupFunction")) , flag(flag) , code(code) @@ -1621,7 +1621,7 @@ QQmlDelegateModelAttached *QQmlDelegateModel::qmlAttachedProperties(QObject *obj return new QQmlDelegateModelAttached(obj); } -bool QQmlDelegateModelPrivate::insert(Compositor::insert_iterator &before, const QV4::ValueRef object, int groups) +bool QQmlDelegateModelPrivate::insert(Compositor::insert_iterator &before, const QV4::Value &object, int groups) { if (!m_context || !m_context->isValid()) return false; @@ -1629,10 +1629,10 @@ bool QQmlDelegateModelPrivate::insert(Compositor::insert_iterator &before, const QQmlDelegateModelItem *cacheItem = m_adaptorModel.createItem(m_cacheMetaType, m_context->engine(), -1); if (!cacheItem) return false; - if (!object->isObject()) + if (!object.isObject()) return false; - QV4::ExecutionEngine *v4 = object->asObject()->engine(); + QV4::ExecutionEngine *v4 = object.asObject()->engine(); QV4::Scope scope(v4); QV4::ScopedObject o(scope, object); if (!o) @@ -1770,7 +1770,7 @@ int QQmlDelegateModelItemMetaType::parseGroups(const QStringList &groups) const return groupFlags; } -int QQmlDelegateModelItemMetaType::parseGroups(const QV4::ValueRef groups) const +int QQmlDelegateModelItemMetaType::parseGroups(const QV4::Value &groups) const { int groupFlags = 0; QV4::Scope scope(QV8Engine::getV4(v8Engine)); @@ -1847,19 +1847,19 @@ QV4::ReturnedValue QQmlDelegateModelItem::set_groups(QV4::CallContext *ctx) return QV4::Encode::undefined(); } -QV4::ReturnedValue QQmlDelegateModelItem::get_member(QQmlDelegateModelItem *thisItem, uint flag, const QV4::ValueRef) +QV4::ReturnedValue QQmlDelegateModelItem::get_member(QQmlDelegateModelItem *thisItem, uint flag, const QV4::Value &) { return QV4::Encode(bool(thisItem->groups & (1 << flag))); } -QV4::ReturnedValue QQmlDelegateModelItem::set_member(QQmlDelegateModelItem *cacheItem, uint flag, const QV4::ValueRef arg) +QV4::ReturnedValue QQmlDelegateModelItem::set_member(QQmlDelegateModelItem *cacheItem, uint flag, const QV4::Value &arg) { if (!cacheItem->metaType->model) return QV4::Encode::undefined(); QQmlDelegateModelPrivate *model = QQmlDelegateModelPrivate::get(cacheItem->metaType->model); - bool member = arg->toBoolean(); + bool member = arg.toBoolean(); uint groupFlag = (1 << flag); if (member == ((cacheItem->groups & groupFlag) != 0)) return QV4::Encode::undefined(); @@ -1873,7 +1873,7 @@ QV4::ReturnedValue QQmlDelegateModelItem::set_member(QQmlDelegateModelItem *cach return QV4::Encode::undefined(); } -QV4::ReturnedValue QQmlDelegateModelItem::get_index(QQmlDelegateModelItem *thisItem, uint flag, const QV4::ValueRef) +QV4::ReturnedValue QQmlDelegateModelItem::get_index(QQmlDelegateModelItem *thisItem, uint flag, const QV4::Value &) { return QV4::Encode((int)thisItem->groupIndex(Compositor::Group(flag))); } @@ -2494,17 +2494,17 @@ QQmlV4Handle QQmlDelegateModelGroup::get(int index) return QQmlV4Handle(o); } -bool QQmlDelegateModelGroupPrivate::parseIndex(const QV4::ValueRef value, int *index, Compositor::Group *group) const +bool QQmlDelegateModelGroupPrivate::parseIndex(const QV4::Value &value, int *index, Compositor::Group *group) const { - if (value->isNumber()) { - *index = value->toInt32(); + if (value.isNumber()) { + *index = value.toInt32(); return true; } - if (!value->isObject()) + if (!value.isObject()) return false; - QV4::ExecutionEngine *v4 = value->asObject()->engine(); + QV4::ExecutionEngine *v4 = value.asObject()->engine(); QV4::Scope scope(v4); QV4::Scoped<QQmlDelegateModelItemObject> object(scope, value); diff --git a/src/qml/types/qqmldelegatemodel_p_p.h b/src/qml/types/qqmldelegatemodel_p_p.h index ced30b9d1b..413ee826ae 100644 --- a/src/qml/types/qqmldelegatemodel_p_p.h +++ b/src/qml/types/qqmldelegatemodel_p_p.h @@ -70,7 +70,7 @@ public: void initializePrototype(); int parseGroups(const QStringList &groupNames) const; - int parseGroups(const QV4::ValueRef groupNames) const; + int parseGroups(const QV4::Value &groupNames) const; QPointer<QQmlDelegateModel> model; const int groupCount; @@ -128,9 +128,9 @@ public: static QV4::ReturnedValue get_model(QV4::CallContext *ctx); static QV4::ReturnedValue get_groups(QV4::CallContext *ctx); static QV4::ReturnedValue set_groups(QV4::CallContext *ctx); - static QV4::ReturnedValue get_member(QQmlDelegateModelItem *thisItem, uint flag, const QV4::ValueRef); - static QV4::ReturnedValue set_member(QQmlDelegateModelItem *thisItem, uint flag, const QV4::ValueRef arg); - static QV4::ReturnedValue get_index(QQmlDelegateModelItem *thisItem, uint flag, const QV4::ValueRef arg); + static QV4::ReturnedValue get_member(QQmlDelegateModelItem *thisItem, uint flag, const QV4::Value &); + static QV4::ReturnedValue set_member(QQmlDelegateModelItem *thisItem, uint flag, const QV4::Value &arg); + static QV4::ReturnedValue get_index(QQmlDelegateModelItem *thisItem, uint flag, const QV4::Value &arg); QV4::ExecutionEngine *v4; QQmlDelegateModelItemMetaType * const metaType; @@ -227,7 +227,7 @@ public: void initPackage(int index, QQuickPackage *package); void destroyingPackage(QQuickPackage *package); - bool parseIndex(const QV4::ValueRef value, int *index, Compositor::Group *group) const; + bool parseIndex(const QV4::Value &value, int *index, Compositor::Group *group) const; bool parseGroupArgs( QQmlV4Function *args, Compositor::Group *group, int *index, int *count, int *groups) const; @@ -290,7 +290,7 @@ public: void emitChanges(); void emitModelUpdated(const QQmlChangeSet &changeSet, bool reset); - bool insert(Compositor::insert_iterator &before, const QV4::ValueRef object, int groups); + bool insert(Compositor::insert_iterator &before, const QV4::Value &object, int groups); static void group_append(QQmlListProperty<QQmlDelegateModelGroup> *property, QQmlDelegateModelGroup *group); static int group_count(QQmlListProperty<QQmlDelegateModelGroup> *property); diff --git a/src/qml/types/qqmllistmodel.cpp b/src/qml/types/qqmllistmodel.cpp index 0abc62b2bf..ea5b58e90a 100644 --- a/src/qml/types/qqmllistmodel.cpp +++ b/src/qml/types/qqmllistmodel.cpp @@ -412,8 +412,6 @@ void ListModel::set(int elementIndex, QV4::Object *object, QVector<int> *roles) QV4::ObjectIterator it(scope, object, QV4::ObjectIterator::WithProtoChain|QV4::ObjectIterator::EnumerableOnly); QV4::ScopedString propertyName(scope); QV4::ScopedValue propertyValue(scope); - QV4::ScopedString s(scope); - QV4::ScopedArrayObject a(scope); while (1) { propertyName = it.nextPropertyNameAsString(propertyValue); if (!propertyName) @@ -423,13 +421,13 @@ void ListModel::set(int elementIndex, QV4::Object *object, QVector<int> *roles) int roleIndex = -1; // Add the value now - if ((s = propertyValue)) { + if (QV4::String *s = propertyValue->asString()) { const ListLayout::Role &r = m_layout->getRoleOrCreate(propertyName, ListLayout::Role::String); roleIndex = e->setStringProperty(r, s->toQString()); } else if (propertyValue->isNumber()) { const ListLayout::Role &r = m_layout->getRoleOrCreate(propertyName, ListLayout::Role::Number); roleIndex = e->setDoubleProperty(r, propertyValue->asDouble()); - } else if ((a = propertyValue)) { + } else if (QV4::ArrayObject *a = propertyValue->asArrayObject()) { const ListLayout::Role &r = m_layout->getRoleOrCreate(propertyName, ListLayout::Role::List); ListModel *subModel = new ListModel(r.subLayout, 0, -1); @@ -489,8 +487,6 @@ void ListModel::set(int elementIndex, QV4::Object *object) QV4::ScopedString propertyName(scope); QV4::ScopedValue propertyValue(scope); QV4::ScopedObject o(scope); - QV4::ScopedArrayObject a(scope); - QV4::Scoped<QV4::DateObject> date(scope); while (1) { propertyName = it.nextPropertyNameAsString(propertyValue); if (!propertyName) @@ -506,8 +502,7 @@ void ListModel::set(int elementIndex, QV4::Object *object) if (r.type == ListLayout::Role::Number) { e->setDoublePropertyFast(r, propertyValue->asDouble()); } - } else if (propertyValue->asArrayObject()) { - a = propertyValue; + } else if (QV4::ArrayObject *a = propertyValue->asArrayObject()) { const ListLayout::Role &r = m_layout->getRoleOrCreate(propertyName, ListLayout::Role::List); if (r.type == ListLayout::Role::List) { ListModel *subModel = new ListModel(r.subLayout, 0, -1); @@ -525,15 +520,13 @@ void ListModel::set(int elementIndex, QV4::Object *object) if (r.type == ListLayout::Role::Bool) { e->setBoolPropertyFast(r, propertyValue->booleanValue()); } - } else if (propertyValue->asDateObject()) { - date = propertyValue; + } else if (QV4::DateObject *date = propertyValue->asDateObject()) { const ListLayout::Role &r = m_layout->getRoleOrCreate(propertyName, ListLayout::Role::DateTime); if (r.type == ListLayout::Role::DateTime) { QDateTime dt = date->toQDateTime();; e->setDateTimePropertyFast(r, dt); } - } else if (propertyValue->isObject()) { - o = propertyValue; + } else if (QV4::Object *o = propertyValue->asObject()) { if (QV4::QObjectWrapper *wrapper = o->as<QV4::QObjectWrapper>()) { QObject *o = wrapper->object(); const ListLayout::Role &r = m_layout->getRoleOrCreate(propertyName, ListLayout::Role::QObject); @@ -607,7 +600,7 @@ int ListModel::setOrCreateProperty(int elementIndex, const QString &key, const Q return roleIndex; } -int ListModel::setExistingProperty(int elementIndex, const QString &key, const QV4::ValueRef data, QV4::ExecutionEngine *eng) +int ListModel::setExistingProperty(int elementIndex, const QString &key, const QV4::Value &data, QV4::ExecutionEngine *eng) { int roleIndex = -1; @@ -1163,7 +1156,7 @@ int ListElement::setVariantProperty(const ListLayout::Role &role, const QVariant return roleIndex; } -int ListElement::setJsProperty(const ListLayout::Role &role, const QV4::ValueRef d, QV4::ExecutionEngine *eng) +int ListElement::setJsProperty(const ListLayout::Role &role, const QV4::Value &d, QV4::ExecutionEngine *eng) { // Check if this key exists yet int roleIndex = -1; @@ -1171,12 +1164,12 @@ int ListElement::setJsProperty(const ListLayout::Role &role, const QV4::ValueRef QV4::Scope scope(eng); // Add the value now - if (d->isString()) { - QString qstr = d->toQString(); + if (d.isString()) { + QString qstr = d.toQString(); roleIndex = setStringProperty(role, qstr); - } else if (d->isNumber()) { - roleIndex = setDoubleProperty(role, d->asDouble()); - } else if (d->asArrayObject()) { + } else if (d.isNumber()) { + roleIndex = setDoubleProperty(role, d.asDouble()); + } else if (d.asArrayObject()) { QV4::ScopedArrayObject a(scope, d); if (role.type == ListLayout::Role::List) { QV4::Scope scope(a->engine()); @@ -1192,13 +1185,13 @@ int ListElement::setJsProperty(const ListLayout::Role &role, const QV4::ValueRef } else { qmlInfo(0) << QString::fromLatin1("Can't assign to existing role '%1' of different type [%2 -> %3]").arg(role.name).arg(roleTypeName(role.type)).arg(roleTypeName(ListLayout::Role::List)); } - } else if (d->isBoolean()) { - roleIndex = setBoolProperty(role, d->booleanValue()); - } else if (d->asDateObject()) { + } else if (d.isBoolean()) { + roleIndex = setBoolProperty(role, d.booleanValue()); + } else if (d.asDateObject()) { QV4::Scoped<QV4::DateObject> dd(scope, d); QDateTime dt = dd->toQDateTime(); roleIndex = setDateTimeProperty(role, dt); - } else if (d->isObject()) { + } else if (d.isObject()) { QV4::ScopedObject o(scope, d); QV4::QObjectWrapper *wrapper = o->as<QV4::QObjectWrapper>(); if (role.type == ListLayout::Role::QObject && wrapper) { @@ -1207,7 +1200,7 @@ int ListElement::setJsProperty(const ListLayout::Role &role, const QV4::ValueRef } else if (role.type == ListLayout::Role::VariantMap) { roleIndex = setVariantMapProperty(role, o); } - } else if (d->isNullOrUndefined()) { + } else if (d.isNullOrUndefined()) { clearProperty(role); } diff --git a/src/qml/types/qqmllistmodel_p_p.h b/src/qml/types/qqmllistmodel_p_p.h index 36d192f2fa..27d0ffcb49 100644 --- a/src/qml/types/qqmllistmodel_p_p.h +++ b/src/qml/types/qqmllistmodel_p_p.h @@ -245,7 +245,7 @@ private: int setVariantProperty(const ListLayout::Role &role, const QVariant &d); - int setJsProperty(const ListLayout::Role &role, const QV4::ValueRef d, QV4::ExecutionEngine *eng); + int setJsProperty(const ListLayout::Role &role, const QV4::Value &d, QV4::ExecutionEngine *eng); int setStringProperty(const ListLayout::Role &role, const QString &s); int setDoubleProperty(const ListLayout::Role &role, double n); @@ -300,7 +300,7 @@ public: void destroy(); int setOrCreateProperty(int elementIndex, const QString &key, const QVariant &data); - int setExistingProperty(int uid, const QString &key, const QV4::ValueRef data, QV4::ExecutionEngine *eng); + int setExistingProperty(int uid, const QString &key, const QV4::Value &data, QV4::ExecutionEngine *eng); QVariant getProperty(int elementIndex, int roleIndex, const QQmlListModel *owner, QV4::ExecutionEngine *eng); ListModel *getListProperty(int elementIndex, const ListLayout::Role &role); |