From 3e05df4abe1469fb4fb04e6d26f2befb3317346e Mon Sep 17 00:00:00 2001 From: Shane Kearns Date: Tue, 20 Apr 2010 17:13:59 +0200 Subject: Use a compile time constant for the C epoch as a julian day. The julian day calculation is complex, so capturing the value and storing as a compile time constant will save some calculations at runtime. Reviewed-by: Thiago Macieira --- src/corelib/tools/qdatetime.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/corelib/tools/qdatetime.cpp b/src/corelib/tools/qdatetime.cpp index 36e5173..c753c0b 100644 --- a/src/corelib/tools/qdatetime.cpp +++ b/src/corelib/tools/qdatetime.cpp @@ -88,7 +88,8 @@ enum { SECS_PER_HOUR = 3600, MSECS_PER_HOUR = 3600000, SECS_PER_MIN = 60, - MSECS_PER_MIN = 60000 + MSECS_PER_MIN = 60000, + JULIAN_DAY_FOR_EPOCH = 2440588 // result of julianDayFromGregorianDate(1970, 1, 1) }; static inline QDate fixedDate(int y, int m, int d) @@ -2320,8 +2321,8 @@ void QDateTime::setTimeSpec(Qt::TimeSpec spec) qint64 toMSecsSinceEpoch_helper(qint64 jd, int msecs) { - int days = jd - julianDayFromGregorianDate(1970, 1, 1); - qint64 retval = (qlonglong(days) * MSECS_PER_DAY) + msecs; + qint64 days = jd - JULIAN_DAY_FOR_EPOCH; + qint64 retval = (days * MSECS_PER_DAY) + msecs; return retval; } -- cgit v0.12