From: Dmitry Stogov Date: Thu, 4 Mar 2021 09:27:31 +0000 (+0300) Subject: Avoid useless date conversion X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b4e9b1846376f562e27a13572a137ec584c13f58;p=php Avoid useless date conversion --- diff --git a/ext/date/php_date.c b/ext/date/php_date.c index 4e840a3106..a12f00957b 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -2270,6 +2270,14 @@ PHPAPI int php_date_initialize(php_date_obj *dateobj, const char *time_str, size timelib_unixtime2local(now, (timelib_sll) sec); php_date_set_time_fraction(now, usec); + if (!format + && time_str_len == sizeof("now") - 1 + && memcmp(time_str, "now", sizeof("now") - 1) == 0) { + timelib_time_dtor(dateobj->time); + dateobj->time = now; + return 1; + } + options = TIMELIB_NO_CLONE; if (flags & PHP_DATE_INIT_FORMAT) { options |= TIMELIB_OVERRIDE_TIME; @@ -3320,7 +3328,10 @@ PHP_FUNCTION(date_timestamp_get) } dateobj = Z_PHPDATE_P(object); DATE_CHECK_INITIALIZED(dateobj->time, DateTime); - timelib_update_ts(dateobj->time, NULL); + + if (!dateobj->time->sse_uptodate) { + timelib_update_ts(dateobj->time, NULL); + } timestamp = timelib_date_to_int(dateobj->time, &epoch_does_not_fit_in_zend_long);