[php-src] PR #23961: ext/standard: Check for UTF-8 first when resolving the charset of html functions

From: Date: Mon, 28 Sep 2026 08:17:05 +0000
Subject: [php-src] PR #23961: ext/standard: Check for UTF-8 first when resolving the charset of html functions
Groups: php.git-pulls 
Request: Send a blank email to git-pulls+get-38875@lists.php.net to get a copy of this message
Pull Request: https://github.com/php/php-src/pull/23961 Author: nicolas-grekas Follow-up of #23957: once htmlspecialchars() returns its input when nothing needs encoding, resolving the charset is about half of what's left for short strings. determine_charset() runs strlen() and walks the charset map with case-insensitive compares on every call, while UTF-8 is what nearly every call asks for, either explicitly as Twig or Laravel's e() do, or through default_charset. This checks for "utf-8" in any case before walking the map, and moves the walk to a separate function so that the common path doesn't pay for its stack frame. On top of #23957, htmlspecialchars() on a short string becomes about 40% cheaper. htmlentities(), html_entity_decode() and get_html_translation_table() benefit the same way, and other charsets resolve as before.

« previous php.git-pulls (#38875) next »