Skip to content

Commit 859da96

Browse files
committed
Restore native parser node fast paths
1 parent c1f878e commit 859da96

1 file changed

Lines changed: 48 additions & 16 deletions

File tree

packages/mysql-on-sqlite/src/mysql/class-wp-mysql-native-parser-node.php

Lines changed: 48 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,97 +35,129 @@ public function merge_fragment( $node ) {
3535

3636
/** @inheritDoc */
3737
public function has_child(): bool {
38-
$this->materialize_native_children();
38+
if ( $this->has_native_ast() ) {
39+
return wp_sqlite_mysql_native_ast_has_child( $this->native_ast, $this->native_node_index );
40+
}
3941
return parent::has_child();
4042
}
4143

4244
/** @inheritDoc */
4345
public function has_child_node( ?string $rule_name = null ): bool {
44-
$this->materialize_native_children();
46+
if ( $this->has_native_ast() ) {
47+
return wp_sqlite_mysql_native_ast_has_child_node( $this->native_ast, $this->native_node_index, $rule_name );
48+
}
4549
return parent::has_child_node( $rule_name );
4650
}
4751

4852
/** @inheritDoc */
4953
public function has_child_token( ?int $token_id = null ): bool {
50-
$this->materialize_native_children();
54+
if ( $this->has_native_ast() ) {
55+
return wp_sqlite_mysql_native_ast_has_child_token( $this->native_ast, $this->native_node_index, $token_id );
56+
}
5157
return parent::has_child_token( $token_id );
5258
}
5359

5460
/** @inheritDoc */
5561
public function get_first_child() {
56-
$this->materialize_native_children();
62+
if ( $this->has_native_ast() ) {
63+
return wp_sqlite_mysql_native_ast_get_first_child( $this->native_ast, $this->native_node_index );
64+
}
5765
return parent::get_first_child();
5866
}
5967

6068
/** @inheritDoc */
6169
public function get_first_child_node( ?string $rule_name = null ): ?WP_Parser_Node {
62-
$this->materialize_native_children();
70+
if ( $this->has_native_ast() ) {
71+
return wp_sqlite_mysql_native_ast_get_first_child_node( $this->native_ast, $this->native_node_index, $rule_name );
72+
}
6373
return parent::get_first_child_node( $rule_name );
6474
}
6575

6676
/** @inheritDoc */
6777
public function get_first_child_token( ?int $token_id = null ): ?WP_Parser_Token {
68-
$this->materialize_native_children();
78+
if ( $this->has_native_ast() ) {
79+
return wp_sqlite_mysql_native_ast_get_first_child_token( $this->native_ast, $this->native_node_index, $token_id );
80+
}
6981
return parent::get_first_child_token( $token_id );
7082
}
7183

7284
/** @inheritDoc */
7385
public function get_first_descendant_node( ?string $rule_name = null ): ?WP_Parser_Node {
74-
$this->materialize_native_children();
86+
if ( $this->has_native_ast() ) {
87+
return wp_sqlite_mysql_native_ast_get_first_descendant_node( $this->native_ast, $this->native_node_index, $rule_name );
88+
}
7589
return parent::get_first_descendant_node( $rule_name );
7690
}
7791

7892
/** @inheritDoc */
7993
public function get_first_descendant_token( ?int $token_id = null ): ?WP_Parser_Token {
80-
$this->materialize_native_children();
94+
if ( $this->has_native_ast() ) {
95+
return wp_sqlite_mysql_native_ast_get_first_descendant_token( $this->native_ast, $this->native_node_index, $token_id );
96+
}
8197
return parent::get_first_descendant_token( $token_id );
8298
}
8399

84100
/** @inheritDoc */
85101
public function get_children(): array {
86-
$this->materialize_native_children();
102+
if ( $this->has_native_ast() ) {
103+
return wp_sqlite_mysql_native_ast_get_children( $this->native_ast, $this->native_node_index );
104+
}
87105
return parent::get_children();
88106
}
89107

90108
/** @inheritDoc */
91109
public function get_child_nodes( ?string $rule_name = null ): array {
92-
$this->materialize_native_children();
110+
if ( $this->has_native_ast() ) {
111+
return wp_sqlite_mysql_native_ast_get_child_nodes( $this->native_ast, $this->native_node_index, $rule_name );
112+
}
93113
return parent::get_child_nodes( $rule_name );
94114
}
95115

96116
/** @inheritDoc */
97117
public function get_child_tokens( ?int $token_id = null ): array {
98-
$this->materialize_native_children();
118+
if ( $this->has_native_ast() ) {
119+
return wp_sqlite_mysql_native_ast_get_child_tokens( $this->native_ast, $this->native_node_index, $token_id );
120+
}
99121
return parent::get_child_tokens( $token_id );
100122
}
101123

102124
/** @inheritDoc */
103125
public function get_descendants(): array {
104-
$this->materialize_native_children();
126+
if ( $this->has_native_ast() ) {
127+
return wp_sqlite_mysql_native_ast_get_descendants( $this->native_ast, $this->native_node_index );
128+
}
105129
return parent::get_descendants();
106130
}
107131

108132
/** @inheritDoc */
109133
public function get_descendant_nodes( ?string $rule_name = null ): array {
110-
$this->materialize_native_children();
134+
if ( $this->has_native_ast() ) {
135+
return wp_sqlite_mysql_native_ast_get_descendant_nodes( $this->native_ast, $this->native_node_index, $rule_name );
136+
}
111137
return parent::get_descendant_nodes( $rule_name );
112138
}
113139

114140
/** @inheritDoc */
115141
public function get_descendant_tokens( ?int $token_id = null ): array {
116-
$this->materialize_native_children();
142+
if ( $this->has_native_ast() ) {
143+
return wp_sqlite_mysql_native_ast_get_descendant_tokens( $this->native_ast, $this->native_node_index, $token_id );
144+
}
117145
return parent::get_descendant_tokens( $token_id );
118146
}
119147

120148
/** @inheritDoc */
121149
public function get_start(): int {
122-
$this->materialize_native_children();
150+
if ( $this->has_native_ast() ) {
151+
return wp_sqlite_mysql_native_ast_get_start( $this->native_ast, $this->native_node_index );
152+
}
123153
return parent::get_start();
124154
}
125155

126156
/** @inheritDoc */
127157
public function get_length(): int {
128-
$this->materialize_native_children();
158+
if ( $this->has_native_ast() ) {
159+
return wp_sqlite_mysql_native_ast_get_length( $this->native_ast, $this->native_node_index );
160+
}
129161
return parent::get_length();
130162
}
131163

0 commit comments

Comments
 (0)