[PATCH] Small date() optimization
| From: | Matt Wilmas | Date: | Fri, 22 Dec 2006 05:06:41 +0000 |
| Subject: | [PATCH] Small date() optimization | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-27174@lists.php.net to get a copy of this message | ||
Hi,
Just a simple patch for 5.2 to save smart_str_appends()'s strlen() calls in
date_format(). It's already done in HEAD. Seems pretty safe for 5.2.1. :-)
I also noticed that if the format string contains a backslash as the last
character, it is lost (should be printed right?). So I changed that too and
attached the patch for HEAD.
5.2's patch:
http://realplain.com/php/date_optimization_5_2.diff
Matt
Index: ext/date/php_date.c =================================================================== RCS file: /repository/php-src/ext/date/php_date.c,v retrieving revision 1.126 diff -u -r1.126 php_date.c --- ext/date/php_date.c 11 Dec 2006 21:08:44 -0000 1.126 +++ ext/date/php_date.c 22 Dec 2006 04:50:00 -0000 @@ -926,7 +926,7 @@ break; case 'U': length = date_spprintf(&buffer, 32 TSRMLS_CC, "%lld", (timelib_sll) t->sse); break; - case '\\': if (i < format_len) i++; length = date_spprintf(&buffer, 32 TSRMLS_CC, "%c", format[i]); break; + case '\\': if (i + 1 < format_len) i++; /* break intentionally missing */ default: length = date_spprintf(&buffer, 32 TSRMLS_CC, "%c", format[i]); break;
Index: ext/date/php_date.c =================================================================== RCS file: /repository/php-src/ext/date/php_date.c,v retrieving revision 1.126 diff -u -r1.126 php_date.c --- ext/date/php_date.c 11 Dec 2006 21:08:44 -0000 1.126 +++ ext/date/php_date.c 22 Dec 2006 04:50:00 -0000 @@ -926,7 +926,7 @@ break; case 'U': length = date_spprintf(&buffer, 32 TSRMLS_CC, "%lld", (timelib_sll) t->sse); break; - case '\\': if (i < format_len) i++; length = date_spprintf(&buffer, 32 TSRMLS_CC, "%c", format[i]); break; + case '\\': if (i + 1 < format_len) i++; /* break intentionally missing */ default: length = date_spprintf(&buffer, 32 TSRMLS_CC, "%c", format[i]); break;