Skip to content

Commit f3d1724

Browse files
committed
Sketching attribute whitespace fast path
1 parent 24da950 commit f3d1724

1 file changed

Lines changed: 18 additions & 10 deletions

File tree

‎src/wp-includes/html-api/class-wp-html-tag-processor.php‎

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2219,25 +2219,33 @@ private function parse_all_attributes(): void {
22192219
$attribute_name = substr( $this->html, $attribute_start, $name_length );
22202220
$this->bytes_already_parsed += $name_length;
22212221

2222-
$this->skip_whitespace();
2223-
if ( $this->bytes_already_parsed >= $doc_length ) {
2224-
$this->parser_state = self::STATE_INCOMPLETE_INPUT;
2225-
break;
2222+
// There is no whitespace to skip when `=` follows the name.
2223+
if ( '=' !== $this->html[ $this->bytes_already_parsed ] ) {
2224+
$this->skip_whitespace();
2225+
if ( $this->bytes_already_parsed >= $doc_length ) {
2226+
$this->parser_state = self::STATE_INCOMPLETE_INPUT;
2227+
break;
2228+
}
22262229
}
22272230

22282231
$has_value = '=' === $this->html[ $this->bytes_already_parsed ];
22292232
if ( $has_value ) {
22302233
++$this->bytes_already_parsed;
2231-
$this->skip_whitespace();
2232-
if ( $this->bytes_already_parsed >= $doc_length ) {
2233-
$this->parser_state = self::STATE_INCOMPLETE_INPUT;
2234-
break;
2234+
2235+
// There is no whitespace to skip when a quote follows `=`.
2236+
$quote = $this->html[ $this->bytes_already_parsed ] ?? '';
2237+
if ( '"' !== $quote && "'" !== $quote ) {
2238+
$this->skip_whitespace();
2239+
if ( $this->bytes_already_parsed >= $doc_length ) {
2240+
$this->parser_state = self::STATE_INCOMPLETE_INPUT;
2241+
break;
2242+
}
2243+
$quote = $this->html[ $this->bytes_already_parsed ];
22352244
}
22362245

2237-
switch ( $this->html[ $this->bytes_already_parsed ] ) {
2246+
switch ( $quote ) {
22382247
case "'":
22392248
case '"':
2240-
$quote = $this->html[ $this->bytes_already_parsed ];
22412249
$value_start = $this->bytes_already_parsed + 1;
22422250
$end_quote_at = strpos( $this->html, $quote, $value_start );
22432251
$end_quote_at = false === $end_quote_at ? $doc_length : $end_quote_at;

0 commit comments

Comments
 (0)