Commit 390d1ce6 authored by Matthew Dempsky's avatar Matthew Dempsky

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/21219Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 7294ccb5
......@@ -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 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 {
nfs = append([]*Field(nil), fields...)
}
nfs[i] = f.Copy()
nfs[i].Type = nft
}
if nfs != nil {
t = t.Copy()
t.SetFields(nfs[:len(fields)])
t.SetFields(nfs)
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment