From cd33d38ce0067719b0215264a22685a91b2e08dc Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 18 Feb 2010 18:27:45 +0100 Subject: Port QtCore uses of QTime as a stopwatch to QTimestamp. tst_qtimeline improvement: from 56187446 to 53915928 (callgrind) --- src/corelib/animation/qabstractanimation.cpp | 1 + src/corelib/animation/qabstractanimation_p.h | 57 +--------------------------- src/corelib/io/qprocess.cpp | 6 +-- src/corelib/io/qprocess_unix.cpp | 8 ++-- src/corelib/kernel/qcoreapplication.cpp | 4 +- src/corelib/tools/qtimeline.cpp | 4 +- 6 files changed, 14 insertions(+), 66 deletions(-) diff --git a/src/corelib/animation/qabstractanimation.cpp b/src/corelib/animation/qabstractanimation.cpp index f834a80..82b3003 100644 --- a/src/corelib/animation/qabstractanimation.cpp +++ b/src/corelib/animation/qabstractanimation.cpp @@ -170,6 +170,7 @@ QUnifiedTimer::QUnifiedTimer() : currentAnimationIdx(0), consistentTiming(false), slowMode(false), isPauseTimerActive(false), runningLeafAnimations(0) { + time.invalidate(); } QUnifiedTimer *QUnifiedTimer::instance() diff --git a/src/corelib/animation/qabstractanimation_p.h b/src/corelib/animation/qabstractanimation_p.h index 8bc3224..3eb4948 100644 --- a/src/corelib/animation/qabstractanimation_p.h +++ b/src/corelib/animation/qabstractanimation_p.h @@ -56,6 +56,7 @@ #include #include #include +#include #include #ifdef Q_OS_WIN @@ -113,61 +114,7 @@ private: Q_DECLARE_PUBLIC(QAbstractAnimation) }; -class ElapsedTimer -{ -public: - ElapsedTimer() { - invalidate(); - } - - void invalidate() { - m_started = -1; - } - - bool isValid() const { - return m_started >= 0; - } - - void start() { - m_started = getTickCount_sys(); - } - - qint64 elapsed() const { - qint64 current = getTickCount_sys(); - qint64 delta = current - m_started; - if (delta < 0) - delta += getPeriod_sys(); //we wrapped around - return delta; - } - -private: - enum { - MSECS_PER_HOUR = 3600000, - MSECS_PER_MIN = 60000 - }; - - qint64 m_started; - - quint64 getPeriod_sys() const { -#ifdef Q_OS_WIN - return Q_UINT64_C(0x100000000); -#else - // fallback - return 86400 * 1000; -#endif - } - - qint64 getTickCount_sys() const { -#ifdef Q_OS_WIN - return ::GetTickCount(); -#else - // fallback - const QTime t = QTime::currentTime(); - return MSECS_PER_HOUR * t.hour() + MSECS_PER_MIN * t.minute() + 1000 * t.second() + t.msec(); -#endif - } -}; - +typedef QTimestamp ElapsedTimer; class QUnifiedTimer : public QObject { diff --git a/src/corelib/io/qprocess.cpp b/src/corelib/io/qprocess.cpp index 12a992a..6250094 100644 --- a/src/corelib/io/qprocess.cpp +++ b/src/corelib/io/qprocess.cpp @@ -88,7 +88,7 @@ QT_END_NAMESPACE #include "qprocess_p.h" #include -#include +#include #include #include #include @@ -1639,7 +1639,7 @@ bool QProcess::waitForBytesWritten(int msecs) if (d->processState == QProcess::NotRunning) return false; if (d->processState == QProcess::Starting) { - QTime stopWatch; + QTimestamp stopWatch; stopWatch.start(); bool started = waitForStarted(msecs); if (!started) @@ -1676,7 +1676,7 @@ bool QProcess::waitForFinished(int msecs) if (d->processState == QProcess::NotRunning) return false; if (d->processState == QProcess::Starting) { - QTime stopWatch; + QTimestamp stopWatch; stopWatch.start(); bool started = waitForStarted(msecs); if (!started) diff --git a/src/corelib/io/qprocess_unix.cpp b/src/corelib/io/qprocess_unix.cpp index 5119ec0..511154a 100644 --- a/src/corelib/io/qprocess_unix.cpp +++ b/src/corelib/io/qprocess_unix.cpp @@ -92,7 +92,6 @@ QT_END_NAMESPACE #include #include -#include #include #include #include @@ -101,6 +100,7 @@ QT_END_NAMESPACE #include #include #include +#include #include #include @@ -933,7 +933,7 @@ bool QProcessPrivate::waitForReadyRead(int msecs) qDebug("QProcessPrivate::waitForReadyRead(%d)", msecs); #endif - QTime stopWatch; + QTimestamp stopWatch; stopWatch.start(); forever { @@ -1005,7 +1005,7 @@ bool QProcessPrivate::waitForBytesWritten(int msecs) qDebug("QProcessPrivate::waitForBytesWritten(%d)", msecs); #endif - QTime stopWatch; + QTimestamp stopWatch; stopWatch.start(); while (!writeBuffer.isEmpty()) { @@ -1072,7 +1072,7 @@ bool QProcessPrivate::waitForFinished(int msecs) qDebug("QProcessPrivate::waitForFinished(%d)", msecs); #endif - QTime stopWatch; + QTimestamp stopWatch; stopWatch.start(); forever { diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp index 2da5a7d..3d6364b 100644 --- a/src/corelib/kernel/qcoreapplication.cpp +++ b/src/corelib/kernel/qcoreapplication.cpp @@ -47,7 +47,6 @@ #include "qeventloop.h" #include "qcorecmdlineargs_p.h" #include -#include #include #include #include @@ -59,6 +58,7 @@ #include #include #include +#include #include #include #include @@ -917,7 +917,7 @@ void QCoreApplication::processEvents(QEventLoop::ProcessEventsFlags flags, int m QThreadData *data = QThreadData::current(); if (!data->eventDispatcher) return; - QTime start; + QTimestamp start; start.start(); if (flags & QEventLoop::DeferredDeletion) QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete); diff --git a/src/corelib/tools/qtimeline.cpp b/src/corelib/tools/qtimeline.cpp index 877a77a..57977bc 100644 --- a/src/corelib/tools/qtimeline.cpp +++ b/src/corelib/tools/qtimeline.cpp @@ -42,9 +42,9 @@ #include "qtimeline.h" #include -#include #include #include +#include QT_BEGIN_NAMESPACE @@ -70,7 +70,7 @@ public: int currentTime; int timerId; - QTime timer; + QTimestamp timer; QTimeLine::Direction direction; QEasingCurve easingCurve; -- cgit v0.12