cmd/compile: change Node.Nbody, Func.Inl from *NodeList to Nodes
Passes toolstash -cmp.
Casual timings show about a 3% improvement in compile times.
Update #14473.
Change-Id: I584add2e8f1a52486ba418b25ba6122b7347b643
Reviewed-on: https://go-review.googlesource.com/19989
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
diff --git a/src/cmd/compile/internal/gc/swt.go b/src/cmd/compile/internal/gc/swt.go
index 661b3ee..6e74349 100644
--- a/src/cmd/compile/internal/gc/swt.go
+++ b/src/cmd/compile/internal/gc/swt.go
@@ -181,7 +181,7 @@
}
}
- typechecklist(ncase.Nbody, Etop)
+ typecheckslice(ncase.Nbody.Slice(), Etop)
}
lineno = int32(lno)
@@ -230,7 +230,7 @@
}
// convert the switch into OIF statements
- var cas *NodeList
+ var cas []*Node
if s.kind == switchKindTrue || s.kind == switchKindFalse {
s.exprname = Nodbool(s.kind == switchKindTrue)
} else if consttype(cond) >= 0 {
@@ -238,8 +238,8 @@
s.exprname = cond
} else {
s.exprname = temp(cond.Type)
- cas = list1(Nod(OAS, s.exprname, cond))
- typechecklist(cas, Etop)
+ cas = []*Node{Nod(OAS, s.exprname, cond)}
+ typecheckslice(cas, Etop)
}
// enumerate the cases, and lop off the default case
@@ -258,7 +258,7 @@
// deal with expressions one at a time
if !okforcmp[t.Etype] || cc[0].typ != caseKindExprConst {
a := s.walkCases(cc[:1])
- cas = list(cas, a)
+ cas = append(cas, a)
cc = cc[1:]
continue
}
@@ -271,15 +271,15 @@
// sort and compile constants
sort.Sort(caseClauseByExpr(cc[:run]))
a := s.walkCases(cc[:run])
- cas = list(cas, a)
+ cas = append(cas, a)
cc = cc[run:]
}
// handle default case
if nerrors == 0 {
- cas = list(cas, def)
- sw.Nbody = concat(cas, sw.Nbody)
- walkstmtlist(sw.Nbody)
+ cas = append(cas, def)
+ sw.Nbody.Set(append(cas, sw.Nbody.Slice()...))
+ walkstmtslice(sw.Nbody.Slice())
}
}
@@ -303,7 +303,7 @@
a.Left = Nod(ONOT, n.Left, nil) // if !val
typecheck(&a.Left, Erv)
}
- a.Nbody = list1(n.Right) // goto l
+ a.Nbody.Set([]*Node{n.Right}) // goto l
cas = list(cas, a)
lineno = int32(lno)
@@ -325,7 +325,7 @@
a.Left = le
}
typecheck(&a.Left, Erv)
- a.Nbody = list1(s.walkCases(cc[:half]))
+ a.Nbody.Set([]*Node{s.walkCases(cc[:half])})
a.Rlist = list1(s.walkCases(cc[half:]))
return a
}
@@ -340,9 +340,9 @@
lno := setlineno(sw)
- var cas *NodeList // cases
- var stat *NodeList // statements
- var def *Node // defaults
+ var cas *NodeList // cases
+ var stat []*Node // statements
+ var def *Node // defaults
br := Nod(OBREAK, nil, nil)
for l := sw.List; l != nil; l = l.Next {
@@ -377,17 +377,19 @@
}
}
- stat = list(stat, Nod(OLABEL, jmp.Left, nil))
+ stat = append(stat, Nod(OLABEL, jmp.Left, nil))
if typeswvar != nil && needvar && n.Rlist != nil {
- l := list1(Nod(ODCL, n.Rlist.N, nil))
- l = list(l, Nod(OAS, n.Rlist.N, typeswvar))
- typechecklist(l, Etop)
- stat = concat(stat, l)
+ l := []*Node{
+ Nod(ODCL, n.Rlist.N, nil),
+ Nod(OAS, n.Rlist.N, typeswvar),
+ }
+ typecheckslice(l, Etop)
+ stat = append(stat, l...)
}
- stat = concat(stat, n.Nbody)
+ stat = append(stat, n.Nbody.Slice()...)
// botch - shouldn't fall thru declaration
- last := stat.End.N
+ last := stat[len(stat)-1]
if last.Xoffset == n.Xoffset && last.Op == OXFALL {
if typeswvar != nil {
setlineno(last)
@@ -401,17 +403,17 @@
last.Op = OFALL
} else {
- stat = list(stat, br)
+ stat = append(stat, br)
}
}
- stat = list(stat, br)
+ stat = append(stat, br)
if def != nil {
cas = list(cas, def)
}
sw.List = cas
- sw.Nbody = stat
+ sw.Nbody.Set(stat)
lineno = lno
}
@@ -531,14 +533,14 @@
return
}
- var cas *NodeList
+ var cas []*Node
// predeclare temporary variables and the boolean var
s.facename = temp(cond.Right.Type)
a := Nod(OAS, s.facename, cond.Right)
typecheck(&a, Etop)
- cas = list(cas, a)
+ cas = append(cas, a)
s.okname = temp(Types[TBOOL])
typecheck(&s.okname, Erv)
@@ -579,18 +581,18 @@
i.Left = Nod(OEQ, typ, nodnil())
if typenil != nil {
// Do explicit nil case right here.
- i.Nbody = list1(typenil)
+ i.Nbody.Set([]*Node{typenil})
} else {
// Jump to default case.
lbl := newCaseLabel()
- i.Nbody = list1(Nod(OGOTO, lbl, nil))
+ i.Nbody.Set([]*Node{Nod(OGOTO, lbl, nil)})
// Wrap default case with label.
blk := Nod(OBLOCK, nil, nil)
blk.List = list(list1(Nod(OLABEL, lbl, nil)), def)
def = blk
}
typecheck(&i.Left, Erv)
- cas = list(cas, i)
+ cas = append(cas, i)
if !isnilinter(cond.Right.Type) {
// Load type from itab.
@@ -608,7 +610,7 @@
h.Bounded = true // guaranteed not to fault
a = Nod(OAS, s.hashname, h)
typecheck(&a, Etop)
- cas = list(cas, a)
+ cas = append(cas, a)
// insert type equality check into each case block
for _, c := range cc {
@@ -625,7 +627,7 @@
for len(cc) > 0 {
if cc[0].typ != caseKindTypeConst {
n := cc[0].node
- cas = list(cas, n.Right)
+ cas = append(cas, n.Right)
cc = cc[1:]
continue
}
@@ -642,7 +644,7 @@
if false {
for i := 0; i < run; i++ {
n := cc[i].node
- cas = list(cas, n.Right)
+ cas = append(cas, n.Right)
}
continue
}
@@ -659,16 +661,16 @@
}
// binary search among cases to narrow by hash
- cas = list(cas, s.walkCases(cc[:ncase]))
+ cas = append(cas, s.walkCases(cc[:ncase]))
cc = cc[ncase:]
}
// handle default case
if nerrors == 0 {
- cas = list(cas, def)
- sw.Nbody = concat(cas, sw.Nbody)
+ cas = append(cas, def)
+ sw.Nbody.Set(append(cas, sw.Nbody.Slice()...))
sw.List = nil
- walkstmtlist(sw.Nbody)
+ walkstmtslice(sw.Nbody.Slice())
}
}
@@ -698,7 +700,7 @@
c := Nod(OIF, nil, nil)
c.Left = s.okname
- c.Nbody = list1(t.Right) // if ok { goto l }
+ c.Nbody.Set([]*Node{t.Right}) // if ok { goto l }
return liststmt(list(init, c))
}
@@ -715,7 +717,7 @@
a := Nod(OIF, nil, nil)
a.Left = Nod(OEQ, s.hashname, Nodintconst(int64(c.hash)))
typecheck(&a.Left, Erv)
- a.Nbody = list1(n.Right)
+ a.Nbody.Set([]*Node{n.Right})
cas = list(cas, a)
}
return liststmt(cas)
@@ -726,7 +728,7 @@
a := Nod(OIF, nil, nil)
a.Left = Nod(OLE, s.hashname, Nodintconst(int64(cc[half-1].hash)))
typecheck(&a.Left, Erv)
- a.Nbody = list1(s.walkCases(cc[:half]))
+ a.Nbody.Set([]*Node{s.walkCases(cc[:half])})
a.Rlist = list1(s.walkCases(cc[half:]))
return a
}