Get rid of asManaged()
authorLars Knoll <lars.knoll@theqtcompany.com>
Fri, 13 Feb 2015 11:19:04 +0000 (12:19 +0100)
committerSimon Hausmann <simon.hausmann@theqtcompany.com>
Tue, 21 Apr 2015 13:01:41 +0000 (13:01 +0000)
Change-Id: I853417fdf1cc339f7d43a006c20e1626b6bfb288
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
13 files changed:
src/qml/jsruntime/qv4debugging.cpp
src/qml/jsruntime/qv4lookup.cpp
src/qml/jsruntime/qv4lookup_p.h
src/qml/jsruntime/qv4managed_p.h
src/qml/jsruntime/qv4object.cpp
src/qml/jsruntime/qv4persistent.cpp
src/qml/jsruntime/qv4persistent_p.h
src/qml/jsruntime/qv4runtime.cpp
src/qml/jsruntime/qv4serialize.cpp
src/qml/jsruntime/qv4value_inl_p.h
src/qml/jsruntime/qv4value_p.h
src/qml/memory/qv4mm.cpp
src/qml/types/qqmllistmodel.cpp

index 36e7a35..5f1194c 100644 (file)
@@ -793,7 +793,7 @@ void Debugger::Collector::collect(const QString &name, const ScopedValue &value)
         addBoolean(name, value->booleanValue());
         break;
     case Value::Managed_Type:
-        if (String *s = value->asString())
+        if (const String *s = value->as<String>())
             addString(name, s->toQString());
         else
             addObject(name, value);
index 274cb90..cc1aca7 100644 (file)
@@ -123,7 +123,7 @@ ReturnedValue Lookup::indexedGetterFallback(Lookup *l, const Value &object, cons
     ScopedObject o(scope, object);
     if (!o) {
         if (idx < UINT_MAX) {
-            if (String *str = object.asString()) {
+            if (const String *str = object.as<String>()) {
                 if (idx >= (uint)str->toQString().length()) {
                     return Encode::undefined();
                 }
@@ -560,7 +560,7 @@ ReturnedValue Lookup::primitiveGetterAccessor1(Lookup *l, ExecutionEngine *engin
 
 ReturnedValue Lookup::stringLengthGetter(Lookup *l, ExecutionEngine *engine, const Value &object)
 {
-    if (String *s = object.asString())
+    if (const String *s = object.as<String>())
         return Encode(s->d()->length());
 
     l->getter = getterGeneric;
@@ -701,7 +701,7 @@ ReturnedValue Lookup::globalGetterAccessor2(Lookup *l, ExecutionEngine *engine)
     return globalGetterGeneric(l, engine);
 }
 
-void Lookup::setterGeneric(Lookup *l, ExecutionEngine *engine, const Value &object, const Value &value)
+void Lookup::setterGeneric(Lookup *l, ExecutionEngine *engine, Value &object, const Value &value)
 {
     Scope scope(engine);
     ScopedObject o(scope, object);
@@ -716,7 +716,7 @@ void Lookup::setterGeneric(Lookup *l, ExecutionEngine *engine, const Value &obje
     o->setLookup(l, value);
 }
 
-void Lookup::setterTwoClasses(Lookup *l, ExecutionEngine *engine, const Value &object, const Value &value)
+void Lookup::setterTwoClasses(Lookup *l, ExecutionEngine *engine, Value &object, const Value &value)
 {
     Lookup l1 = *l;
 
@@ -735,7 +735,7 @@ void Lookup::setterTwoClasses(Lookup *l, ExecutionEngine *engine, const Value &o
     setterFallback(l, engine, object, value);
 }
 
-void Lookup::setterFallback(Lookup *l, ExecutionEngine *engine, const Value &object, const Value &value)
+void Lookup::setterFallback(Lookup *l, ExecutionEngine *engine, Value &object, const Value &value)
 {
     QV4::Scope scope(engine);
     QV4::ScopedObject o(scope, object.toObject(scope.engine));
@@ -745,9 +745,9 @@ void Lookup::setterFallback(Lookup *l, ExecutionEngine *engine, const Value &obj
     }
 }
 
-void Lookup::setter0(Lookup *l, ExecutionEngine *engine, const Value &object, const Value &value)
+void Lookup::setter0(Lookup *l, ExecutionEngine *engine, Value &object, const Value &value)
 {
-    Object *o = static_cast<Object *>(object.asManaged());
+    Object *o = object.as<Object>();
     if (o && o->internalClass() == l->classList[0]) {
         o->memberData()->data[l->index] = value;
         return;
@@ -756,9 +756,9 @@ void Lookup::setter0(Lookup *l, ExecutionEngine *engine, const Value &object, co
     setterTwoClasses(l, engine, object, value);
 }
 
-void Lookup::setterInsert0(Lookup *l, ExecutionEngine *engine, const Value &object, const Value &value)
+void Lookup::setterInsert0(Lookup *l, ExecutionEngine *engine, Value &object, const Value &value)
 {
-    Object *o = static_cast<Object *>(object.asManaged());
+    Object *o = object.as<Object>();
     if (o && o->internalClass() == l->classList[0]) {
         if (!o->prototype()) {
             if (!o->memberData() || l->index >= o->memberData()->size)
@@ -773,9 +773,9 @@ void Lookup::setterInsert0(Lookup *l, ExecutionEngine *engine, const Value &obje
     setterFallback(l, engine, object, value);
 }
 
-void Lookup::setterInsert1(Lookup *l, ExecutionEngine *engine, const Value &object, const Value &value)
+void Lookup::setterInsert1(Lookup *l, ExecutionEngine *engine, Value &object, const Value &value)
 {
-    Object *o = static_cast<Object *>(object.asManaged());
+    Object *o = object.as<Object>();
     if (o && o->internalClass() == l->classList[0]) {
         Heap::Object *p = o->prototype();
         if (p && p->internalClass == l->classList[1]) {
@@ -791,9 +791,9 @@ void Lookup::setterInsert1(Lookup *l, ExecutionEngine *engine, const Value &obje
     setterFallback(l, engine, object, value);
 }
 
-void Lookup::setterInsert2(Lookup *l, ExecutionEngine *engine, const Value &object, const Value &value)
+void Lookup::setterInsert2(Lookup *l, ExecutionEngine *engine, Value &object, const Value &value)
 {
-    Object *o = static_cast<Object *>(object.asManaged());
+    Object *o = object.as<Object>();
     if (o && o->internalClass() == l->classList[0]) {
         Heap::Object *p = o->prototype();
         if (p && p->internalClass == l->classList[1]) {
@@ -812,9 +812,9 @@ void Lookup::setterInsert2(Lookup *l, ExecutionEngine *engine, const Value &obje
     setterFallback(l, engine, object, value);
 }
 
-void Lookup::setter0setter0(Lookup *l, ExecutionEngine *engine, const Value &object, const Value &value)
+void Lookup::setter0setter0(Lookup *l, ExecutionEngine *engine, Value &object, const Value &value)
 {
-    Object *o = static_cast<Object *>(object.asManaged());
+    Object *o = object.as<Object>();
     if (o) {
         if (o->internalClass() == l->classList[0]) {
             o->memberData()->data[l->index] = value;
index 88397dc..ff20b52 100644 (file)
@@ -51,7 +51,7 @@ struct Lookup {
         void (*indexedSetter)(Lookup *l, const Value &object, const Value &index, const Value &v);
         ReturnedValue (*getter)(Lookup *l, ExecutionEngine *engine, const Value &object);
         ReturnedValue (*globalGetter)(Lookup *l, ExecutionEngine *engine);
-        void (*setter)(Lookup *l, ExecutionEngine *engine, const Value &object, const Value &v);
+        void (*setter)(Lookup *l, ExecutionEngine *engine, Value &object, const Value &v);
     };
     union {
         ExecutionEngine *engine;
@@ -107,14 +107,14 @@ struct Lookup {
     static ReturnedValue globalGetterAccessor1(Lookup *l, ExecutionEngine *engine);
     static ReturnedValue globalGetterAccessor2(Lookup *l, ExecutionEngine *engine);
 
-    static void setterGeneric(Lookup *l, ExecutionEngine *engine, const Value &object, const Value &value);
-    static void setterTwoClasses(Lookup *l, ExecutionEngine *engine, const Value &object, const Value &value);
-    static void setterFallback(Lookup *l, ExecutionEngine *engine, const Value &object, const Value &value);
-    static void setter0(Lookup *l, ExecutionEngine *engine, const Value &object, const Value &value);
-    static void setterInsert0(Lookup *l, ExecutionEngine *engine, const Value &object, const Value &value);
-    static void setterInsert1(Lookup *l, ExecutionEngine *engine, const Value &object, const Value &value);
-    static void setterInsert2(Lookup *l, ExecutionEngine *engine, const Value &object, const Value &value);
-    static void setter0setter0(Lookup *l, ExecutionEngine *engine, const Value &object, const Value &value);
+    static void setterGeneric(Lookup *l, ExecutionEngine *engine, Value &object, const Value &value);
+    static void setterTwoClasses(Lookup *l, ExecutionEngine *engine, Value &object, const Value &value);
+    static void setterFallback(Lookup *l, ExecutionEngine *engine, Value &object, const Value &value);
+    static void setter0(Lookup *l, ExecutionEngine *engine, Value &object, const Value &value);
+    static void setterInsert0(Lookup *l, ExecutionEngine *engine, Value &object, const Value &value);
+    static void setterInsert1(Lookup *l, ExecutionEngine *engine, Value &object, const Value &value);
+    static void setterInsert2(Lookup *l, ExecutionEngine *engine, Value &object, const Value &value);
+    static void setter0setter0(Lookup *l, ExecutionEngine *engine, Value &object, const Value &value);
 
     ReturnedValue lookup(const Value &thisObject, Object *obj, PropertyAttributes *attrs);
     ReturnedValue lookup(Object *obj, PropertyAttributes *attrs);
index 4b455cb..31e52df 100644 (file)
@@ -150,7 +150,6 @@ public:
     };
     Q_MANAGED_TYPE(Invalid)
 
-    String *asString() { return d()->vtable->isString ? reinterpret_cast<String *>(this) : 0; }
     Object *asObject() { return d()->vtable->isObject ? reinterpret_cast<Object *>(this) : 0; }
     FunctionObject *asFunctionObject() { return d()->vtable->isFunctionObject ? reinterpret_cast<FunctionObject *>(this) : 0; }
     BooleanObject *asBooleanObject() { return d()->vtable->type == Type_BooleanObject ? reinterpret_cast<BooleanObject *>(this) : 0; }
@@ -181,7 +180,9 @@ private:
 
 template<>
 inline const Managed *Value::as() const {
-    return asManaged();
+    if (isManaged())
+        return managed();
+    return 0;
 }
 
 template<typename T>
@@ -193,7 +194,7 @@ inline T *managed_cast(Managed *m)
 template<>
 inline String *managed_cast(Managed *m)
 {
-    return m ? m->asString() : 0;
+    return m ? m->as<String>() : 0;
 }
 template<>
 inline Object *managed_cast(Managed *m)
index 37f1360..ad26aa7 100644 (file)
@@ -356,7 +356,7 @@ bool Object::hasOwnProperty(uint index) const
         return true;
 
     if (isStringObject()) {
-        String *s = static_cast<const StringObject *>(this)->d()->value.asString();
+        String *s = static_cast<const StringObject *>(this)->d()->value.as<String>();
         if (index < (uint)s->d()->length())
             return true;
     }
@@ -416,7 +416,7 @@ PropertyAttributes Object::queryIndexed(const Managed *m, uint index)
         return o->arrayData()->attributes(index);
 
     if (o->isStringObject()) {
-        String *s = static_cast<const StringObject *>(o)->d()->value.asString();
+        String *s = static_cast<const StringObject *>(o)->d()->value.as<String>();
         if (index < (uint)s->d()->length())
             return (Attr_NotWritable|Attr_NotConfigurable);
     }
index 0889415..f7e88dd 100644 (file)
@@ -190,7 +190,7 @@ void PersistentValueStorage::mark(ExecutionEngine *e)
     Page *p = static_cast<Page *>(firstPage);
     while (p) {
         for (int i = 0; i < kEntriesPerPage; ++i) {
-            if (Managed *m = p->values[i].asManaged())
+            if (Managed *m = p->values[i].as<Managed>())
                 m->mark(e);
         }
         drainMarkStack(e, markBase);
index f8ddb93..2d2f856 100644 (file)
@@ -96,7 +96,7 @@ public:
     Managed *asManaged() const {
         if (!val)
             return 0;
-        return val->asManaged();
+        return val->as<Managed>();
     }
 
     ExecutionEngine *engine() const {
@@ -138,7 +138,7 @@ public:
     Managed *asManaged() const {
         if (!val)
             return 0;
-        return val->asManaged();
+        return val->as<Managed>();
     }
 
     ExecutionEngine *engine() const {
index 937104a..605f5c2 100644 (file)
@@ -576,7 +576,7 @@ ReturnedValue Runtime::getElement(ExecutionEngine *engine, const Value &object,
     ScopedObject o(scope, object);
     if (!o) {
         if (idx < UINT_MAX) {
-            if (String *str = object.asString()) {
+            if (const String *str = object.as<String>()) {
                 if (idx >= (uint)str->toQString().length()) {
                     return Encode::undefined();
                 }
index c907088..df0febc 100644 (file)
@@ -265,7 +265,7 @@ void Serialize::serialize(QByteArray &data, const QV4::Value &v, ExecutionEngine
             s = properties->getIndexed(ii);
             serialize(data, s, engine);
 
-            QV4::String *str = s->asString();
+            QV4::String *str = s->as<String>();
             val = o->get(str);
             if (scope.hasException())
                 scope.engine->catchException();
index 3d25d8a..ae5949d 100644 (file)
@@ -63,18 +63,11 @@ inline bool Value::isPrimitive() const
     return !isObject();
 }
 
-inline String *Value::asString() const
-{
-    if (isString())
-        return stringValue();
-    return 0;
-}
-
-inline void Value::mark(ExecutionEngine *e) const
+inline void Value::mark(ExecutionEngine *e)
 {
     if (!val)
         return;
-    Managed *m = asManaged();
+    Managed *m = as<Managed>();
     if (m)
         m->mark(e);
 }
index 035eaa8..bc97e1a 100644 (file)
@@ -304,8 +304,6 @@ struct Q_QML_PRIVATE_EXPORT Value
         return b;
     }
 
-    inline String *asString() const;
-    inline Managed *asManaged() const;
     inline Object *asObject() const;
     inline FunctionObject *asFunctionObject() const;
 
@@ -347,7 +345,7 @@ struct Q_QML_PRIVATE_EXPORT Value
     // Section 9.12
     bool sameValue(Value other) const;
 
-    inline void mark(ExecutionEngine *e) const;
+    inline void mark(ExecutionEngine *e);
 
     Value &operator =(const ScopedValue &v);
     Value &operator=(ReturnedValue v) { val = v; return *this; }
@@ -376,12 +374,6 @@ struct Q_QML_PRIVATE_EXPORT Value
     }
 };
 
-inline Managed *Value::asManaged() const
-{
-    if (isManaged())
-        return managed();
-    return 0;
-}
 
 struct Q_QML_PRIVATE_EXPORT Primitive : public Value
 {
index 07408a3..07e8b11 100644 (file)
@@ -381,7 +381,7 @@ void MemoryManager::sweep(bool lastSweep)
 {
     if (m_weakValues) {
         for (PersistentValueStorage::Iterator it = m_weakValues->begin(); it != m_weakValues->end(); ++it) {
-            if (Managed *m = (*it).asManaged()) {
+            if (Managed *m = (*it).as<Managed>()) {
                 if (!m->markBit())
                     (*it) = Primitive::undefinedValue();
             }
@@ -607,7 +607,7 @@ void MemoryManager::collectFromJSStack() const
     Value *v = m_d->engine->jsStackBase;
     Value *top = m_d->engine->jsStackTop;
     while (v < top) {
-        Managed *m = v->asManaged();
+        Managed *m = v->as<Managed>();
         if (m && m->inUse())
             // Skip pointers to already freed objects, they are bogus as well
             m->mark(m_d->engine);
index d479743..17aea74 100644 (file)
@@ -421,7 +421,7 @@ void ListModel::set(int elementIndex, QV4::Object *object, QVector<int> *roles)
         int roleIndex = -1;
 
         // Add the value now
-        if (QV4::String *s = propertyValue->asString()) {
+        if (const QV4::String *s = propertyValue->as<QV4::String>()) {
             const ListLayout::Role &r = m_layout->getRoleOrCreate(propertyName, ListLayout::Role::String);
             roleIndex = e->setStringProperty(r, s->toQString());
         } else if (propertyValue->isNumber()) {