Convert some QDateTime::currentDateTime() to currentDateTimeUtc() (I)

The latter is much faster as it doesn't have to deal with
time zones.

This change handles the trivial ones: Either the call to
currentDateTime() is immediately followed by a call to toUTC()
or toTime_t(). The latter is much faster on UTC QDateTimes, too.

Credits to Milian Wolff, from whose QtWS15 talk this advice is
taken.

Change-Id: I872f5bbb26cbecedc1e5c0dbee4d5ac2c6eb67ee
Reviewed-by: Milian Wolff <milian.wolff@kdab.com>
This commit is contained in:
Marc Mutz 2015-10-23 16:32:59 +02:00
parent 8a8a5813a9
commit 2cdafb0999
4 changed files with 5 additions and 5 deletions

View File

@ -963,7 +963,7 @@ QUuid QUuid::createUuid()
{ {
int *pseed = new int; int *pseed = new int;
static QBasicAtomicInt serial = Q_BASIC_ATOMIC_INITIALIZER(2); static QBasicAtomicInt serial = Q_BASIC_ATOMIC_INITIALIZER(2);
qsrand(*pseed = QDateTime::currentDateTime().toTime_t() qsrand(*pseed = QDateTime::currentDateTimeUtc().toTime_t()
+ quintptr(&pseed) + quintptr(&pseed)
+ serial.fetchAndAddRelaxed(1)); + serial.fetchAndAddRelaxed(1));
uuidseed.setLocalData(pseed); uuidseed.setLocalData(pseed);
@ -971,7 +971,7 @@ QUuid QUuid::createUuid()
#else #else
static bool seeded = false; static bool seeded = false;
if (!seeded) if (!seeded)
qsrand(QDateTime::currentDateTime().toTime_t() qsrand(QDateTime::currentDateTimeUtc().toTime_t()
+ quintptr(&seeded)); + quintptr(&seeded));
#endif #endif

View File

@ -1498,7 +1498,7 @@ void QPdfEnginePrivate::writeInfo()
printString(creator); printString(creator);
xprintf("\n/Producer "); xprintf("\n/Producer ");
printString(QString::fromLatin1("Qt " QT_VERSION_STR)); printString(QString::fromLatin1("Qt " QT_VERSION_STR));
QDateTime now = QDateTime::currentDateTime().toUTC(); QDateTime now = QDateTime::currentDateTimeUtc();
QTime t = now.time(); QTime t = now.time();
QDate d = now.date(); QDate d = now.date();
xprintf("\n/CreationDate (D:%d%02d%02d%02d%02d%02d)\n", xprintf("\n/CreationDate (D:%d%02d%02d%02d%02d%02d)\n",

View File

@ -901,7 +901,7 @@ QList<QNetworkCookie> QNetworkCookiePrivate::parseSetCookieHeaderLine(const QByt
// We do not support RFC 2965 Set-Cookie2-style cookies // We do not support RFC 2965 Set-Cookie2-style cookies
QList<QNetworkCookie> result; QList<QNetworkCookie> result;
QDateTime now = QDateTime::currentDateTime().toUTC(); const QDateTime now = QDateTime::currentDateTimeUtc();
int position = 0; int position = 0;
const int length = cookieString.length(); const int length = cookieString.length();

View File

@ -279,7 +279,7 @@ quint64 QNetworkSessionPrivateImpl::bytesReceived() const
quint64 QNetworkSessionPrivateImpl::activeTime() const quint64 QNetworkSessionPrivateImpl::activeTime() const
{ {
if (state == QNetworkSession::Connected && startTime != Q_UINT64_C(0)) if (state == QNetworkSession::Connected && startTime != Q_UINT64_C(0))
return QDateTime::currentDateTime().toTime_t() - startTime; return QDateTime::currentDateTimeUtc().toTime_t() - startTime;
return Q_UINT64_C(0); return Q_UINT64_C(0);
} }