Interactivity API: Do not process directives when there aren't any.

Short-circuits directive processing when the markup does not actually contain any `data-wp-*` attributes.
This reduces function calls and memory usage for the best case scenario due to not involving `WP_HTML_Tag_Processor`.

Reviewed by gziolo, swissspidy.
Merges [57824] to the to the 6.5 branch.

Props joemcgill, swissspidy, gziolo, cbravobernal, flixos90.
Fixes #60749.

Built from https://develop.svn.wordpress.org/branches/6.5@57825


git-svn-id: http://core.svn.wordpress.org/branches/6.5@57326 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Pascal Birchler 2024-03-13 10:44:11 +00:00
parent 100e435853
commit 412b7647c4
2 changed files with 5 additions and 1 deletions

View File

@ -204,6 +204,10 @@ final class WP_Interactivity_API {
* @return string The processed HTML content. It returns the original content when the HTML contains unbalanced tags.
*/
public function process_directives( string $html ): string {
if ( ! str_contains( $html, 'data-wp-' ) ) {
return $html;
}
$context_stack = array();
$namespace_stack = array();
$result = $this->process_directives_args( $html, $context_stack, $namespace_stack );

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.5-RC2-57823';
$wp_version = '6.5-RC2-57825';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.