Skip to content

Commit 91d821e

Browse files
committed
Use instanceof check for native lexer fast path
When the native extension is loaded, WP_MySQL_Lexer extends WP_MySQL_Native_Lexer, so an instanceof check is more direct than method_exists() — and it gives the IDE/static analyzer something to work with.
1 parent 7b2099a commit 91d821e

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1158,7 +1158,7 @@ public function create_parser( string $query ): WP_MySQL_Parser {
11581158
80038,
11591159
$this->active_sql_modes
11601160
);
1161-
if ( method_exists( $lexer, 'native_token_stream' ) ) {
1161+
if ( $lexer instanceof WP_MySQL_Native_Lexer ) {
11621162
$tokens = $lexer->native_token_stream();
11631163
return new WP_MySQL_Parser( self::$mysql_grammar, $tokens );
11641164
}

packages/mysql-on-sqlite/tests/tools/run-parser-benchmark.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ function get_stats( $total, $failures, $exceptions ) {
5656

5757
try {
5858
$lexer = new WP_MySQL_Lexer( $query );
59-
$tokens = method_exists( $lexer, 'native_token_stream' )
59+
$tokens = $lexer instanceof WP_MySQL_Native_Lexer
6060
? $lexer->native_token_stream()
6161
: $lexer->remaining_tokens();
6262
if ( ( is_array( $tokens ) ? count( $tokens ) : $tokens->count() ) === 0 ) {

0 commit comments

Comments
 (0)