1
0
mirror of https://github.com/golang/go synced 2024-11-11 23:20:24 -07:00

cmd/compile: simplify substAny's TSTRUCT case

Now that structs use a slice to store their fields, this code can be
simplified somewhat.

Passes toolstash -cmp.

Change-Id: If17b1c89871fa06f34938fa67df0f8c6bcf1a86b
Reviewed-on: https://go-review.googlesource.com/21219
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Matthew Dempsky 2016-03-28 09:32:10 -07:00
parent 7294ccb54e
commit 390d1ce686

View File

@ -1147,38 +1147,22 @@ func substAny(t *Type, types *[]*Type) *Type {
}
case TSTRUCT:
// nfs only has to be big enough for the builtin functions.
var nfs [8]*Field
fields := t.FieldSlice()
changed := false
var nfs []*Field
for i, f := range fields {
nft := substAny(f.Type, types)
if nft != f.Type {
nfs[i] = f.Copy()
nfs[i].Type = nft
changed = true
if nft == f.Type {
continue
}
if nfs == nil {
nfs = append([]*Field(nil), fields...)
}
nfs[i] = f.Copy()
nfs[i].Type = nft
}
if changed {
// Above we've initialized nfs with copied fields
// whenever the field type changed. However, because
// we keep fields in a linked list, we can only safely
// share the unmodified tail of the list. We need to
// copy the rest.
tail := true
for i := len(fields) - 1; i >= 0; i-- {
if nfs[i] != nil {
tail = false
} else if tail {
nfs[i] = fields[i]
} else {
nfs[i] = fields[i].Copy()
}
}
if nfs != nil {
t = t.Copy()
t.SetFields(nfs[:len(fields)])
t.SetFields(nfs)
}
}