Skip to content

Commit fa5a7ba

Browse files
authored
Inline was_mutated flag on native parser node hot path (#390)
## Summary Drop the `was_mutated()` getter from `WP_MySQL_Native_Parser_Node` and read the property directly. The flag is checked on every read of a native-backed node, so a method call per access shows up on full-tree traversals. The naming still reads at the call sites (`if ( \$this->was_mutated )`), so we don't lose anything by inlining.
1 parent b6473ef commit fa5a7ba

1 file changed

Lines changed: 16 additions & 20 deletions

File tree

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

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -38,136 +38,132 @@ public function merge_fragment( $node ) {
3838

3939
/** @inheritDoc */
4040
public function has_child(): bool {
41-
if ( $this->was_mutated() ) {
41+
if ( $this->was_mutated ) {
4242
return parent::has_child();
4343
}
4444
return wp_sqlite_mysql_native_ast_has_child( $this->native_ast, $this->native_node_index );
4545
}
4646

4747
/** @inheritDoc */
4848
public function has_child_node( ?string $rule_name = null ): bool {
49-
if ( $this->was_mutated() ) {
49+
if ( $this->was_mutated ) {
5050
return parent::has_child_node( $rule_name );
5151
}
5252
return wp_sqlite_mysql_native_ast_has_child_node( $this->native_ast, $this->native_node_index, $rule_name );
5353
}
5454

5555
/** @inheritDoc */
5656
public function has_child_token( ?int $token_id = null ): bool {
57-
if ( $this->was_mutated() ) {
57+
if ( $this->was_mutated ) {
5858
return parent::has_child_token( $token_id );
5959
}
6060
return wp_sqlite_mysql_native_ast_has_child_token( $this->native_ast, $this->native_node_index, $token_id );
6161
}
6262

6363
/** @inheritDoc */
6464
public function get_first_child() {
65-
if ( $this->was_mutated() ) {
65+
if ( $this->was_mutated ) {
6666
return parent::get_first_child();
6767
}
6868
return wp_sqlite_mysql_native_ast_get_first_child( $this->native_ast, $this->native_node_index );
6969
}
7070

7171
/** @inheritDoc */
7272
public function get_first_child_node( ?string $rule_name = null ): ?WP_Parser_Node {
73-
if ( $this->was_mutated() ) {
73+
if ( $this->was_mutated ) {
7474
return parent::get_first_child_node( $rule_name );
7575
}
7676
return wp_sqlite_mysql_native_ast_get_first_child_node( $this->native_ast, $this->native_node_index, $rule_name );
7777
}
7878

7979
/** @inheritDoc */
8080
public function get_first_child_token( ?int $token_id = null ): ?WP_Parser_Token {
81-
if ( $this->was_mutated() ) {
81+
if ( $this->was_mutated ) {
8282
return parent::get_first_child_token( $token_id );
8383
}
8484
return wp_sqlite_mysql_native_ast_get_first_child_token( $this->native_ast, $this->native_node_index, $token_id );
8585
}
8686

8787
/** @inheritDoc */
8888
public function get_first_descendant_node( ?string $rule_name = null ): ?WP_Parser_Node {
89-
if ( $this->was_mutated() ) {
89+
if ( $this->was_mutated ) {
9090
return parent::get_first_descendant_node( $rule_name );
9191
}
9292
return wp_sqlite_mysql_native_ast_get_first_descendant_node( $this->native_ast, $this->native_node_index, $rule_name );
9393
}
9494

9595
/** @inheritDoc */
9696
public function get_first_descendant_token( ?int $token_id = null ): ?WP_Parser_Token {
97-
if ( $this->was_mutated() ) {
97+
if ( $this->was_mutated ) {
9898
return parent::get_first_descendant_token( $token_id );
9999
}
100100
return wp_sqlite_mysql_native_ast_get_first_descendant_token( $this->native_ast, $this->native_node_index, $token_id );
101101
}
102102

103103
/** @inheritDoc */
104104
public function get_children(): array {
105-
if ( $this->was_mutated() ) {
105+
if ( $this->was_mutated ) {
106106
return parent::get_children();
107107
}
108108
return wp_sqlite_mysql_native_ast_get_children( $this->native_ast, $this->native_node_index );
109109
}
110110

111111
/** @inheritDoc */
112112
public function get_child_nodes( ?string $rule_name = null ): array {
113-
if ( $this->was_mutated() ) {
113+
if ( $this->was_mutated ) {
114114
return parent::get_child_nodes( $rule_name );
115115
}
116116
return wp_sqlite_mysql_native_ast_get_child_nodes( $this->native_ast, $this->native_node_index, $rule_name );
117117
}
118118

119119
/** @inheritDoc */
120120
public function get_child_tokens( ?int $token_id = null ): array {
121-
if ( $this->was_mutated() ) {
121+
if ( $this->was_mutated ) {
122122
return parent::get_child_tokens( $token_id );
123123
}
124124
return wp_sqlite_mysql_native_ast_get_child_tokens( $this->native_ast, $this->native_node_index, $token_id );
125125
}
126126

127127
/** @inheritDoc */
128128
public function get_descendants(): array {
129-
if ( $this->was_mutated() ) {
129+
if ( $this->was_mutated ) {
130130
return parent::get_descendants();
131131
}
132132
return wp_sqlite_mysql_native_ast_get_descendants( $this->native_ast, $this->native_node_index );
133133
}
134134

135135
/** @inheritDoc */
136136
public function get_descendant_nodes( ?string $rule_name = null ): array {
137-
if ( $this->was_mutated() ) {
137+
if ( $this->was_mutated ) {
138138
return parent::get_descendant_nodes( $rule_name );
139139
}
140140
return wp_sqlite_mysql_native_ast_get_descendant_nodes( $this->native_ast, $this->native_node_index, $rule_name );
141141
}
142142

143143
/** @inheritDoc */
144144
public function get_descendant_tokens( ?int $token_id = null ): array {
145-
if ( $this->was_mutated() ) {
145+
if ( $this->was_mutated ) {
146146
return parent::get_descendant_tokens( $token_id );
147147
}
148148
return wp_sqlite_mysql_native_ast_get_descendant_tokens( $this->native_ast, $this->native_node_index, $token_id );
149149
}
150150

151151
/** @inheritDoc */
152152
public function get_start(): int {
153-
if ( $this->was_mutated() ) {
153+
if ( $this->was_mutated ) {
154154
return parent::get_start();
155155
}
156156
return wp_sqlite_mysql_native_ast_get_start( $this->native_ast, $this->native_node_index );
157157
}
158158

159159
/** @inheritDoc */
160160
public function get_length(): int {
161-
if ( $this->was_mutated() ) {
161+
if ( $this->was_mutated ) {
162162
return parent::get_length();
163163
}
164164
return wp_sqlite_mysql_native_ast_get_length( $this->native_ast, $this->native_node_index );
165165
}
166166

167-
private function was_mutated(): bool {
168-
return $this->was_mutated;
169-
}
170-
171167
private function materialize_native_children(): void {
172168
if ( $this->was_mutated ) {
173169
return;

0 commit comments

Comments
 (0)