From: Matthew Dempsky Date: Mon, 28 Mar 2016 16:32:10 +0000 (-0700) Subject: cmd/compile: simplify substAny's TSTRUCT case X-Git-Tag: go1.7beta1~1057 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=390d1ce686729dea40cee796ce391f9fd8466942;p=gostls13.git 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 Run-TryBot: Matthew Dempsky TryBot-Result: Gobot Gobot --- diff --git a/src/cmd/compile/internal/gc/subr.go b/src/cmd/compile/internal/gc/subr.go index 99f4a776a8..f72ea61ebb 100644 --- a/src/cmd/compile/internal/gc/subr.go +++ b/src/cmd/compile/internal/gc/subr.go @@ -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) } }