Inline casting of Value to objects
authorLars Knoll <lars.knoll@digia.com>
Fri, 25 Jan 2013 12:23:58 +0000 (13:23 +0100)
committerSimon Hausmann <simon.hausmann@digia.com>
Fri, 25 Jan 2013 12:54:41 +0000 (13:54 +0100)
Change-Id: Ic5538b8a0a1f430a265399bced0ce9fc0a79696e
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
qmljs_value.cpp
qmljs_value.h
qv4managed.h

index 72f92a1..0e4e4f2 100644 (file)
@@ -153,51 +153,6 @@ double Value::toInteger(double number)
     return std::signbit(number) ? -v : v;
 }
 
-Object *Value::asObject() const
-{
-    return isObject() ? objectValue() : 0;
-}
-
-FunctionObject *Value::asFunctionObject() const
-{
-    return isObject() ? objectValue()->asFunctionObject() : 0;
-}
-
-BooleanObject *Value::asBooleanObject() const
-{
-    return isObject() ? objectValue()->asBooleanObject() : 0;
-}
-
-NumberObject *Value::asNumberObject() const
-{
-    return isObject() ? objectValue()->asNumberObject() : 0;
-}
-
-StringObject *Value::asStringObject() const
-{
-    return isObject() ? objectValue()->asStringObject() : 0;
-}
-
-DateObject *Value::asDateObject() const
-{
-    return isObject() ? objectValue()->asDateObject() : 0;
-}
-
-RegExpObject *Value::asRegExpObject() const
-{
-    return isObject() ? objectValue()->asRegExpObject() : 0;
-}
-
-ArrayObject *Value::asArrayObject() const
-{
-    return isObject() ? objectValue()->asArrayObject() : 0;
-}
-
-ErrorObject *Value::asErrorObject() const
-{
-    return isObject() ? objectValue()->asErrorObject() : 0;
-}
-
 Value Value::property(ExecutionContext *ctx, String *name) const
 {
     return isObject() ? objectValue()->__get__(ctx, name) : undefinedValue();
index 9e19788..b6124c0 100644 (file)
 #include <QtCore/qnumeric.h>
 #include <qv4string.h>
 #include <QtCore/QDebug>
+#include <qv4managed.h>
 
 namespace QQmlJS {
 namespace VM {
 
 struct String;
-struct Object;
-struct BooleanObject;
-struct NumberObject;
-struct StringObject;
-struct ArrayObject;
-struct DateObject;
-struct FunctionObject;
-struct RegExpObject;
-struct ErrorObject;
-struct ArgumentsObject;
 struct ExecutionContext;
 struct ExecutionEngine;
 struct Value;
@@ -87,6 +78,7 @@ struct Value
                 int int_32;
 #if CPU(X86_64)
 #else
+                Managed *m;
                 Object *o;
                 String *s;
 #endif
@@ -170,6 +162,9 @@ struct Value
     Object *objectValue() const {
         return (Object *)(val & ~(quint64(Type_Mask) << Tag_Shift));
     }
+    Managed *managed() const {
+        return (Managed *)(val & ~(quint64(Type_Mask) << Tag_Shift));
+    }
 #else
     String *stringValue() const {
         return s;
@@ -177,6 +172,9 @@ struct Value
     Object *objectValue() const {
         return o;
     }
+    Managed *managed() const {
+        return m;
+    }
 #endif
 
     quint64 rawValue() const {
@@ -417,6 +415,52 @@ inline uint Value::asArrayLength(ExecutionContext *ctx, bool *ok) const
 }
 
 
+inline Object *Value::asObject() const
+{
+    return isObject() ? objectValue() : 0;
+}
+
+inline FunctionObject *Value::asFunctionObject() const
+{
+    return isObject() ? managed()->asFunctionObject() : 0;
+}
+
+inline BooleanObject *Value::asBooleanObject() const
+{
+    return isObject() ? managed()->asBooleanObject() : 0;
+}
+
+inline NumberObject *Value::asNumberObject() const
+{
+    return isObject() ? managed()->asNumberObject() : 0;
+}
+
+inline StringObject *Value::asStringObject() const
+{
+    return isObject() ? managed()->asStringObject() : 0;
+}
+
+inline DateObject *Value::asDateObject() const
+{
+    return isObject() ? managed()->asDateObject() : 0;
+}
+
+inline RegExpObject *Value::asRegExpObject() const
+{
+    return isObject() ? managed()->asRegExpObject() : 0;
+}
+
+inline ArrayObject *Value::asArrayObject() const
+{
+    return isObject() ? managed()->asArrayObject() : 0;
+}
+
+inline ErrorObject *Value::asErrorObject() const
+{
+    return isObject() ? managed()->asErrorObject() : 0;
+}
+
+
 } // namespace VM
 } // namespace QQmlJS
 
index 8513228..ff1963d 100644 (file)
@@ -104,6 +104,7 @@ public:
         Type_ForeachIteratorObject
     };
 
+    Object *asObject() { return reinterpret_cast<Object *>(this); }
     ArrayObject *asArrayObject() { return type == Type_ArrayObject ? reinterpret_cast<ArrayObject *>(this) : 0; }
     FunctionObject *asFunctionObject() { return type == Type_FunctionObject ? reinterpret_cast<FunctionObject *>(this) : 0; }
     BooleanObject *asBooleanObject() { return type == Type_BooleanObject ? reinterpret_cast<BooleanObject *>(this) : 0; }