From f8eeabcf5ca4615fcb3ed783dbd321f4998a7651 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 23 Oct 2015 16:32:59 +0200 Subject: [PATCH] QNetworkReplyHttpImpl: convert some QDateTime::currentDateTime() to currentDateTimeUtc() The latter is much faster as it doesn't have to deal with time zones. This change is safe, because the QDateTime is only used to compare against a copy of itself, adjusted by some seconds, which doen't care which TZ the date-time is in, to get a time_t, which is much faster done from a UTC time, and to calculate the seconds to expirationTime, which, from a quick glance around, seem to be mostly, if not exclusively, in UTC. secsTo() works across time zones, but the comparison between UTC date-times is fastest. Credits to Milian Wolff, from whose QtWS15 talk this advice is taken. Change-Id: I22aa5350b29493f01fb503ef5ec68a964ca95cf3 Reviewed-by: Lars Knoll --- src/network/access/qnetworkreplyhttpimpl.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/network/access/qnetworkreplyhttpimpl.cpp b/src/network/access/qnetworkreplyhttpimpl.cpp index 63fca2bda2c..c29b1322176 100644 --- a/src/network/access/qnetworkreplyhttpimpl.cpp +++ b/src/network/access/qnetworkreplyhttpimpl.cpp @@ -512,7 +512,7 @@ bool QNetworkReplyHttpImplPrivate::loadFromCacheIfAllowed(QHttpNetworkRequest &h return false; } - QDateTime currentDateTime = QDateTime::currentDateTime(); + QDateTime currentDateTime = QDateTime::currentDateTimeUtc(); QDateTime expirationDate = metaData.expirationDate(); bool response_is_fresh; @@ -545,7 +545,7 @@ bool QNetworkReplyHttpImplPrivate::loadFromCacheIfAllowed(QHttpNetworkRequest &h date_value = dateHeader.toTime_t(); } - int now = currentDateTime.toUTC().toTime_t(); + int now = currentDateTime.toTime_t(); int request_time = now; int response_time = now;