Skip to content

Commit a81283d

Browse files
committed
cmd/compile: inline list storage stealing
It is only necessary in a few places, and this inlining will simplify the transition away from NodeLists. Passes toolstash -cmp. Change-Id: I4ee9b4bf56ffa04df23e20a0a83b302d36b33510 Reviewed-on: https://go-review.googlesource.com/20290 Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent b8a2e25 commit a81283d

File tree

2 files changed

+16
-30
lines changed

2 files changed

+16
-30
lines changed

src/cmd/compile/internal/gc/parser.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,11 @@ func (p *parser) labeled_stmt(label *Node) *Node {
684684
label.Name.Defn = ls
685685
l := list1(label)
686686
if ls != nil {
687-
l = list(l, ls)
687+
if ls.Op == OBLOCK && nodeSeqLen(ls.Ninit) == 0 {
688+
l = concat(l, ls.List)
689+
} else {
690+
l = list(l, ls)
691+
}
688692
}
689693
return liststmt(l)
690694
}
@@ -1043,7 +1047,12 @@ func (p *parser) if_stmt() *Node {
10431047
if p.tok == LIF {
10441048
setNodeSeq(&stmt.Rlist, []*Node{p.if_stmt()})
10451049
} else {
1046-
setNodeSeq(&stmt.Rlist, []*Node{p.compound_stmt(true)})
1050+
cs := p.compound_stmt(true)
1051+
if cs.Op == OBLOCK && cs.Ninit == nil {
1052+
setNodeSeq(&stmt.Rlist, cs.List)
1053+
} else {
1054+
setNodeSeq(&stmt.Rlist, []*Node{cs})
1055+
}
10471056
}
10481057
}
10491058

@@ -2538,7 +2547,11 @@ func (p *parser) stmt_list() (l *NodeList) {
25382547
if s == missing_stmt {
25392548
break
25402549
}
2541-
l = list(l, s)
2550+
if s != nil && s.Op == OBLOCK && nodeSeqLen(s.Ninit) == 0 {
2551+
l = concat(l, s.List)
2552+
} else {
2553+
l = list(l, s)
2554+
}
25422555
// customized version of osemi:
25432556
// ';' is optional before a closing ')' or '}'
25442557
if p.tok == ')' || p.tok == '}' {

src/cmd/compile/internal/gc/syntax.go

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -391,15 +391,6 @@ func list1(n *Node) *NodeList {
391391
if n == nil {
392392
return nil
393393
}
394-
if n.Op == OBLOCK && nodeSeqLen(n.Ninit) == 0 {
395-
// Flatten list and steal storage.
396-
// Poison pointer to catch errant uses.
397-
l := n.List
398-
399-
setNodeSeq(&n.List, nil)
400-
return l
401-
}
402-
403394
l := new(NodeList)
404395
l.N = n
405396
l.End = l
@@ -741,15 +732,6 @@ func setNodeSeq(a nodesOrNodeListPtr, b nodesOrNodeList) {
741732
// This is an interim function during the transition from NodeList to Nodes.
742733
// TODO(iant): Remove when transition is complete.
743734
func setNodeSeqNode(a nodesOrNodeListPtr, n *Node) {
744-
// This is what the old list1 function did;
745-
// the rest of the compiler has come to expect it.
746-
if n.Op == OBLOCK && nodeSeqLen(n.Ninit) == 0 {
747-
l := n.List
748-
setNodeSeq(&n.List, nil)
749-
setNodeSeq(a, l)
750-
return
751-
}
752-
753735
switch a := a.(type) {
754736
case **NodeList:
755737
*a = list1(n)
@@ -822,15 +804,6 @@ func appendNodeSeq(a nodesOrNodeListPtr, b nodesOrNodeList) {
822804
// This is an interim function during the transition from NodeList to Nodes.
823805
// TODO(iant): Remove when transition is complete.
824806
func appendNodeSeqNode(a nodesOrNodeListPtr, n *Node) {
825-
// This is what the old list1 function did;
826-
// the rest of the compiler has come to expect it.
827-
if n.Op == OBLOCK && nodeSeqLen(n.Ninit) == 0 {
828-
l := n.List
829-
setNodeSeq(&n.List, nil)
830-
appendNodeSeq(a, l)
831-
return
832-
}
833-
834807
switch a := a.(type) {
835808
case **NodeList:
836809
*a = list(*a, n)

0 commit comments

Comments
 (0)