Commit fa86f441e20 for php
commit fa86f441e200cd0d8c46b9f8a95a2cddb6f9c42d
Author: Alexander Danilov <10532067+adapik@users.noreply.github.com>
Date: Thu Dec 3 00:24:25 2026 +0200
ext/standard: Improve performance of string.toupper and string.tolower filters (#26035)
diff --git a/NEWS b/NEWS
index f1c3310b687..aac6185cb06 100644
--- a/NEWS
+++ b/NEWS
@@ -263,6 +263,8 @@ PHP NEWS
one byte and the replacement has a different length. (Weilin Du)
. Fixed bug GH-25960 (getimagesize() accepts a JPEG 2000 header with missing
component descriptors). (kid-lxy)
+ . Improved performance of the string.toupper and string.tolower stream
+ filters. (Alexander Danilov)
- URI:
. Fix casing of enum cases in UriHostType and UrlHostType to match the RFC
diff --git a/UPGRADING b/UPGRADING
index b614390b0af..994b4fd0cf6 100644
--- a/UPGRADING
+++ b/UPGRADING
@@ -279,6 +279,8 @@ PHP 8.7 UPGRADE NOTES
encoding.
. Improved performance of in_array() and array_search() in strict mode when
searching for a string.
+ . Improved performance of the string.toupper and string.tolower stream
+ filters.
- JSON:
. Improved performance of json_encode() for strings with non-ASCII
diff --git a/ext/standard/filters.c b/ext/standard/filters.c
index 1648c4ac2da..6f948cc3044 100644
--- a/ext/standard/filters.c
+++ b/ext/standard/filters.c
@@ -73,9 +73,6 @@ static const php_stream_filter_factory strfilter_rot13_factory = {
/* }}} */
/* {{{ string.toupper / string.tolower stream filter implementation */
-static const char lowercase[] = "abcdefghijklmnopqrstuvwxyz";
-static const char uppercase[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
-
static php_stream_filter_status_t strfilter_toupper_filter(
php_stream *stream,
php_stream_filter *thisfilter,
@@ -91,7 +88,7 @@ static php_stream_filter_status_t strfilter_toupper_filter(
while (buckets_in->head) {
bucket = php_stream_bucket_make_writeable(buckets_in->head);
- php_strtr(bucket->buf, bucket->buflen, lowercase, uppercase, 26);
+ zend_str_toupper(bucket->buf, bucket->buflen);
consumed += bucket->buflen;
php_stream_bucket_append(buckets_out, bucket);
@@ -119,7 +116,7 @@ static php_stream_filter_status_t strfilter_tolower_filter(
while (buckets_in->head) {
bucket = php_stream_bucket_make_writeable(buckets_in->head);
- php_strtr(bucket->buf, bucket->buflen, uppercase, lowercase, 26);
+ zend_str_tolower(bucket->buf, bucket->buflen);
consumed += bucket->buflen;
php_stream_bucket_append(buckets_out, bucket);