mirror of
https://github.com/WordPress/WordPress.git
synced 2025-01-03 06:57:35 +01:00
Formatting: Improve performance of esc_url()
.
This changeset indirectly improves performance of the commonly used `esc_url()` function by optimizing the low-level function `wp_kses_bad_protocol()` for the by far most common scenarios, which are URLs using either the `http` or `https` protocol. For this common scenario, the changeset now avoids the `do while` loop. While for a single call to the `esc_url()` function the performance wins are negligible, given that `esc_url()` is often called many times in one page load, they can add up, making this a worthwhile improvement. Props mukesh27, schlessera, markjaquith, azaozz, spacedmonkey. Fixes #22951. Built from https://develop.svn.wordpress.org/trunk@55053 git-svn-id: http://core.svn.wordpress.org/trunk@54586 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
bc8ed77b19
commit
de505f0eac
@ -1686,7 +1686,16 @@ function wp_kses_check_attr_val( $value, $vless, $checkname, $checkvalue ) {
|
|||||||
* @return string Filtered content.
|
* @return string Filtered content.
|
||||||
*/
|
*/
|
||||||
function wp_kses_bad_protocol( $content, $allowed_protocols ) {
|
function wp_kses_bad_protocol( $content, $allowed_protocols ) {
|
||||||
$content = wp_kses_no_null( $content );
|
$content = wp_kses_no_null( $content );
|
||||||
|
|
||||||
|
// Short-circuit if the string starts with `https://` or `http://`. Most common cases.
|
||||||
|
if (
|
||||||
|
( str_starts_with( $content, 'https://' ) && in_array( 'https', $allowed_protocols, true ) ) ||
|
||||||
|
( str_starts_with( $content, 'http://' ) && in_array( 'http', $allowed_protocols, true ) )
|
||||||
|
) {
|
||||||
|
return $content;
|
||||||
|
}
|
||||||
|
|
||||||
$iterations = 0;
|
$iterations = 0;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '6.2-alpha-55052';
|
$wp_version = '6.2-alpha-55053';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
Loading…
Reference in New Issue
Block a user