Cleanup: change signature of Object::insertMember()
authorLars Knoll <lars.knoll@digia.com>
Tue, 7 Jan 2014 15:10:00 +0000 (16:10 +0100)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Thu, 9 Jan 2014 06:47:22 +0000 (07:47 +0100)
Methods returning a Property pointer have to be removed, so that
we can move over to store member data requiring only one value for
the common case of data properties.

This will in the long term reduce memory consumption on 64 bit
systems quite a bit.

Change-Id: I78de3794ec7b3bc5db13aa57275d3f08fa9d470a
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
src/imports/xmllistmodel/qqmlxmllistmodel.cpp
src/qml/jsruntime/qv4functionobject.cpp
src/qml/jsruntime/qv4jsonobject.cpp
src/qml/jsruntime/qv4object.cpp
src/qml/jsruntime/qv4object_p.h
src/qml/jsruntime/qv4objectproto.cpp
src/qml/jsruntime/qv4regexpobject.cpp
src/qml/jsruntime/qv4runtime.cpp
src/qml/qml/v8/qv8engine.cpp
src/qml/types/qqmldelegatemodel.cpp
src/qml/util/qqmladaptormodel.cpp

index 97dc3ab..ebfdad5 100644 (file)
@@ -925,10 +925,12 @@ QQmlV4Handle QQuickXmlListModel::get(int index) const
     ExecutionEngine *v4engine = QV8Engine::getV4(v8engine);
     Scope scope(v4engine);
     Scoped<Object> o(scope, v4engine->newObject());
+    ScopedString name(scope);
+    ScopedValue value(scope);
     for (int ii = 0; ii < d->roleObjects.count(); ++ii) {
-        ScopedString name(scope, v4engine->newIdentifier(d->roleObjects[ii]->name()));
-        Property *p = o->insertMember(name, PropertyAttributes());
-        p->value = v8engine->fromVariant(d->data.value(ii).value(index));
+        name = v4engine->newIdentifier(d->roleObjects[ii]->name());
+        value = v8engine->fromVariant(d->data.value(ii).value(index));
+        o->insertMember(name, value);
     }
 
     return QQmlV4Handle(o);
index 10b2590..a1673df 100644 (file)
@@ -427,8 +427,8 @@ ScriptFunction::ScriptFunction(ExecutionContext *scope, Function *function)
 
     if (scope->strictMode) {
         Property pd = Property::fromAccessor(v4->thrower, v4->thrower);
-        *insertMember(scope->engine->id_caller, Attr_Accessor|Attr_NotConfigurable|Attr_NotEnumerable) = pd;
-        *insertMember(scope->engine->id_arguments, Attr_Accessor|Attr_NotConfigurable|Attr_NotEnumerable) = pd;
+        insertMember(scope->engine->id_caller, pd, Attr_Accessor|Attr_NotConfigurable|Attr_NotEnumerable);
+        insertMember(scope->engine->id_arguments, pd, Attr_Accessor|Attr_NotConfigurable|Attr_NotEnumerable);
     }
 }
 
@@ -509,8 +509,8 @@ SimpleScriptFunction::SimpleScriptFunction(ExecutionContext *scope, Function *fu
 
     if (scope->strictMode) {
         Property pd = Property::fromAccessor(v4->thrower, v4->thrower);
-        *insertMember(scope->engine->id_caller, Attr_Accessor|Attr_NotConfigurable|Attr_NotEnumerable) = pd;
-        *insertMember(scope->engine->id_arguments, Attr_Accessor|Attr_NotConfigurable|Attr_NotEnumerable) = pd;
+        insertMember(scope->engine->id_caller, pd, Attr_Accessor|Attr_NotConfigurable|Attr_NotEnumerable);
+        insertMember(scope->engine->id_arguments, pd, Attr_Accessor|Attr_NotConfigurable|Attr_NotEnumerable);
     }
 }
 
@@ -668,8 +668,8 @@ BoundFunction::BoundFunction(ExecutionContext *scope, FunctionObjectRef target,
     ExecutionEngine *v4 = scope->engine;
 
     Property pd = Property::fromAccessor(v4->thrower, v4->thrower);
-    *insertMember(scope->engine->id_arguments, Attr_Accessor|Attr_NotConfigurable|Attr_NotEnumerable) = pd;
-    *insertMember(scope->engine->id_caller, Attr_Accessor|Attr_NotConfigurable|Attr_NotEnumerable) = pd;
+    insertMember(scope->engine->id_arguments, pd, Attr_Accessor|Attr_NotConfigurable|Attr_NotEnumerable);
+    insertMember(scope->engine->id_caller, pd, Attr_Accessor|Attr_NotConfigurable|Attr_NotEnumerable);
 }
 
 void BoundFunction::destroy(Managed *that)
index 65f053e..f40c765 100644 (file)
@@ -290,8 +290,7 @@ bool JsonParser::parseMember(ObjectRef o)
     if (idx < UINT_MAX) {
         o->putIndexed(idx, val);
     } else {
-        Property *p = o->insertMember(s, Attr_Data);
-        p->value = val.asReturnedValue();
+        o->insertMember(s, val);
     }
 
     END;
index c155e70..00d11b4 100644 (file)
@@ -162,12 +162,6 @@ void Object::putValue(Property *pd, PropertyAttributes attrs, const ValueRef val
         engine()->currentContext()->throwTypeError();
 }
 
-void Object::defineDefaultProperty(const StringRef name, ValueRef value)
-{
-    Property *pd = insertMember(name, Attr_Data|Attr_NotEnumerable);
-    pd->value = *value;
-}
-
 void Object::defineDefaultProperty(const QString &name, ValueRef value)
 {
     ExecutionEngine *e = engine();
@@ -206,12 +200,10 @@ void Object::defineAccessorProperty(const QString &name, ReturnedValue (*getter)
 void Object::defineAccessorProperty(const StringRef name, ReturnedValue (*getter)(CallContext *), ReturnedValue (*setter)(CallContext *))
 {
     ExecutionEngine *v4 = engine();
-    Property *p = insertMember(name, QV4::Attr_Accessor|QV4::Attr_NotConfigurable|QV4::Attr_NotEnumerable);
-
-    if (getter)
-        p->setGetter(v4->newBuiltinFunction(v4->rootContext, name, getter)->getPointer());
-    if (setter)
-        p->setSetter(v4->newBuiltinFunction(v4->rootContext, name, setter)->getPointer());
+    Property p;
+    p.setGetter(getter ? v4->newBuiltinFunction(v4->rootContext, name, getter)->getPointer() : 0);
+    p.setSetter(setter ? v4->newBuiltinFunction(v4->rootContext, name, setter)->getPointer() : 0);
+    insertMember(name, p, QV4::Attr_Accessor|QV4::Attr_NotConfigurable|QV4::Attr_NotEnumerable);
 }
 
 void Object::defineReadonlyProperty(const QString &name, ValueRef value)
@@ -224,8 +216,7 @@ void Object::defineReadonlyProperty(const QString &name, ValueRef value)
 
 void Object::defineReadonlyProperty(const StringRef name, ValueRef value)
 {
-    Property *pd = insertMember(name, Attr_ReadOnly);
-    pd->value = *value;
+    insertMember(name, value, Attr_ReadOnly);
 }
 
 void Object::markObjects(Managed *that, ExecutionEngine *e)
@@ -265,7 +256,7 @@ void Object::ensureMemberIndex(uint idx)
     }
 }
 
-Property *Object::insertMember(const StringRef s, PropertyAttributes attributes)
+void Object::insertMember(const StringRef s, const Property &p, PropertyAttributes attributes)
 {
     uint idx;
     internalClass = internalClass->addMember(s.getPointer(), attributes, &idx);
@@ -275,7 +266,7 @@ Property *Object::insertMember(const StringRef s, PropertyAttributes attributes)
 
     ensureMemberIndex(idx);
 
-    return memberData + idx;
+    memberData[idx] = p;
 }
 
 // Section 8.12.1
@@ -734,11 +725,8 @@ void Object::internalPut(const StringRef name, const ValueRef value)
         return;
     }
 
-    {
-        Property *p = insertMember(name, Attr_Data);
-        p->value = *value;
-        return;
-    }
+    insertMember(name, value);
+    return;
 
   reject:
     if (engine()->currentContext()->strictMode) {
@@ -910,9 +898,9 @@ bool Object::__defineOwnProperty__(ExecutionContext *ctx, const StringRef name,
         if (!extensible)
             goto reject;
         // clause 4
-        Property *pd = insertMember(name, attrs);
-        *pd = p;
-        pd->fullyPopulated(&attrs);
+        Property pd = p;
+        pd.fullyPopulated(&attrs);
+        insertMember(name, pd, attrs);
         return true;
     }
 
index b9fc05e..9500c2a 100644 (file)
@@ -157,7 +157,9 @@ struct Q_QML_EXPORT Object: Managed {
     void putValue(Property *pd, PropertyAttributes attrs, const ValueRef value);
 
     /* The spec default: Writable: true, Enumerable: false, Configurable: true */
-    void defineDefaultProperty(const StringRef name, ValueRef value);
+    void defineDefaultProperty(const StringRef name, ValueRef value) {
+        insertMember(name, value, Attr_Data|Attr_NotEnumerable);
+    }
     void defineDefaultProperty(const QString &name, ValueRef value);
     void defineDefaultProperty(const QString &name, ReturnedValue (*code)(CallContext *), int argumentCount = 0);
     void defineDefaultProperty(const StringRef name, ReturnedValue (*code)(CallContext *), int argumentCount = 0);
@@ -167,7 +169,10 @@ struct Q_QML_EXPORT Object: Managed {
     void defineReadonlyProperty(const QString &name, ValueRef value);
     void defineReadonlyProperty(const StringRef name, ValueRef value);
 
-    Property *insertMember(const StringRef s, PropertyAttributes attributes);
+    void insertMember(const StringRef s, const ValueRef v, PropertyAttributes attributes = Attr_Data) {
+        insertMember(s, Property::fromValue(*v), attributes);
+    }
+    void insertMember(const StringRef s, const Property &p, PropertyAttributes attributes);
 
     inline ExecutionEngine *engine() const { return internalClass->engine; }
 
index f319b99..ac19101 100644 (file)
@@ -134,9 +134,9 @@ void ObjectPrototype::init(ExecutionEngine *v4, ObjectRef ctor)
     defineDefaultProperty(QStringLiteral("__defineSetter__"), method_defineSetter, 2);
 
     Scoped<String> id_proto(scope, v4->id___proto__);
-    Property *p = insertMember(StringRef(v4->id___proto__), Attr_Accessor|Attr_NotEnumerable);
-    p->setGetter(v4->newBuiltinFunction(v4->rootContext, id_proto, method_get_proto)->getPointer());
-    p->setSetter(v4->newBuiltinFunction(v4->rootContext, id_proto, method_set_proto)->getPointer());
+    Property p = Property::fromAccessor(v4->newBuiltinFunction(v4->rootContext, id_proto, method_get_proto)->getPointer(),
+                                        v4->newBuiltinFunction(v4->rootContext, id_proto, method_set_proto)->getPointer());
+    insertMember(StringRef(v4->id___proto__), p, Attr_Accessor|Attr_NotEnumerable);
 }
 
 ReturnedValue ObjectPrototype::method_getPrototypeOf(CallContext *ctx)
index 1813250..1b55c5a 100644 (file)
@@ -149,8 +149,8 @@ void RegExpObject::init(ExecutionEngine *engine)
     ScopedObject protectThis(scope, this);
 
     ScopedString lastIndex(scope, engine->newIdentifier(QStringLiteral("lastIndex")));
-    Property *lastIndexProperty = insertMember(lastIndex, Attr_NotEnumerable|Attr_NotConfigurable);
-    lastIndexProperty->value = Primitive::fromInt32(0);
+    ScopedValue v(scope, Primitive::fromInt32(0));
+    insertMember(lastIndex, v, Attr_NotEnumerable|Attr_NotConfigurable);
     if (!this->value)
         return;
 
@@ -162,7 +162,6 @@ void RegExpObject::init(ExecutionEngine *engine)
         p.replace('/', QLatin1String("\\/"));
     }
 
-    ScopedValue v(scope);
     defineReadonlyProperty(QStringLiteral("source"), (v = engine->newString(p)));
     defineReadonlyProperty(QStringLiteral("global"), Primitive::fromBoolean(global));
     defineReadonlyProperty(QStringLiteral("ignoreCase"), Primitive::fromBoolean(this->value->ignoreCase()));
index 91ddfd0..9275704 100644 (file)
@@ -1093,8 +1093,8 @@ void __qmljs_builtin_define_property(ExecutionContext *ctx, const ValueRef objec
     if (idx != UINT_MAX) {
         o->arraySet(idx, val);
     } else {
-        Property *pd = o->insertMember(name, Attr_Data);
-        pd->value = val ? *val : Primitive::undefinedValue();
+        ScopedValue v(scope, val ? *val : Primitive::undefinedValue());
+        o->insertMember(name, v);
     }
 }
 
@@ -1119,15 +1119,13 @@ void __qmljs_builtin_define_getter_setter(ExecutionContext *ctx, const ValueRef
     Q_ASSERT(!!o);
 
     uint idx = name->asArrayIndex();
+    Property pd;
+    pd.setGetter(getter ? getter->asFunctionObject() : 0);
+    pd.setSetter(setter ? setter->asFunctionObject() : 0);
     if (idx != UINT_MAX) {
-        Property pd;
-        pd.setGetter(getter ? getter->asFunctionObject() : 0);
-        pd.setSetter(setter ? setter->asFunctionObject() : 0);
         o->arraySet(idx, pd, Attr_Accessor);
     } else {
-        Property *pd = o->insertMember(name, Attr_Accessor);
-        pd->setGetter(getter ? getter->asFunctionObject() : 0);
-        pd->setSetter(setter ? setter->asFunctionObject() : 0);
+        o->insertMember(name, pd, Attr_Accessor);
     }
 }
 
index c5c2a69..e64cc0c 100644 (file)
@@ -593,10 +593,11 @@ QV4::ReturnedValue QV8Engine::variantMapToJS(const QVariantMap &vmap)
     QV4::Scoped<QV4::Object> o(scope, m_v4Engine->newObject());
     QVariantMap::const_iterator it;
     QV4::ScopedString s(scope);
+    QV4::ScopedValue v(scope);
     for (it = vmap.constBegin(); it != vmap.constEnd(); ++it) {
         s = m_v4Engine->newIdentifier(it.key());
-        QV4::Property *p = o->insertMember(s, QV4::Attr_Data);
-        p->value = variantToJS(it.value());
+        v = variantToJS(it.value());
+        o->insertMember(s, v);
     }
     return o.asReturnedValue();
 }
index 40150d6..4c8635b 100644 (file)
@@ -1629,37 +1629,46 @@ void QQmlDelegateModelItemMetaType::initializePrototype()
     proto->defineAccessorProperty(QStringLiteral("model"), QQmlDelegateModelItem::get_model, 0);
     proto->defineAccessorProperty(QStringLiteral("groups"), QQmlDelegateModelItem::get_groups, QQmlDelegateModelItem::set_groups);
     QV4::ScopedString s(scope);
+    QV4::Property p;
+
     s = v4->newString(QStringLiteral("isUnresolved"));
-    QV4::Property *p = proto->insertMember(s, QV4::Attr_Accessor|QV4::Attr_NotConfigurable|QV4::Attr_NotEnumerable);
-    p->setGetter(new (v4->memoryManager) DelegateModelGroupFunction(v4->rootContext, 30, QQmlDelegateModelItem::get_member));
+    p.setGetter(new (v4->memoryManager) DelegateModelGroupFunction(v4->rootContext, 30, QQmlDelegateModelItem::get_member));
+    p.setSetter(0);
+    proto->insertMember(s, p, QV4::Attr_Accessor|QV4::Attr_NotConfigurable|QV4::Attr_NotEnumerable);
+
     s = v4->newString(QStringLiteral("inItems"));
-    p = proto->insertMember(s, QV4::Attr_Accessor|QV4::Attr_NotConfigurable|QV4::Attr_NotEnumerable);
-    p->setGetter(new (v4->memoryManager) DelegateModelGroupFunction(v4->rootContext, QQmlListCompositor::Default, QQmlDelegateModelItem::get_member));
-    p->setSetter(new (v4->memoryManager) DelegateModelGroupFunction(v4->rootContext, QQmlListCompositor::Default, QQmlDelegateModelItem::set_member));
+    p.setGetter(new (v4->memoryManager) DelegateModelGroupFunction(v4->rootContext, QQmlListCompositor::Default, QQmlDelegateModelItem::get_member));
+    p.setSetter(new (v4->memoryManager) DelegateModelGroupFunction(v4->rootContext, QQmlListCompositor::Default, QQmlDelegateModelItem::set_member));
+    proto->insertMember(s, p, QV4::Attr_Accessor|QV4::Attr_NotConfigurable|QV4::Attr_NotEnumerable);
+
     s = v4->newString(QStringLiteral("inPersistedItems"));
-    p = proto->insertMember(s, QV4::Attr_Accessor|QV4::Attr_NotConfigurable|QV4::Attr_NotEnumerable);
-    p->setGetter(new (v4->memoryManager) DelegateModelGroupFunction(v4->rootContext, QQmlListCompositor::Persisted, QQmlDelegateModelItem::get_member));
-    p->setSetter(new (v4->memoryManager) DelegateModelGroupFunction(v4->rootContext, QQmlListCompositor::Persisted, QQmlDelegateModelItem::set_member));
+    p.setGetter(new (v4->memoryManager) DelegateModelGroupFunction(v4->rootContext, QQmlListCompositor::Persisted, QQmlDelegateModelItem::get_member));
+    p.setSetter(new (v4->memoryManager) DelegateModelGroupFunction(v4->rootContext, QQmlListCompositor::Persisted, QQmlDelegateModelItem::set_member));
+    proto->insertMember(s, p, QV4::Attr_Accessor|QV4::Attr_NotConfigurable|QV4::Attr_NotEnumerable);
+
     s = v4->newString(QStringLiteral("itemsIndex"));
-    p = proto->insertMember(s, QV4::Attr_Accessor|QV4::Attr_NotConfigurable|QV4::Attr_NotEnumerable);
-    p->setGetter(new (v4->memoryManager) DelegateModelGroupFunction(v4->rootContext, QQmlListCompositor::Default, QQmlDelegateModelItem::get_index));
+    p.setGetter(new (v4->memoryManager) DelegateModelGroupFunction(v4->rootContext, QQmlListCompositor::Default, QQmlDelegateModelItem::get_index));
+    proto->insertMember(s, p, QV4::Attr_Accessor|QV4::Attr_NotConfigurable|QV4::Attr_NotEnumerable);
+
     s = v4->newString(QStringLiteral("persistedItemsIndex"));
-    p = proto->insertMember(s, QV4::Attr_Accessor|QV4::Attr_NotConfigurable|QV4::Attr_NotEnumerable);
-    p->setGetter(new (v4->memoryManager) DelegateModelGroupFunction(v4->rootContext, QQmlListCompositor::Persisted, QQmlDelegateModelItem::get_index));
+    p.setGetter(new (v4->memoryManager) DelegateModelGroupFunction(v4->rootContext, QQmlListCompositor::Persisted, QQmlDelegateModelItem::get_index));
+    p.setSetter(0);
+    proto->insertMember(s, p, QV4::Attr_Accessor|QV4::Attr_NotConfigurable|QV4::Attr_NotEnumerable);
 
     for (int i = 2; i < groupNames.count(); ++i) {
         QString propertyName = QStringLiteral("in") + groupNames.at(i);
         propertyName.replace(2, 1, propertyName.at(2).toUpper());
         s = v4->newString(propertyName);
-        p = proto->insertMember(s, QV4::Attr_Accessor|QV4::Attr_NotConfigurable|QV4::Attr_NotEnumerable);
-        p->setGetter(new (v4->memoryManager) DelegateModelGroupFunction(v4->rootContext, i + 1, QQmlDelegateModelItem::get_member));
-        p->setSetter(new (v4->memoryManager) DelegateModelGroupFunction(v4->rootContext, i + 1, QQmlDelegateModelItem::set_member));
+        p.setGetter(new (v4->memoryManager) DelegateModelGroupFunction(v4->rootContext, i + 1, QQmlDelegateModelItem::get_member));
+        p.setSetter(new (v4->memoryManager) DelegateModelGroupFunction(v4->rootContext, i + 1, QQmlDelegateModelItem::set_member));
+        proto->insertMember(s, p, QV4::Attr_Accessor|QV4::Attr_NotConfigurable|QV4::Attr_NotEnumerable);
     }
     for (int i = 2; i < groupNames.count(); ++i) {
         const QString propertyName = groupNames.at(i) + QStringLiteral("Index");
         s = v4->newString(propertyName);
-        p = proto->insertMember(s, QV4::Attr_Accessor|QV4::Attr_NotConfigurable|QV4::Attr_NotEnumerable);
-        p->setGetter(new (v4->memoryManager) DelegateModelGroupFunction(v4->rootContext, i + 1, QQmlDelegateModelItem::get_index));
+        p.setGetter(new (v4->memoryManager) DelegateModelGroupFunction(v4->rootContext, i + 1, QQmlDelegateModelItem::get_index));
+        p.setSetter(0);
+        proto->insertMember(s, p, QV4::Attr_Accessor|QV4::Attr_NotConfigurable|QV4::Attr_NotEnumerable);
     }
     modelItemProto = proto;
 }
index 38fdffd..36c3623 100644 (file)
@@ -226,9 +226,10 @@ public:
             const QByteArray &propertyName = it.key();
 
             QV4::ScopedString name(scope, v4->newString(QString::fromUtf8(propertyName)));
-            QV4::Property *p = proto->insertMember(name, QV4::Attr_Accessor|QV4::Attr_NotEnumerable|QV4::Attr_NotConfigurable);
-            p->setGetter(new (v4->memoryManager) QV4::IndexedBuiltinFunction(v4->rootContext, propertyId, QQmlDMCachedModelData::get_property));
-            p->setSetter(new (v4->memoryManager) QV4::IndexedBuiltinFunction(v4->rootContext, propertyId, QQmlDMCachedModelData::set_property));
+            QV4::Property p;
+            p.setGetter(new (v4->memoryManager) QV4::IndexedBuiltinFunction(v4->rootContext, propertyId, QQmlDMCachedModelData::get_property));
+            p.setSetter(new (v4->memoryManager) QV4::IndexedBuiltinFunction(v4->rootContext, propertyId, QQmlDMCachedModelData::set_property));
+            proto->insertMember(name, p, QV4::Attr_Accessor|QV4::Attr_NotEnumerable|QV4::Attr_NotConfigurable);
         }
         prototype = proto;
     }