diff options
author | Lars Knoll <[email protected]> | 2014-02-07 09:46:02 +0100 |
---|---|---|
committer | The Qt Project <[email protected]> | 2014-02-22 10:11:06 +0100 |
commit | b8bb8d752639d0907922bdd4e4a944534a0a6770 (patch) | |
tree | def6913e3ffbf43176b0426ae31f8351c2b98579 /src/qml/jsruntime/qv4runtime_p.h | |
parent | 109889428edc5e4cf25c9fdd11a5e006e8a08630 (diff) |
Simplify some runtime code
Simpler code and delivers the same performance.
Change-Id: Ifd0398f0c123f4c21998f518574cf74cd7cf7e09
Reviewed-by: Simon Hausmann <[email protected]>
Diffstat (limited to 'src/qml/jsruntime/qv4runtime_p.h')
-rw-r--r-- | src/qml/jsruntime/qv4runtime_p.h | 44 |
1 files changed, 17 insertions, 27 deletions
diff --git a/src/qml/jsruntime/qv4runtime_p.h b/src/qml/jsruntime/qv4runtime_p.h index 3c2824ee23..1c34e554c3 100644 --- a/src/qml/jsruntime/qv4runtime_p.h +++ b/src/qml/jsruntime/qv4runtime_p.h @@ -350,11 +350,10 @@ inline QV4::ReturnedValue __qmljs_add(QV4::ExecutionContext *ctx, const QV4::Val { TRACE2(left, right); - if (QV4::Value::integerCompatible(*left, *right)) + if (left->isInteger() && right->isInteger()) return add_int32(left->integerValue(), right->integerValue()).asReturnedValue(); - - if (QV4::Value::bothDouble(*left, *right)) - return QV4::Primitive::fromDouble(left->doubleValue() + right->doubleValue()).asReturnedValue(); + if (left->isNumber() && right->isNumber()) + return QV4::Primitive::fromDouble(left->asDouble() + right->asDouble()).asReturnedValue(); return __qmljs_add_helper(ctx, left, right); } @@ -363,11 +362,12 @@ inline QV4::ReturnedValue __qmljs_sub(const QV4::ValueRef left, const QV4::Value { TRACE2(left, right); - if (QV4::Value::integerCompatible(*left, *right)) + if (left->isInteger() && right->isInteger()) return sub_int32(left->integerValue(), right->integerValue()).asReturnedValue(); - double lval = __qmljs_to_number(left); - double rval = __qmljs_to_number(right); + double lval = left->isNumber() ? left->asDouble() : left->toNumberImpl(); + double rval = right->isNumber() ? right->asDouble() : right->toNumberImpl(); + return QV4::Primitive::fromDouble(lval - rval).asReturnedValue(); } @@ -375,11 +375,12 @@ inline QV4::ReturnedValue __qmljs_mul(const QV4::ValueRef left, const QV4::Value { TRACE2(left, right); - if (QV4::Value::integerCompatible(*left, *right)) + if (left->isInteger() && right->isInteger()) return mul_int32(left->integerValue(), right->integerValue()).asReturnedValue(); - double lval = __qmljs_to_number(left); - double rval = __qmljs_to_number(right); + double lval = left->isNumber() ? left->asDouble() : left->toNumberImpl(); + double rval = right->isNumber() ? right->asDouble() : right->toNumberImpl(); + return QV4::Primitive::fromDouble(lval * rval).asReturnedValue(); } @@ -387,8 +388,8 @@ inline QV4::ReturnedValue __qmljs_div(const QV4::ValueRef left, const QV4::Value { TRACE2(left, right); - double lval = __qmljs_to_number(left); - double rval = __qmljs_to_number(right); + double lval = left->toNumber(); + double rval = right->toNumber(); return QV4::Primitive::fromDouble(lval / rval).asReturnedValue(); } @@ -411,11 +412,8 @@ inline QV4::ReturnedValue __qmljs_shl(const QV4::ValueRef left, const QV4::Value { TRACE2(left, right); - if (QV4::Value::integerCompatible(*left, *right)) - return Encode((int)(left->integerValue() << ((uint(right->integerValue()) & 0x1f)))); - int lval = left->toInt32(); - unsigned rval = right->toUInt32() & 0x1f; + int rval = right->toInt32() & 0x1f; return Encode((int)(lval << rval)); } @@ -423,9 +421,6 @@ inline QV4::ReturnedValue __qmljs_shr(const QV4::ValueRef left, const QV4::Value { TRACE2(left, right); - if (QV4::Value::integerCompatible(*left, *right)) - return Encode((int)(left->integerValue() >> ((uint(right->integerValue()) & 0x1f)))); - int lval = left->toInt32(); unsigned rval = right->toUInt32() & 0x1f; return Encode((int)(lval >> rval)); @@ -435,14 +430,9 @@ inline QV4::ReturnedValue __qmljs_ushr(const QV4::ValueRef left, const QV4::Valu { TRACE2(left, right); - uint res; - if (QV4::Value::integerCompatible(*left, *right)) { - res = uint(left->integerValue()) >> (uint(right->integerValue()) & 0x1f); - } else { - unsigned lval = left->toUInt32(); - unsigned rval = right->toUInt32() & 0x1f; - res = lval >> rval; - } + unsigned lval = left->toUInt32(); + unsigned rval = right->toUInt32() & 0x1f; + uint res = lval >> rval; return Encode(res); } |