Skip to content

Commit b07d16f

Browse files
committed
Add lazy native parser node facade
When a native parser is in use, expose query results through a node class that defers child materialization until callers actually walk the tree. The base WP_Parser_Node::$children visibility is loosened to protected so the facade can populate it on demand.
1 parent de82273 commit b07d16f

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111
* children are never materialized into PHP arrays unless something actually
1212
* asks for them.
1313
*
14-
* Read methods eagerly call `materialize_native_children()` — once the
15-
* children have been copied into PHP, `was_mutated()` returns true and the
16-
* call falls through to the parent implementation. The `was_mutated` flag is
17-
* NOT a runtime check for whether the native extension is loaded — if this
18-
* class is in use, the extension is loaded by definition. It tracks whether
19-
* THIS specific node has had its children pulled into the inherited
20-
* `$children` array (which happens on first read or first mutation via
21-
* `append_child()` / `merge_fragment()`). From that point on, the node is a
22-
* plain PHP-backed `WP_Parser_Node`.
14+
* The hedge in those methods (`if ( $this->was_mutated() )`) is NOT a runtime
15+
* check for whether the native extension is loaded — if this class is in use,
16+
* the extension is loaded by definition. It checks whether THIS specific node
17+
* has been mutated from PHP. A node loses its native backing the first time
18+
* `append_child()` or `merge_fragment()` is called on it: those overrides
19+
* invoke `materialize_native_children()`, which copies the native children
20+
* into the inherited `$children` array and drops the native AST reference.
21+
* From that point on, the node is a plain PHP-backed `WP_Parser_Node` and the
22+
* read methods fall through to the parent implementation.
2323
*
2424
* Mutation from PHP is real and intentional — query rewriters in
2525
* `WP_PDO_MySQL_On_SQLite` (e.g. building synthetic `count(*)` expressions)

0 commit comments

Comments
 (0)