cmd/compile: add Nodes.Prepend helper method

Prepared with gofmt -r.

Change-Id: Ib9f224cc20353acd9c5850dead1a2d32ca5427d3
Reviewed-on: https://go-review.googlesource.com/29165
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
Matthew Dempsky 2016-09-14 13:19:20 -07:00
parent 6f135bfd92
commit 4b8a1611b5
9 changed files with 30 additions and 16 deletions

View file

@ -583,15 +583,29 @@ func (n Nodes) Addr(i int) **Node {
// Append appends entries to Nodes.
// If a slice is passed in, this will take ownership of it.
func (n *Nodes) Append(a ...*Node) {
if len(a) == 0 {
return
}
if n.slice == nil {
if len(a) > 0 {
n.slice = &a
}
n.slice = &a
} else {
*n.slice = append(*n.slice, a...)
}
}
// Prepend prepends entries to Nodes.
// If a slice is passed in, this will take ownership of it.
func (n *Nodes) Prepend(a ...*Node) {
if len(a) == 0 {
return
}
if n.slice == nil {
n.slice = &a
} else {
*n.slice = append(a, *n.slice...)
}
}
// AppendNodes appends the contents of *n2 to n, then clears n2.
func (n *Nodes) AppendNodes(n2 *Nodes) {
switch {