Skip to content

Commit

Permalink
Cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
weltling committed Jan 3, 2018
1 parent 0f6f965 commit 3cab0c3
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions ext/standard/hrtime.c
Expand Up @@ -19,7 +19,6 @@
/* $Id$ */

#include "php.h"
#include "zend_exceptions.h"
#include "hrtime.h"

/* {{{ */
Expand All @@ -35,7 +34,6 @@
#elif PHP_HRTIME_PLATFORM_WINDOWS

# define WIN32_LEAN_AND_MEAN
# include <windows.h>

static uint64_t _timer_freq = 0;
static double _timer_int = .0;
Expand Down Expand Up @@ -116,9 +114,13 @@ PHP_MINIT_FUNCTION(hrtime)
static zend_always_inline php_hrtime_t _timer_current(void)
{/*{{{*/
#if PHP_HRTIME_PLATFORM_WINDOWS
uint64_t cur;
QueryPerformanceCounter((LARGE_INTEGER*) &cur);
return (php_hrtime_t)((double)cur * _timer_int * (double)NANO_IN_SEC);
uint64_t cur = 0;
LARGE_INTEGER lt;
if (QueryPerformanceCounter(&lt)) {
cur = lt.QuadPart;
return (php_hrtime_t)((double)cur * _timer_int * (double)NANO_IN_SEC);
}
return 0;
#elif PHP_HRTIME_PLATFORM_APPLE
return (php_hrtime_t)mach_absolute_time() * _timerlib_info.numer / _timerlib_info.denom;
#elif PHP_HRTIME_PLATFORM_POSIX
Expand Down Expand Up @@ -160,7 +162,7 @@ static zend_always_inline php_hrtime_t _timer_current(void)
} while (0)
#endif

/* {{{ proto mixed hrtime([bool get_as_numu = false])
/* {{{ proto mixed hrtime([bool get_as_number = false])
Returns an array of integers in form [seconds, nanoseconds] counted
from an arbitrary point in time. If an optional boolean argument is
passed, returns an integer on 64-bit platforms or float on 32-bit
Expand All @@ -176,16 +178,15 @@ PHP_FUNCTION(hrtime)
Z_PARAM_BOOL(get_as_num)
ZEND_PARSE_PARAMETERS_END();

if (!get_as_num) {
/* TODO On 32-bit care about millenium bug. */
if (UNEXPECTED(get_as_num)) {
PHP_RETURN_HRTIME(t);
} else {
array_init(return_value);
add_next_index_long(return_value, (zend_long)(t / (php_hrtime_t)NANO_IN_SEC));
add_next_index_long(return_value, (zend_long)(t % (php_hrtime_t)NANO_IN_SEC));
} else {
PHP_RETURN_HRTIME(t);
}
#else
RETURN_LONG(0);
RETURN_FALSE
#endif
}
/* }}} */
Expand Down

0 comments on commit 3cab0c3

Please sign in to comment.