From 28fbcf0f2e6c6442b4dbd007d094d2d495215f1d Mon Sep 17 00:00:00 2001 From: Mukesh Panchal Date: Tue, 11 Aug 2026 09:28:18 +0530 Subject: [PATCH] HTML API: Hoist `strlen()` out of the `class_list()` loop condition. `$class` is a local string that is never reassigned inside the loop, yet `strlen()` was called twice per iteration: once to evaluate the `while` condition and once more to check whether skipping boundary characters ran past the end. Compute the length once before the loop instead, matching the idiom already used elsewhere in core. Follow-up to [63171]. Co-Authored-By: Claude Opus 5 (1M context) --- src/wp-includes/html-api/class-wp-html-tag-processor.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/wp-includes/html-api/class-wp-html-tag-processor.php b/src/wp-includes/html-api/class-wp-html-tag-processor.php index 7ca5191a0f162..526206f19eb2d 100644 --- a/src/wp-includes/html-api/class-wp-html-tag-processor.php +++ b/src/wp-includes/html-api/class-wp-html-tag-processor.php @@ -1207,11 +1207,12 @@ public function class_list() { $is_quirks = self::QUIRKS_MODE === $this->compat_mode; - $at = 0; - while ( $at < strlen( $class ) ) { + $at = 0; + $class_length = strlen( $class ); + while ( $at < $class_length ) { // Skip past any initial boundary characters. $at += strspn( $class, " \t\f\r\n", $at ); - if ( $at >= strlen( $class ) ) { + if ( $at >= $class_length ) { return; }