Skip to content

Commit 232abea

Browse files
committed
Unroll whitespace check in '--' line-comment dispatch
The leading-whitespace skip at the top of read_next_token() was already unrolled into byte-equality checks for the perf reasons documented in 916b512. Apply the same unroll to the third-byte whitespace check that gates a '--' as a line-comment start, so the hot dispatch chain doesn't fall back into strpos() on a 5-char mask for this case. The bound check is folded into '?? null' on the third-byte read, matching the rest of the lookahead style.
1 parent d492808 commit 232abea

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

packages/mysql-on-sqlite/src/mysql/class-wp-mysql-lexer.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2507,10 +2507,16 @@ private function read_next_token(): ?int {
25072507
$type = self::LOGICAL_NOT_OPERATOR;
25082508
}
25092509
} elseif ( '-' === $byte ) {
2510+
$third_byte = $this->sql[ $this->bytes_already_read + 2 ] ?? null;
25102511
if (
25112512
'-' === $next_byte
2512-
&& $this->bytes_already_read + 2 < $this->sql_length
2513-
&& false !== strpos( self::WHITESPACE_MASK, $this->sql[ $this->bytes_already_read + 2 ] )
2513+
&& (
2514+
' ' === $third_byte
2515+
|| "\t" === $third_byte
2516+
|| "\n" === $third_byte
2517+
|| "\r" === $third_byte
2518+
|| "\f" === $third_byte
2519+
)
25142520
) {
25152521
$type = $this->read_line_comment();
25162522
} elseif ( '>' === $next_byte ) {

0 commit comments

Comments
 (0)