]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: inline list storage stealing
authorJosh Bleecher Snyder <josharian@gmail.com>
Sun, 6 Mar 2016 00:25:58 +0000 (16:25 -0800)
committerJosh Bleecher Snyder <josharian@gmail.com>
Mon, 7 Mar 2016 23:05:05 +0000 (23:05 +0000)
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 <iant@golang.org>
src/cmd/compile/internal/gc/parser.go
src/cmd/compile/internal/gc/syntax.go

index 5c68336a33efb6d6c8a4191f7d680d1293ea7b67..66804e49a97385a857a661bc01e766990bf9aed4 100644 (file)
@@ -684,7 +684,11 @@ func (p *parser) labeled_stmt(label *Node) *Node {
        label.Name.Defn = ls
        l := list1(label)
        if ls != nil {
-               l = list(l, ls)
+               if ls.Op == OBLOCK && nodeSeqLen(ls.Ninit) == 0 {
+                       l = concat(l, ls.List)
+               } else {
+                       l = list(l, ls)
+               }
        }
        return liststmt(l)
 }
@@ -1043,7 +1047,12 @@ func (p *parser) if_stmt() *Node {
                if p.tok == LIF {
                        setNodeSeq(&stmt.Rlist, []*Node{p.if_stmt()})
                } else {
-                       setNodeSeq(&stmt.Rlist, []*Node{p.compound_stmt(true)})
+                       cs := p.compound_stmt(true)
+                       if cs.Op == OBLOCK && cs.Ninit == nil {
+                               setNodeSeq(&stmt.Rlist, cs.List)
+                       } else {
+                               setNodeSeq(&stmt.Rlist, []*Node{cs})
+                       }
                }
        }
 
@@ -2538,7 +2547,11 @@ func (p *parser) stmt_list() (l *NodeList) {
                if s == missing_stmt {
                        break
                }
-               l = list(l, s)
+               if s != nil && s.Op == OBLOCK && nodeSeqLen(s.Ninit) == 0 {
+                       l = concat(l, s.List)
+               } else {
+                       l = list(l, s)
+               }
                // customized version of osemi:
                // ';' is optional before a closing ')' or '}'
                if p.tok == ')' || p.tok == '}' {
index 868b40eaf38b3e18d8c4223cfe2153b3c3a074de..7aec6ae7de4985bc2e604f3d7fb41a05a3b53caf 100644 (file)
@@ -391,15 +391,6 @@ func list1(n *Node) *NodeList {
        if n == nil {
                return nil
        }
-       if n.Op == OBLOCK && nodeSeqLen(n.Ninit) == 0 {
-               // Flatten list and steal storage.
-               // Poison pointer to catch errant uses.
-               l := n.List
-
-               setNodeSeq(&n.List, nil)
-               return l
-       }
-
        l := new(NodeList)
        l.N = n
        l.End = l
@@ -741,15 +732,6 @@ func setNodeSeq(a nodesOrNodeListPtr, b nodesOrNodeList) {
 // This is an interim function during the transition from NodeList to Nodes.
 // TODO(iant): Remove when transition is complete.
 func setNodeSeqNode(a nodesOrNodeListPtr, n *Node) {
-       // This is what the old list1 function did;
-       // the rest of the compiler has come to expect it.
-       if n.Op == OBLOCK && nodeSeqLen(n.Ninit) == 0 {
-               l := n.List
-               setNodeSeq(&n.List, nil)
-               setNodeSeq(a, l)
-               return
-       }
-
        switch a := a.(type) {
        case **NodeList:
                *a = list1(n)
@@ -822,15 +804,6 @@ func appendNodeSeq(a nodesOrNodeListPtr, b nodesOrNodeList) {
 // This is an interim function during the transition from NodeList to Nodes.
 // TODO(iant): Remove when transition is complete.
 func appendNodeSeqNode(a nodesOrNodeListPtr, n *Node) {
-       // This is what the old list1 function did;
-       // the rest of the compiler has come to expect it.
-       if n.Op == OBLOCK && nodeSeqLen(n.Ninit) == 0 {
-               l := n.List
-               setNodeSeq(&n.List, nil)
-               appendNodeSeq(a, l)
-               return
-       }
-
        switch a := a.(type) {
        case **NodeList:
                *a = list(*a, n)