Skip to content

Commit 1c4cbcf

Browse files
committed
Cache native AST child materialization
1 parent 0d25340 commit 1c4cbcf

1 file changed

Lines changed: 16 additions & 48 deletions

File tree

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

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

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

4442
/** @inheritDoc */
4543
public function has_child_node( ?string $rule_name = null ): bool {
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-
}
44+
$this->materialize_native_children();
4945
return parent::has_child_node( $rule_name );
5046
}
5147

5248
/** @inheritDoc */
5349
public function has_child_token( ?int $token_id = null ): bool {
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-
}
50+
$this->materialize_native_children();
5751
return parent::has_child_token( $token_id );
5852
}
5953

6054
/** @inheritDoc */
6155
public function get_first_child() {
62-
if ( $this->has_native_ast() ) {
63-
return wp_sqlite_mysql_native_ast_get_first_child( $this->native_ast, $this->native_node_index );
64-
}
56+
$this->materialize_native_children();
6557
return parent::get_first_child();
6658
}
6759

6860
/** @inheritDoc */
6961
public function get_first_child_node( ?string $rule_name = null ): ?WP_Parser_Node {
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-
}
62+
$this->materialize_native_children();
7363
return parent::get_first_child_node( $rule_name );
7464
}
7565

7666
/** @inheritDoc */
7767
public function get_first_child_token( ?int $token_id = null ): ?WP_Parser_Token {
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-
}
68+
$this->materialize_native_children();
8169
return parent::get_first_child_token( $token_id );
8270
}
8371

8472
/** @inheritDoc */
8573
public function get_first_descendant_node( ?string $rule_name = null ): ?WP_Parser_Node {
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-
}
74+
$this->materialize_native_children();
8975
return parent::get_first_descendant_node( $rule_name );
9076
}
9177

9278
/** @inheritDoc */
9379
public function get_first_descendant_token( ?int $token_id = null ): ?WP_Parser_Token {
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-
}
80+
$this->materialize_native_children();
9781
return parent::get_first_descendant_token( $token_id );
9882
}
9983

10084
/** @inheritDoc */
10185
public function get_children(): array {
102-
if ( $this->has_native_ast() ) {
103-
return wp_sqlite_mysql_native_ast_get_children( $this->native_ast, $this->native_node_index );
104-
}
86+
$this->materialize_native_children();
10587
return parent::get_children();
10688
}
10789

10890
/** @inheritDoc */
10991
public function get_child_nodes( ?string $rule_name = null ): array {
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-
}
92+
$this->materialize_native_children();
11393
return parent::get_child_nodes( $rule_name );
11494
}
11595

11696
/** @inheritDoc */
11797
public function get_child_tokens( ?int $token_id = null ): array {
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-
}
98+
$this->materialize_native_children();
12199
return parent::get_child_tokens( $token_id );
122100
}
123101

124102
/** @inheritDoc */
125103
public function get_descendants(): array {
126-
if ( $this->has_native_ast() ) {
127-
return wp_sqlite_mysql_native_ast_get_descendants( $this->native_ast, $this->native_node_index );
128-
}
104+
$this->materialize_native_children();
129105
return parent::get_descendants();
130106
}
131107

132108
/** @inheritDoc */
133109
public function get_descendant_nodes( ?string $rule_name = null ): array {
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-
}
110+
$this->materialize_native_children();
137111
return parent::get_descendant_nodes( $rule_name );
138112
}
139113

140114
/** @inheritDoc */
141115
public function get_descendant_tokens( ?int $token_id = null ): array {
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-
}
116+
$this->materialize_native_children();
145117
return parent::get_descendant_tokens( $token_id );
146118
}
147119

148120
/** @inheritDoc */
149121
public function get_start(): int {
150-
if ( $this->has_native_ast() ) {
151-
return wp_sqlite_mysql_native_ast_get_start( $this->native_ast, $this->native_node_index );
152-
}
122+
$this->materialize_native_children();
153123
return parent::get_start();
154124
}
155125

156126
/** @inheritDoc */
157127
public function get_length(): int {
158-
if ( $this->has_native_ast() ) {
159-
return wp_sqlite_mysql_native_ast_get_length( $this->native_ast, $this->native_node_index );
160-
}
128+
$this->materialize_native_children();
161129
return parent::get_length();
162130
}
163131

0 commit comments

Comments
 (0)