Modified: trunk/Source/WTF/ChangeLog (120551 => 120552)
--- trunk/Source/WTF/ChangeLog 2012-06-17 18:36:21 UTC (rev 120551)
+++ trunk/Source/WTF/ChangeLog 2012-06-17 21:06:03 UTC (rev 120552)
@@ -1,3 +1,18 @@
+2012-06-17 Patrick Gansterer <[email protected]>
+
+ [WIN] Simplify implementation of currentTime()
+ https://bugs.webkit.org/show_bug.cgi?id=83156
+
+ Reviewed by Brent Fulgham.
+
+ Use GetSystemTimeAsFileTime() instead of ftime().
+ This avoids an unneeded call to the MS CRT and
+ brings the Win/WinCE code closer together.
+
+ * wtf/CurrentTime.cpp:
+ (WTF::lowResUTCTime):
+ (WTF::currentTime):
+
2012-06-15 Tony Payne <[email protected]>
[chromium] Add iccjpeg and qcms to chromium port.
Modified: trunk/Source/WTF/wtf/CurrentTime.cpp (120551 => 120552)
--- trunk/Source/WTF/wtf/CurrentTime.cpp 2012-06-17 18:36:21 UTC (rev 120551)
+++ trunk/Source/WTF/wtf/CurrentTime.cpp 2012-06-17 21:06:03 UTC (rev 120552)
@@ -47,15 +47,6 @@
#include <stdint.h>
#include <time.h>
-#if USE(QUERY_PERFORMANCE_COUNTER)
-#if OS(WINCE)
-extern "C" time_t mktime(struct tm *t);
-#else
-#include <sys/timeb.h>
-#include <sys/types.h>
-#endif
-#endif
-
#elif PLATFORM(WX)
#include <wx/datetime.h>
#elif PLATFORM(EFL)
@@ -74,12 +65,35 @@
namespace WTF {
-const double msPerSecond = 1000.0;
-
#if !PLATFORM(CHROMIUM)
#if OS(WINDOWS)
+// Number of 100 nanosecond between January 1, 1601 and January 1, 1970.
+static const ULONGLONG epochBias = 116444736000000000ULL;
+static const double nsPerSecond = 1000000000.0;
+
+static double lowResUTCTime()
+{
+ FILETIME fileTime;
+
+#if OS(WINCE)
+ GetCurrentFT(&fileTime);
+#else
+ GetSystemTimeAsFileTime(&fileTime);
+#endif
+
+ // As per Windows documentation for FILETIME, copy the resulting FILETIME structure to a
+ // ULARGE_INTEGER structure using memcpy (using memcpy instead of direct assignment can
+ // prevent alignment faults on 64-bit Windows).
+
+ ULARGE_INTEGER dateTime;
+ memcpy(&dateTime, &fileTime, sizeof(dateTime));
+
+ // Windows file times are in 100s of nanoseconds.
+ return (dateTime.QuadPart - epochBias) / (100 * nsPerSecond);
+}
+
#if USE(QUERY_PERFORMANCE_COUNTER)
static LARGE_INTEGER qpcFrequency;
@@ -128,28 +142,6 @@
return (1000.0 * qpc.QuadPart) / static_cast<double>(qpcFrequency.QuadPart);
}
-static double lowResUTCTime()
-{
-#if OS(WINCE)
- SYSTEMTIME systemTime;
- GetSystemTime(&systemTime);
- struct tm tmtime;
- tmtime.tm_year = systemTime.wYear - 1900;
- tmtime.tm_mon = systemTime.wMonth - 1;
- tmtime.tm_mday = systemTime.wDay;
- tmtime.tm_wday = systemTime.wDayOfWeek;
- tmtime.tm_hour = systemTime.wHour;
- tmtime.tm_min = systemTime.wMinute;
- tmtime.tm_sec = systemTime.wSecond;
- time_t timet = mktime(&tmtime);
- return timet * msPerSecond + systemTime.wMilliseconds;
-#else
- struct _timeb timebuffer;
- _ftime(&timebuffer);
- return timebuffer.time * msPerSecond + timebuffer.millitm;
-#endif
-}
-
static bool qpcAvailable()
{
static bool available;
@@ -208,36 +200,13 @@
#else
-static double currentSystemTime()
-{
- FILETIME ft;
- GetCurrentFT(&ft);
-
- // As per Windows documentation for FILETIME, copy the resulting FILETIME structure to a
- // ULARGE_INTEGER structure using memcpy (using memcpy instead of direct assignment can
- // prevent alignment faults on 64-bit Windows).
-
- ULARGE_INTEGER t;
- memcpy(&t, &ft, sizeof(t));
-
- // Windows file times are in 100s of nanoseconds.
- // To convert to seconds, we have to divide by 10,000,000, which is more quickly
- // done by multiplying by 0.0000001.
-
- // Between January 1, 1601 and January 1, 1970, there were 369 complete years,
- // of which 89 were leap years (1700, 1800, and 1900 were not leap years).
- // That is a total of 134774 days, which is 11644473600 seconds.
-
- return t.QuadPart * 0.0000001 - 11644473600.0;
-}
-
double currentTime()
{
static bool init = false;
static double lastTime;
static DWORD lastTickCount;
if (!init) {
- lastTime = currentSystemTime();
+ lastTime = lowResUTCTime();
lastTickCount = GetTickCount();
init = true;
return lastTime;