diff options
author | Lars Knoll <lars.knoll@digia.com> | 2013-09-14 15:08:11 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-09-18 13:14:16 +0200 |
commit | 43cdae853b726642893622d2feffcd0f4a2d6953 (patch) | |
tree | 9ad482429a7808ab720a720400eb14e149c113da /src/qml/jsruntime/qv4value.cpp | |
parent | f79df5da0769836bc866b470cdac43d6363dc7db (diff) |
Optimize some runtime methods
This prings performance up by ~25% again.
Change-Id: I680466e11b722b2eac0edda0fe4199b717d23855
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src/qml/jsruntime/qv4value.cpp')
-rw-r--r-- | src/qml/jsruntime/qv4value.cpp | 48 |
1 files changed, 5 insertions, 43 deletions
diff --git a/src/qml/jsruntime/qv4value.cpp b/src/qml/jsruntime/qv4value.cpp index 79bfae42e3..aa962687b2 100644 --- a/src/qml/jsruntime/qv4value.cpp +++ b/src/qml/jsruntime/qv4value.cpp @@ -48,41 +48,6 @@ using namespace QV4; -int Value::toInt32() const -{ - if (isConvertibleToInt()) - return int_32; - double d; - if (isDouble()) - d = dbl; - else - d = toNumber(); - - const double D32 = 4294967296.0; - const double D31 = D32 / 2.0; - - if ((d >= -D31 && d < D31)) - return static_cast<int>(d); - - return Value::toInt32(d); -} - -unsigned int Value::toUInt32() const -{ - if (isConvertibleToInt()) - return (unsigned) int_32; - double d; - if (isDouble()) - d = dbl; - else - d = toNumber(); - - const double D32 = 4294967296.0; - if (d >= 0 && d < D32) - return static_cast<uint>(d); - return toUInt32(d); -} - int Value::toUInt16() const { if (isConvertibleToInt()) @@ -117,17 +82,11 @@ double Value::toInteger() const return Value::toInteger(toNumber()); } -double Value::toNumber() const +double Value::toNumberImpl() const { switch (type()) { case QV4::Value::Undefined_Type: return std::numeric_limits<double>::quiet_NaN(); - case QV4::Value::Null_Type: - return 0; - case QV4::Value::Boolean_Type: - return (booleanValue() ? 1. : 0.); - case QV4::Value::Integer_Type: - return int_32; case QV4::Value::String_Type: return __qmljs_string_to_number(stringValue()->toQString()); case QV4::Value::Object_Type: { @@ -136,8 +95,11 @@ double Value::toNumber() const ScopedValue prim(scope, __qmljs_to_primitive(ValueRef::fromRawValue(this), NUMBER_HINT)); return prim->toNumber(); } + case QV4::Value::Null_Type: + case QV4::Value::Boolean_Type: + case QV4::Value::Integer_Type: default: // double - return doubleValue(); + Q_UNREACHABLE(); } } |