]> granicus.if.org Git - php/commitdiff
Avoid time(NULL) call if explicit timestamp given
authorNikita Popov <nikita.ppv@gmail.com>
Mon, 8 Apr 2019 07:43:47 +0000 (09:43 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Mon, 8 Apr 2019 07:43:47 +0000 (09:43 +0200)
As suggested by Benjamin Coutu.

ext/date/php_date.c

index 565e0185382a6732513468f6ba24250c37793a96..c80e318b2264f1acde27f919253567dac7d6dec7 100644 (file)
@@ -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;