File tree Expand file tree Collapse file tree 1 file changed +43
-22
lines changed Expand file tree Collapse file tree 1 file changed +43
-22
lines changed Original file line number Diff line number Diff line change @@ -1600,37 +1600,58 @@ not be called directly.
1600
1600
=cut
1601
1601
*/
1602
1602
1603
+
1603
1604
OP *
1604
1605
Perl_op_linklist(pTHX_ OP *o)
1605
1606
{
1607
+
1608
+ OP **prevp;
1609
+ OP *kid;
1610
+ OP * top_op = o;
1611
+
1606
1612
PERL_ARGS_ASSERT_OP_LINKLIST;
1607
1613
1608
- if (o->op_next)
1609
- return o->op_next;
1614
+ while (1) {
1615
+ /* Descend down the tree looking for any unprocessed subtrees to
1616
+ * do first */
1617
+ if (!o->op_next) {
1618
+ if (o->op_flags & OPf_KIDS) {
1619
+ o = cUNOPo->op_first;
1620
+ continue;
1621
+ }
1622
+ o->op_next = o; /* leaf node; link to self initially */
1623
+ }
1610
1624
1611
- /* establish postfix order */
1612
- if (o->op_flags & OPf_KIDS) {
1613
- OP *kid;
1614
- OP *first = cUNOPo->op_first;
1615
- o->op_next = LINKLIST(first);
1616
- kid = first;
1617
- for (;;) {
1618
- OP *sibl = OpSIBLING(kid);
1619
- if (sibl) {
1620
- kid->op_next = LINKLIST(sibl);
1621
- kid = sibl;
1622
- } else {
1623
- kid->op_next = o;
1624
- break;
1625
- }
1626
- }
1627
- }
1628
- else
1629
- o->op_next = o;
1625
+ /* if we're at the top level, there either weren't any children
1626
+ * to process, or we've worked our way back to the top. */
1627
+ if (o == top_op)
1628
+ return o->op_next;
1629
+
1630
+ /* o is now processed. Next, process any sibling subtrees */
1631
+
1632
+ if (OpHAS_SIBLING(o)) {
1633
+ o = OpSIBLING(o);
1634
+ continue;
1635
+ }
1636
+
1637
+ /* Done all the subtrees at this level. Go back up a level and
1638
+ * link the parent in with all its (processed) children.
1639
+ */
1630
1640
1631
- return o->op_next;
1641
+ o = o->op_sibparent;
1642
+ assert(!o->op_next);
1643
+ prevp = &(o->op_next);
1644
+ kid = (o->op_flags & OPf_KIDS) ? cUNOPo->op_first : NULL;
1645
+ while (kid) {
1646
+ *prevp = kid->op_next;
1647
+ prevp = &(kid->op_next);
1648
+ kid = OpSIBLING(kid);
1649
+ }
1650
+ *prevp = o;
1651
+ }
1632
1652
}
1633
1653
1654
+
1634
1655
static OP *
1635
1656
S_scalarkids(pTHX_ OP *o)
1636
1657
{
You can’t perform that action at this time.
0 commit comments