Commit:    fd650ec93e15bbbc05542e4acdde13d1fd9bcf73
Author:    Stanislav Malyshev <s...@php.net>         Tue, 4 Dec 2012 21:02:09 
-0800
Parents:   b8553d8494ce197b8a86c0a23f8a41e9feac653b
Branches:  PHP-5.4 PHP-5.5 master

Link:       
http://git.php.net/?p=php-src.git;a=commitdiff;h=fd650ec93e15bbbc05542e4acdde13d1fd9bcf73

Log:
fix bug #63666 - Poor date() performance

Bugs:
https://bugs.php.net/63666

Changed paths:
  M  NEWS
  M  ext/date/php_date.c


Diff:
diff --git a/NEWS b/NEWS
index 1296b02..b49bae2 100644
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,7 @@ PHP                                                             
           NEWS
 ?? ??? 2012, PHP 5.4.10
 
 - Core:
+  . Fixed bug #63666 (Poor date() performance). (Paul Talborg).
   . Fixed bug #63635 (Segfault in gc_collect_cycles). (Dmitry)
   . Fixed bug #63468 (wrong called method as callback with inheritance).
     (Laruence)
diff --git a/ext/date/php_date.c b/ext/date/php_date.c
index 893a9d6..b87dfcb 100644
--- a/ext/date/php_date.c
+++ b/ext/date/php_date.c
@@ -948,6 +948,7 @@ static char *date_format(char *format, int format_len, 
timelib_time *t, int loca
        timelib_time_offset *offset = NULL;
        timelib_sll          isoweek, isoyear;
        int                  rfc_colon;
+       int                  weekYearSet = 0;
 
        if (!format_len) {
                return estrdup("");
@@ -974,7 +975,6 @@ static char *date_format(char *format, int format_len, 
timelib_time *t, int loca
                        offset = timelib_get_time_zone_info(t->sse, t->tz_info);
                }
        }
-       timelib_isoweek_from_date(t->y, t->m, t->d, &isoweek, &isoyear);
 
        for (i = 0; i < format_len; i++) {
                rfc_colon = 0;
@@ -990,8 +990,12 @@ static char *date_format(char *format, int format_len, 
timelib_time *t, int loca
                        case 'z': length = slprintf(buffer, 32, "%d", (int) 
timelib_day_of_year(t->y, t->m, t->d)); break;
 
                        /* week */
-                       case 'W': length = slprintf(buffer, 32, "%02d", (int) 
isoweek); break; /* iso weeknr */
-                       case 'o': length = slprintf(buffer, 32, "%d", (int) 
isoyear); break; /* iso year */
+                       case 'W':
+                               if(!weekYearSet) { 
timelib_isoweek_from_date(t->y, t->m, t->d, &isoweek, &isoyear); weekYearSet = 
1; }
+                               length = slprintf(buffer, 32, "%02d", (int) 
isoweek); break; /* iso weeknr */
+                       case 'o':
+                               if(!weekYearSet) { 
timelib_isoweek_from_date(t->y, t->m, t->d, &isoweek, &isoyear); weekYearSet = 
1; }
+                               length = slprintf(buffer, 32, "%d", (int) 
isoyear); break; /* iso year */
 
                        /* month */
                        case 'F': length = slprintf(buffer, 32, "%s", 
mon_full_names[t->m - 1]); break;


--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to