diff options
author | Lars Knoll <lars.knoll@digia.com> | 2012-12-13 14:48:20 +0100 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@digia.com> | 2012-12-13 16:16:50 +0100 |
commit | 48b825007fe45d84cea1ae6f526103ccedef87c3 (patch) | |
tree | 9865659d685bf20d5d3a3e09d6683f96362a89b5 /qmljs_value.h | |
parent | c498ddfbb6f6207ef2943929720c00a4f9c108f8 (diff) |
inline some code in toInt32 and toUInt32
Speeds up crypto.js by ~5%
Change-Id: I707bd6e7dc0f13b70889955e1b90f0c436db1848
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'qmljs_value.h')
-rw-r--r-- | qmljs_value.h | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/qmljs_value.h b/qmljs_value.h index 7f095caf87..9446c79dc3 100644 --- a/qmljs_value.h +++ b/qmljs_value.h @@ -64,6 +64,11 @@ struct ErrorObject; struct ArgumentsObject; struct ExecutionContext; struct ExecutionEngine; +struct Value; + +extern "C" { +double __qmljs_to_number(Value value, ExecutionContext *ctx); +} typedef uint Bool; @@ -197,6 +202,7 @@ struct Value int toUInt16(ExecutionContext *ctx); int toInt32(ExecutionContext *ctx); unsigned int toUInt32(ExecutionContext *ctx); + Bool toBoolean(ExecutionContext *ctx) const; double toInteger(ExecutionContext *ctx) const; double toNumber(ExecutionContext *ctx) const; @@ -324,6 +330,40 @@ inline Value Value::fromObject(Object *o) return v; } +inline int Value::toInt32(ExecutionContext *ctx) +{ + if (isConvertibleToInt()) + return int_32; + double d; + if (isDouble()) + d = dbl; + else + d = __qmljs_to_number(*this, ctx); + + const double D32 = 4294967296.0; + const double D31 = D32 / 2.0; + + if ((d >= -D31 && d < D31)) + return static_cast<int>(d); + + return Value::toInt32(__qmljs_to_number(*this, ctx)); +} + +inline unsigned int Value::toUInt32(ExecutionContext *ctx) { + if (isConvertibleToInt()) + return (unsigned) int_32; + double d; + if (isDouble()) + d = dbl; + else + d = __qmljs_to_number(*this, ctx); + + const double D32 = 4294967296.0; + if (dbl >= 0 && dbl < D32) + return static_cast<uint>(dbl); + return toUInt32(d); +} + } // namespace VM } // namespace QQmlJS |