mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/compile: change Func.{Enter,Exit} from NodeList to slice
Introduces a new types Nodes that can be used to replace NodeList. Update #14473. Change-Id: Id77c5dcae0cbeb898ba12dd46bd400aad408871c Reviewed-on: https://go-review.googlesource.com/19969 Reviewed-by: David Crawshaw <crawshaw@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
parent
6520da6ed5
commit
188e3d2515
9 changed files with 157 additions and 44 deletions
|
|
@ -149,8 +149,8 @@ type Param struct {
|
|||
// Func holds Node fields used only with function-like nodes.
|
||||
type Func struct {
|
||||
Shortname *Node
|
||||
Enter *NodeList
|
||||
Exit *NodeList
|
||||
Enter Nodes
|
||||
Exit Nodes
|
||||
cvars *[]*Node // closure params
|
||||
Dcl []*Node // autodcl for this func/closure
|
||||
Inldcl *[]*Node // copy of dcl for use in inlining
|
||||
|
|
@ -506,3 +506,55 @@ func count(l *NodeList) int {
|
|||
}
|
||||
return int(n)
|
||||
}
|
||||
|
||||
// Nodes is a pointer to a slice of *Node.
|
||||
// For fields that are not used in most nodes, this is used instead of
|
||||
// a slice to save space.
|
||||
type Nodes struct{ slice *[]*Node }
|
||||
|
||||
// Slice returns the entries in Nodes as a slice.
|
||||
// Changes to the slice entries (as in s[i] = n) will be reflected in
|
||||
// the Nodes.
|
||||
func (n *Nodes) Slice() []*Node {
|
||||
if n.slice == nil {
|
||||
return nil
|
||||
}
|
||||
return *n.slice
|
||||
}
|
||||
|
||||
// NodeList returns the entries in Nodes as a NodeList.
|
||||
// Changes to the NodeList entries (as in l.N = n) will *not* be
|
||||
// reflect in the Nodes.
|
||||
// This wastes memory and should be used as little as possible.
|
||||
func (n *Nodes) NodeList() *NodeList {
|
||||
if n.slice == nil {
|
||||
return nil
|
||||
}
|
||||
var ret *NodeList
|
||||
for _, n := range *n.slice {
|
||||
ret = list(ret, n)
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
// Set sets Nodes to a slice.
|
||||
// This takes ownership of the slice.
|
||||
func (n *Nodes) Set(s []*Node) {
|
||||
if len(s) == 0 {
|
||||
n.slice = nil
|
||||
} else {
|
||||
n.slice = &s
|
||||
}
|
||||
}
|
||||
|
||||
// Append appends entries to Nodes.
|
||||
// If a slice is passed in, this will take ownership of it.
|
||||
func (n *Nodes) Append(a ...*Node) {
|
||||
if n.slice == nil {
|
||||
if len(a) > 0 {
|
||||
n.slice = &a
|
||||
}
|
||||
} else {
|
||||
*n.slice = append(*n.slice, a...)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue