summaryrefslogtreecommitdiffstats
path: root/src/declarative/util
diff options
context:
space:
mode:
authormread <qt-info@nokia.com>2011-10-05 15:40:26 (GMT)
committermread <qt-info@nokia.com>2011-10-05 15:51:27 (GMT)
commit6e1b00087902866cd4c0e3057690d045356869f0 (patch)
tree7e3a0f471235923c9b22a6fbd3e0a84c33af0a9d /src/declarative/util
parent2a6298bcf29104a4258992c7357a031f4ca9cc7f (diff)
downloadQt-6e1b00087902866cd4c0e3057690d045356869f0.zip
Qt-6e1b00087902866cd4c0e3057690d045356869f0.tar.gz
Qt-6e1b00087902866cd4c0e3057690d045356869f0.tar.bz2
Converting accidental use of doubles to qreal in declarative
Declarative had a number of places where double operations were used instead of qreal, due to the use of double literals. These are now constructed as qreal literals so that qreal operations are used. This makes no difference where qreal is double. But on Symbian, qreal is float, and this give a performance boost for floating point intensive code. Task-number: QTBUG-4894 Reviewed-by: Martin Jones
Diffstat (limited to 'src/declarative/util')
-rw-r--r--src/declarative/util/qdeclarativeanimation.cpp2
-rw-r--r--src/declarative/util/qdeclarativesmoothedanimation.cpp42
-rw-r--r--src/declarative/util/qdeclarativespringanimation.cpp8
-rw-r--r--src/declarative/util/qdeclarativestateoperations.cpp2
-rw-r--r--src/declarative/util/qdeclarativexmllistmodel.cpp2
5 files changed, 28 insertions, 28 deletions
diff --git a/src/declarative/util/qdeclarativeanimation.cpp b/src/declarative/util/qdeclarativeanimation.cpp
index ce21bcd..455c4f6 100644
--- a/src/declarative/util/qdeclarativeanimation.cpp
+++ b/src/declarative/util/qdeclarativeanimation.cpp
@@ -2719,7 +2719,7 @@ void QDeclarativeParentAnimation::transition(QDeclarativeStateActions &actions,
}
if (scale != 0)
- rotation = atan2(transform.m12()/scale, transform.m11()/scale) * 180/M_PI;
+ rotation = atan2(transform.m12()/scale, transform.m11()/scale) * 180/qreal(M_PI);
else {
qmlInfo(this) << QDeclarativeParentAnimation::tr("Unable to preserve appearance under scale of 0");
ok = false;
diff --git a/src/declarative/util/qdeclarativesmoothedanimation.cpp b/src/declarative/util/qdeclarativesmoothedanimation.cpp
index b77db89..e905d0a 100644
--- a/src/declarative/util/qdeclarativesmoothedanimation.cpp
+++ b/src/declarative/util/qdeclarativesmoothedanimation.cpp
@@ -51,7 +51,7 @@
#include <QtCore/qdebug.h>
-#include <math.h>
+#include <QtCore/qmath.h>
#define DELAY_STOP_TIMER_INTERVAL 32
@@ -98,20 +98,20 @@ bool QSmoothedAnimation::recalc()
s = to - initialValue;
vi = initialVelocity;
- s = (invert? -1.0: 1.0) * s;
+ s = (invert? qreal(-1.0): qreal(1.0)) * s;
if (userDuration > 0 && velocity > 0) {
tf = s / velocity;
- if (tf > (userDuration / 1000.)) tf = (userDuration / 1000.);
+ if (tf > (userDuration / qreal(1000.))) tf = (userDuration / qreal(1000.));
} else if (userDuration > 0) {
- tf = userDuration / 1000.;
+ tf = userDuration / qreal(1000.);
} else if (velocity > 0) {
tf = s / velocity;
} else {
return false;
}
- finalDuration = ceil(tf * 1000.0);
+ finalDuration = ceil(tf * qreal(1000.0));
if (maximumEasingTime == 0) {
a = 0;
@@ -121,33 +121,33 @@ bool QSmoothedAnimation::recalc()
vp = velocity;
sp = 0;
sd = s;
- } else if (maximumEasingTime != -1 && tf > (maximumEasingTime / 1000.)) {
- qreal met = maximumEasingTime / 1000.;
+ } else if (maximumEasingTime != -1 && tf > (maximumEasingTime / qreal(1000.))) {
+ qreal met = maximumEasingTime / qreal(1000.);
td = tf - met;
qreal c1 = td;
qreal c2 = (tf - td) * vi - tf * velocity;
- qreal c3 = -0.5 * (tf - td) * vi * vi;
+ qreal c3 = qreal(-0.5) * (tf - td) * vi * vi;
- qreal vp1 = (-c2 + sqrt(c2 * c2 - 4 * c1 * c3)) / (2. * c1);
+ qreal vp1 = (-c2 + qSqrt(c2 * c2 - 4 * c1 * c3)) / (qreal(2.) * c1);
vp = vp1;
a = vp / met;
d = a;
tp = (vp - vi) / a;
- sp = vi * tp + 0.5 * a * tp * tp;
+ sp = vi * tp + qreal(0.5) * a * tp * tp;
sd = sp + (td - tp) * vp;
} else {
- qreal c1 = 0.25 * tf * tf;
- qreal c2 = 0.5 * vi * tf - s;
- qreal c3 = -0.25 * vi * vi;
+ qreal c1 = qreal(0.25) * tf * tf;
+ qreal c2 = qreal(0.5) * vi * tf - s;
+ qreal c3 = qreal(-0.25) * vi * vi;
- qreal a1 = (-c2 + sqrt(c2 * c2 - 4 * c1 * c3)) / (2. * c1);
+ qreal a1 = (-c2 + qSqrt(c2 * c2 - 4 * c1 * c3)) / (qreal(2.) * c1);
- qreal tp1 = 0.5 * tf - 0.5 * vi / a1;
+ qreal tp1 = qreal(0.5) * tf - qreal(0.5) * vi / a1;
qreal vp1 = a1 * tp1 + vi;
- qreal sp1 = 0.5 * a1 * tp1 * tp1 + vi * tp1;
+ qreal sp1 = qreal(0.5) * a1 * tp1 * tp1 + vi * tp1;
a = a1;
d = a1;
@@ -165,7 +165,7 @@ qreal QSmoothedAnimation::easeFollow(qreal time_seconds)
qreal value;
if (time_seconds < tp) {
trackVelocity = vi + time_seconds * a;
- value = 0.5 * a * time_seconds * time_seconds + vi * time_seconds;
+ value = qreal(0.5) * a * time_seconds * time_seconds + vi * time_seconds;
} else if (time_seconds < td) {
time_seconds -= tp;
trackVelocity = vp;
@@ -173,7 +173,7 @@ qreal QSmoothedAnimation::easeFollow(qreal time_seconds)
} else if (time_seconds < tf) {
time_seconds -= td;
trackVelocity = vp - time_seconds * a;
- value = sd - 0.5 * d * time_seconds * time_seconds + vp * time_seconds;
+ value = sd - qreal(0.5) * d * time_seconds * time_seconds + vp * time_seconds;
} else {
trackVelocity = 0;
value = s;
@@ -186,10 +186,10 @@ qreal QSmoothedAnimation::easeFollow(qreal time_seconds)
void QSmoothedAnimation::updateCurrentTime(int t)
{
- qreal time_seconds = qreal(t - lastTime) / 1000.;
+ qreal time_seconds = qreal(t - lastTime) / qreal(1000.);
qreal value = easeFollow(time_seconds);
- value *= (invert? -1.0: 1.0);
+ value *= (invert? qreal(-1.0): qreal(1.0));
QDeclarativePropertyPrivate::write(target, initialValue + value,
QDeclarativePropertyPrivate::BypassInterceptor
| QDeclarativePropertyPrivate::DontRemoveBinding);
@@ -213,7 +213,7 @@ void QSmoothedAnimation::init()
return;
}
- bool hasReversed = trackVelocity != 0. &&
+ bool hasReversed = trackVelocity != qreal(0.) &&
((!invert) == ((initialValue - to) > 0));
if (hasReversed) {
diff --git a/src/declarative/util/qdeclarativespringanimation.cpp b/src/declarative/util/qdeclarativespringanimation.cpp
index 2c6058c..0b453ee 100644
--- a/src/declarative/util/qdeclarativespringanimation.cpp
+++ b/src/declarative/util/qdeclarativespringanimation.cpp
@@ -161,17 +161,17 @@ bool QDeclarativeSpringAnimationPrivate::animate(const QDeclarativeProperty &pro
animation.velocity = animation.velocity + (spring * diff - damping * animation.velocity) / mass;
else
animation.velocity = animation.velocity + spring * diff - damping * animation.velocity;
- if (maxVelocity > 0.) {
+ if (maxVelocity > qreal(0.)) {
// limit velocity
if (animation.velocity > maxVelocity)
animation.velocity = maxVelocity;
else if (animation.velocity < -maxVelocity)
animation.velocity = -maxVelocity;
}
- animation.currentValue += animation.velocity * 16.0 / 1000.0;
+ animation.currentValue += animation.velocity * qreal(16.0) / qreal(1000.0);
if (haveModulus) {
animation.currentValue = fmod(animation.currentValue, modulus);
- if (animation.currentValue < 0.0)
+ if (animation.currentValue < qreal(0.0))
animation.currentValue += modulus;
}
}
@@ -195,7 +195,7 @@ bool QDeclarativeSpringAnimationPrivate::animate(const QDeclarativeProperty &pro
animation.currentValue = fmod(animation.currentValue, modulus);
} else {
animation.currentValue -= moveBy;
- if (haveModulus && animation.currentValue < 0.0)
+ if (haveModulus && animation.currentValue < qreal(0.0))
animation.currentValue = fmod(animation.currentValue, modulus) + modulus;
}
if (lastTime - animation.start >= animation.duration) {
diff --git a/src/declarative/util/qdeclarativestateoperations.cpp b/src/declarative/util/qdeclarativestateoperations.cpp
index c260684..8f613b0 100644
--- a/src/declarative/util/qdeclarativestateoperations.cpp
+++ b/src/declarative/util/qdeclarativestateoperations.cpp
@@ -123,7 +123,7 @@ void QDeclarativeParentChangePrivate::doChange(QDeclarativeItem *targetParent, Q
}
if (scale != 0)
- rotation = atan2(transform.m12()/scale, transform.m11()/scale) * 180/M_PI;
+ rotation = atan2(transform.m12()/scale, transform.m11()/scale) * 180/qreal(M_PI);
else {
qmlInfo(q) << QDeclarativeParentChange::tr("Unable to preserve appearance under scale of 0");
ok = false;
diff --git a/src/declarative/util/qdeclarativexmllistmodel.cpp b/src/declarative/util/qdeclarativexmllistmodel.cpp
index 658dcad..980568e 100644
--- a/src/declarative/util/qdeclarativexmllistmodel.cpp
+++ b/src/declarative/util/qdeclarativexmllistmodel.cpp
@@ -530,7 +530,7 @@ public:
void notifyQueryStarted(bool remoteSource) {
Q_Q(QDeclarativeXmlListModel);
- progress = remoteSource ? 0.0 : 1.0;
+ progress = remoteSource ? qreal(0.0) : qreal(1.0);
status = QDeclarativeXmlListModel::Loading;
errorString.clear();
emit q->progressChanged(progress);