From baccf6029b5e4c1200d235452b7bf17c7d8f45a8 Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Tue, 17 Nov 2026 11:16:28 +0400 Subject: [PATCH] Decode an identifier only when a url token may follow consume_ident_like() decoded every identifier to compare it with "url", and used the result only when the next byte is `(`. Checking that byte first skips the decoding for every identifier that is not followed by `(`, which is most of them. Tokenizing the 70 KB stylesheet from the previous commit took 4.9 ms before and 4.5 ms after, best of 10 runs on PHP 8.5. (cherry picked from commit a72493d4cadd5c6cd5b172832ad256e08734dca3) --- src/wp-includes/css-api/class-wp-css-token-processor.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/css-api/class-wp-css-token-processor.php b/src/wp-includes/css-api/class-wp-css-token-processor.php index e9b0e27e4bd7e..c7603b46ac100 100644 --- a/src/wp-includes/css-api/class-wp-css-token-processor.php +++ b/src/wp-includes/css-api/class-wp-css-token-processor.php @@ -1057,11 +1057,14 @@ private function consume_ident_like(): bool { // Consume an ident sequence, and let string be the result. $ident_start = $this->at; $this->consume_ident_sequence(); - $string = self::decode_range( $this->css, $ident_start, $this->at - $ident_start ); // If string's value is an ASCII case-insensitive match for "url", // and the next input code point is U+0028 LEFT PARENTHESIS ((). - if ( 0 === strcasecmp( $string, 'url' ) && $this->at < $this->length && '(' === $this->css[ $this->at ] ) { + if ( + $this->at < $this->length && + '(' === $this->css[ $this->at ] && + 0 === strcasecmp( self::decode_range( $this->css, $ident_start, $this->at - $ident_start ), 'url' ) + ) { // Consume it. ++$this->at;