From bf5f2a9e3e3bf70c373b65bf95a332f4e1c514f9 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 10 Aug 2012 16:14:48 +0200 Subject: Switch to struct timespec everywhere instead of timeval This avoids an extra division by 1000 when getting the current time. This can't overflow, under normal circumstances, even on 32-bit: when adding two values less than 1 billion, the result is less than 2 billion, which is less than 2^31. Change-Id: I6f8e1aadfe2fcf6ac8da584eab4c1e61aee51cbb Reviewed-by: David Faure (KDE) Reviewed-by: Thiago Macieira --- src/corelib/tools/qelapsedtimer_mac.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/corelib/tools/qelapsedtimer_mac.cpp') diff --git a/src/corelib/tools/qelapsedtimer_mac.cpp b/src/corelib/tools/qelapsedtimer_mac.cpp index 611098779c..19056d1bd9 100644 --- a/src/corelib/tools/qelapsedtimer_mac.cpp +++ b/src/corelib/tools/qelapsedtimer_mac.cpp @@ -76,14 +76,14 @@ static qint64 absoluteToMSecs(qint64 cpuTime) return absoluteToNSecs(cpuTime) / 1000000; } -timeval qt_gettime() Q_DECL_NOTHROW +timespec qt_gettime() Q_DECL_NOTHROW { - timeval tv; + timespec tv; uint64_t cpu_time = mach_absolute_time(); uint64_t nsecs = absoluteToNSecs(cpu_time); tv.tv_sec = nsecs / 1000000000ull; - tv.tv_usec = (nsecs / 1000) - (tv.tv_sec * 1000000); + tv.tv_nsec = nsecs - (tv.tv_sec * 1000000000ull); return tv; } -- cgit v1.2.3