aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime/qv4value_p.h
diff options
context:
space:
mode:
authorErik Verbruggen <erik.verbruggen@qt.io>2018-07-06 14:36:11 +0200
committerErik Verbruggen <erik.verbruggen@qt.io>2018-07-13 10:20:07 +0000
commit8fdfd9ff5ded388a3d29c917aebb795485abfbfd (patch)
treee9b614f90adbd7943a4c6190e8e1ba39cec37d40 /src/qml/jsruntime/qv4value_p.h
parenteab3371b91a2a752a123c4995d977a36ff952168 (diff)
JS: Encode result of Math.min and Math.max as int when possible
So now Math.max(array1.length, array2.length) won't return a double anymore. This improves the score in the crypto benchmark by ~10% Change-Id: I8453a671d28d7f2a39ba74b18b3155f031d9b12f Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/jsruntime/qv4value_p.h')
-rw-r--r--src/qml/jsruntime/qv4value_p.h11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/qml/jsruntime/qv4value_p.h b/src/qml/jsruntime/qv4value_p.h
index 7c9ca9c0bf..6a6df3eb6d 100644
--- a/src/qml/jsruntime/qv4value_p.h
+++ b/src/qml/jsruntime/qv4value_p.h
@@ -334,14 +334,17 @@ public:
return true;
if (isDouble()) {
double d = doubleValue();
- int i = (int)d;
- if (i == d && !(d == 0 && std::signbit(d))) {
- setInt_32(i);
+ if (isInt32(d)) {
+ setInt_32(int(d));
return true;
}
}
return false;
}
+ QML_NEARLY_ALWAYS_INLINE static bool isInt32(double d) {
+ int i = int(d);
+ return (i == d && !(d == 0 && std::signbit(d)));
+ }
double asDouble() const {
if (tag() == quint32(ValueTypeInternal::Integer))
return int_32();
@@ -733,7 +736,7 @@ struct Encode {
}
static ReturnedValue smallestNumber(double d) {
- if (static_cast<int>(d) == d && !(d == 0. && std::signbit(d)))
+ if (Value::isInt32(d))
return Encode(static_cast<int>(d));
else
return Encode(d);