Skip to content

Commit fd650ec

Browse files
committed
fix bug #63666 - Poor date() performance
1 parent b8553d8 commit fd650ec

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ PHP NEWS
33
?? ??? 2012, PHP 5.4.10
44

55
- Core:
6+
. Fixed bug #63666 (Poor date() performance). (Paul Talborg).
67
. Fixed bug #63635 (Segfault in gc_collect_cycles). (Dmitry)
78
. Fixed bug #63468 (wrong called method as callback with inheritance).
89
(Laruence)

ext/date/php_date.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -948,6 +948,7 @@ static char *date_format(char *format, int format_len, timelib_time *t, int loca
948948
timelib_time_offset *offset = NULL;
949949
timelib_sll isoweek, isoyear;
950950
int rfc_colon;
951+
int weekYearSet = 0;
951952

952953
if (!format_len) {
953954
return estrdup("");
@@ -974,7 +975,6 @@ static char *date_format(char *format, int format_len, timelib_time *t, int loca
974975
offset = timelib_get_time_zone_info(t->sse, t->tz_info);
975976
}
976977
}
977-
timelib_isoweek_from_date(t->y, t->m, t->d, &isoweek, &isoyear);
978978

979979
for (i = 0; i < format_len; i++) {
980980
rfc_colon = 0;
@@ -990,8 +990,12 @@ static char *date_format(char *format, int format_len, timelib_time *t, int loca
990990
case 'z': length = slprintf(buffer, 32, "%d", (int) timelib_day_of_year(t->y, t->m, t->d)); break;
991991

992992
/* week */
993-
case 'W': length = slprintf(buffer, 32, "%02d", (int) isoweek); break; /* iso weeknr */
994-
case 'o': length = slprintf(buffer, 32, "%d", (int) isoyear); break; /* iso year */
993+
case 'W':
994+
if(!weekYearSet) { timelib_isoweek_from_date(t->y, t->m, t->d, &isoweek, &isoyear); weekYearSet = 1; }
995+
length = slprintf(buffer, 32, "%02d", (int) isoweek); break; /* iso weeknr */
996+
case 'o':
997+
if(!weekYearSet) { timelib_isoweek_from_date(t->y, t->m, t->d, &isoweek, &isoyear); weekYearSet = 1; }
998+
length = slprintf(buffer, 32, "%d", (int) isoyear); break; /* iso year */
995999

9961000
/* month */
9971001
case 'F': length = slprintf(buffer, 32, "%s", mon_full_names[t->m - 1]); break;

0 commit comments

Comments
 (0)