]> granicus.if.org Git - php/commitdiff
improved system time function determination
authorAnatol Belski <ab@php.net>
Tue, 23 Dec 2014 11:02:36 +0000 (12:02 +0100)
committerAnatol Belski <ab@php.net>
Tue, 23 Dec 2014 12:00:30 +0000 (13:00 +0100)
It doesn't need to LoadLibrary and all that stuff every time, but
once on the first access. Also the functions which are not directly
used inlined now.

win32/time.c

index 75539748e88c46c9b989ea56859b8104fc743687..9b5030a0f290e54ee3930af7421445147f0a56d9 100644 (file)
@@ -27,7 +27,9 @@
 
 typedef VOID (WINAPI *MyGetSystemTimeAsFileTime)(LPFILETIME lpSystemTimeAsFileTime);
 
-static MyGetSystemTimeAsFileTime get_time_func(void)
+static MyGetSystemTimeAsFileTime timefunc = NULL;
+
+static zend_always_inline MyGetSystemTimeAsFileTime get_time_func(void)
 {
        MyGetSystemTimeAsFileTime timefunc = NULL;
        HMODULE hMod = LoadLibrary("kernel32.dll");
@@ -45,19 +47,16 @@ static MyGetSystemTimeAsFileTime get_time_func(void)
        return timefunc;
 }
 
-int getfilesystemtime(struct timeval *tv)
+static zend_always_inline int getfilesystemtime(struct timeval *tv)
 {
        FILETIME ft;
        unsigned __int64 ff = 0;
-       MyGetSystemTimeAsFileTime timefunc;
        ULARGE_INTEGER fft;
 
-       timefunc = get_time_func();
-       if (timefunc) {
-               timefunc(&ft);
-       } else {
-               GetSystemTimeAsFileTime(&ft);
+       if (!timefunc) {
+               timefunc = get_time_func();
        }
+       timefunc(&ft);
 
         /*
         * Do not cast a pointer to a FILETIME structure to either a