]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: simplify substAny's TSTRUCT case
authorMatthew Dempsky <mdempsky@google.com>
Mon, 28 Mar 2016 16:32:10 +0000 (09:32 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Mon, 28 Mar 2016 21:07:05 +0000 (21:07 +0000)
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>

src/cmd/compile/internal/gc/subr.go

index 99f4a776a81b99a2f49875e1d22846bdec1ef082..f72ea61ebbaf4732aaa9866ac0278da19e1a9183 100644 (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 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)
                }
        }