com php-src: Avoid time(NULL) call if explicit timestamp given: ext/date/php_date.c

From: Date: Mon, 08 Apr 2019 07:43:47 +0000
Subject: com php-src: Avoid time(NULL) call if explicit timestamp given: ext/date/php_date.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-105561@lists.php.net to get a copy of this message
Commit: c708c4b40443f472ef99f72abc9f7080f3ca7923 Author: Nikita Popov <nikita.ppv@gmail.com> Mon, 8 Apr 2019 09:43:47 +0200 Parents: 6acba73876e8d0786668a7f84e8ffd90416fc57b Branches: PHP-7.4 master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=c708c4b40443f472ef99f72abc9f7080f3ca7923 Log: Avoid time(NULL) call if explicit timestamp given As suggested by Benjamin Coutu. Changed paths: M ext/date/php_date.c Diff: diff --git a/ext/date/php_date.c b/ext/date/php_date.c index 565e018..c80e318 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -1761,7 +1761,7 @@ PHP_FUNCTION(time) Returns the results of the C system call localtime as an associative array if the associative_array argument is set to 1 other wise it is a regular array */ PHP_FUNCTION(localtime) { - zend_long timestamp = (zend_long)time(NULL); + zend_long timestamp; zend_bool associative = 0; timelib_tzinfo *tzi; timelib_time *ts; @@ -1772,6 +1772,10 @@ PHP_FUNCTION(localtime) Z_PARAM_BOOL(associative) ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); + if (ZEND_NUM_ARGS() == 0) { + timestamp = (zend_long) time(NULL); + } + tzi = get_timezone_info(); ts = timelib_time_ctor(); ts->tz_info = tzi; @@ -1810,7 +1814,7 @@ PHP_FUNCTION(localtime) Get date/time information */ PHP_FUNCTION(getdate) { - zend_long timestamp = (zend_long)time(NULL); + zend_long timestamp; timelib_tzinfo *tzi; timelib_time *ts; @@ -1819,6 +1823,10 @@ PHP_FUNCTION(getdate) Z_PARAM_LONG(timestamp) ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); + if (ZEND_NUM_ARGS() == 0) { + timestamp = (zend_long) time(NULL); + } + tzi = get_timezone_info(); ts = timelib_time_ctor(); ts->tz_info = tzi;

« previous php.cvs (#105561) next »