From: Lars Knoll Date: Fri, 25 Jan 2013 12:23:58 +0000 (+0100) Subject: Inline casting of Value to objects X-Git-Tag: upstream/5.2.1~669^2~659^2~379 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e813c253f350bad7a1ad16ddd2d7e6601830609d;p=platform%2Fupstream%2Fqtdeclarative.git Inline casting of Value to objects Change-Id: Ic5538b8a0a1f430a265399bced0ce9fc0a79696e Reviewed-by: Simon Hausmann --- diff --git a/qmljs_value.cpp b/qmljs_value.cpp index 72f92a1..0e4e4f2 100644 --- a/qmljs_value.cpp +++ b/qmljs_value.cpp @@ -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(); diff --git a/qmljs_value.h b/qmljs_value.h index 9e19788..b6124c0 100644 --- a/qmljs_value.h +++ b/qmljs_value.h @@ -47,21 +47,12 @@ #include #include #include +#include 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 diff --git a/qv4managed.h b/qv4managed.h index 8513228..ff1963d 100644 --- a/qv4managed.h +++ b/qv4managed.h @@ -104,6 +104,7 @@ public: Type_ForeachIteratorObject }; + Object *asObject() { return reinterpret_cast(this); } ArrayObject *asArrayObject() { return type == Type_ArrayObject ? reinterpret_cast(this) : 0; } FunctionObject *asFunctionObject() { return type == Type_FunctionObject ? reinterpret_cast(this) : 0; } BooleanObject *asBooleanObject() { return type == Type_BooleanObject ? reinterpret_cast(this) : 0; }