mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
mruby-compiler: optimize NODE_STMTS nesting to reduce AST depth
Modify new_stmts to flatten unnecessary nesting by returning existing NODE_STMTS directly instead of wrapping them. This reduces memory usage and AST complexity when multiple parentheses levels are used. Before: (((expr1; expr2))) creates nested NODE_STMTS After: (((expr1; expr2))) creates single NODE_STMTS with statements Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -385,6 +385,10 @@ static node*
|
||||
new_stmts(parser_state *p, node *body)
|
||||
{
|
||||
if (body) {
|
||||
/* If body is already a NODE_STMTS, just return it directly */
|
||||
if (typen(body->car) == NODE_STMTS) {
|
||||
return body;
|
||||
}
|
||||
return list2((node*)NODE_STMTS, body);
|
||||
}
|
||||
return cons((node*)NODE_STMTS, 0);
|
||||
|
||||
Reference in New Issue
Block a user