Skip to content

ext/date: various optimizations of _php_gettimeofday #18560

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions ext/date/tests/gettimeofday_basic.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,12 @@ echo "*** Testing gettimeofday() : basic functionality ***\n";

date_default_timezone_set("Asia/Calcutta");

// Initialise all required variables
$get_as_float = true;

// Calling gettimeofday() with all possible arguments
var_dump( gettimeofday($get_as_float) );
var_dump( gettimeofday(true) );

// Calling gettimeofday() with mandatory arguments
var_dump( gettimeofday() );

// Initialise all required variables
$get_as_float = false;

// Calling gettimeofday() with all possible arguments
var_dump( gettimeofday($get_as_float) );
var_dump( gettimeofday(false) );

?>
--EXPECTF--
Expand Down
10 changes: 5 additions & 5 deletions ext/standard/microtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@
#define SEC_IN_MIN 60

#ifdef HAVE_GETTIMEOFDAY
static void _php_gettimeofday(INTERNAL_FUNCTION_PARAMETERS, int mode)
static void _php_gettimeofday(INTERNAL_FUNCTION_PARAMETERS, bool mode)
{
bool get_as_float = 0;
bool get_as_float = false;
struct timeval tp = {0};

ZEND_PARSE_PARAMETERS_START(0, 1)
Expand All @@ -66,7 +66,7 @@ static void _php_gettimeofday(INTERNAL_FUNCTION_PARAMETERS, int mode)

offset = timelib_get_time_zone_info(tp.tv_sec, get_timezone_info());

array_init(return_value);
array_init_size(return_value, 4);
add_assoc_long(return_value, "sec", tp.tv_sec);
add_assoc_long(return_value, "usec", tp.tv_usec);

Expand All @@ -82,14 +82,14 @@ static void _php_gettimeofday(INTERNAL_FUNCTION_PARAMETERS, int mode)
/* {{{ Returns either a string or a float containing the current time in seconds and microseconds */
PHP_FUNCTION(microtime)
{
_php_gettimeofday(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
_php_gettimeofday(INTERNAL_FUNCTION_PARAM_PASSTHRU, false);
}
/* }}} */

/* {{{ Returns the current time as array */
PHP_FUNCTION(gettimeofday)
{
_php_gettimeofday(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
_php_gettimeofday(INTERNAL_FUNCTION_PARAM_PASSTHRU, true);
}
#endif
/* }}} */
Expand Down