1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 12:48:10 +00:00

JSSpecCompiler: Elide nested TreeList nodes

This commit is contained in:
Dan Klishch 2023-09-13 01:28:11 -04:00 committed by Jelle Raaijmakers
parent f30815b534
commit 14a86c8fd6
4 changed files with 23 additions and 12 deletions

View file

@ -24,7 +24,7 @@ RecursionDecision IfBranchMergingPass::on_entry(Tree tree)
}
};
for (auto const& node : list->m_expressions) {
for (auto const& node : list->m_trees) {
if (is<IfBranch>(node.ptr())) {
merge_if_needed();
unmerged_branches.append(node);
@ -37,7 +37,7 @@ RecursionDecision IfBranchMergingPass::on_entry(Tree tree)
}
merge_if_needed();
list->m_expressions = move(result);
list->m_trees = move(result);
}
return RecursionDecision::Recurse;
}
@ -75,8 +75,8 @@ Tree IfBranchMergingPass::merge_branches(Vector<Tree> const& unmerged_branches)
// 3. Else,
// ...
auto substep_list = as<TreeList>(branch->m_branch);
if (substep_list && substep_list->m_expressions.size() == 1) {
if (auto nested_if = as<IfBranch>(substep_list->m_expressions[0]); nested_if)
if (substep_list && substep_list->m_trees.size() == 1) {
if (auto nested_if = as<IfBranch>(substep_list->m_trees[0]); nested_if)
branch = make_ref_counted<ElseIfBranch>(nested_if->m_condition, nested_if->m_branch);
}
}