]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: eliminate IterParams
authorMatthew Dempsky <mdempsky@google.com>
Wed, 9 Mar 2016 01:45:55 +0000 (17:45 -0800)
committerMatthew Dempsky <mdempsky@google.com>
Wed, 9 Mar 2016 09:13:43 +0000 (09:13 +0000)
It's only used once, so just make the caller responsible for iterating
both the receiver and input params.

Change-Id: Icb34f3f0cf96e80fbe27f3f49d12eddc26599b92
Reviewed-on: https://go-review.googlesource.com/20454
Reviewed-by: Dave Cheney <dave@cheney.net>
src/cmd/compile/internal/gc/align.go
src/cmd/compile/internal/gc/type.go

index e11da5022afac6087c2d519435851627a2339e16..35c824b959a9d3de1fc95c7cc9ae0462a08fd919 100644 (file)
@@ -618,15 +618,11 @@ func typeinit() {
 func Argsize(t *Type) int {
        var w int64
 
-       for fp, ip := IterFields(t.Results()); fp != nil; fp = ip.Next() {
-               if x := fp.Width + fp.Type.Width; x > w {
-                       w = x
-               }
-       }
-
-       for fp, ip := IterParams(t); fp != nil; fp = ip.Next() {
-               if x := fp.Width + fp.Type.Width; x > w {
-                       w = x
+       for _, p := range recvParamsResults {
+               for f, it := IterFields(p(t)); f != nil; f = it.Next() {
+                       if x := f.Width + f.Type.Width; x > w {
+                               w = x
+                       }
                }
        }
 
index b18da81445008c06a0f30f946d2ace7c5e3a66ba..3fefe3d066f87602b824d9aebeb77027e685f970 100644 (file)
@@ -164,10 +164,10 @@ type Type struct {
        Lastfn *Node // for usefield
 }
 
-// Iter provides an abstraction for iterating across struct fields,
-// interface methods, and function parameters.
+// Iter provides an abstraction for iterating across struct fields and
+// interface methods.
 type Iter struct {
-       a, b *Type
+       x *Type
 }
 
 // IterFields returns the first field or method in struct or interface type t
@@ -176,35 +176,21 @@ func IterFields(t *Type) (*Type, Iter) {
        if t.Etype != TSTRUCT && t.Etype != TINTER {
                Fatalf("IterFields: type %v does not have fields", t)
        }
-       i := Iter{a: t.Type}
+       i := Iter{x: t.Type}
        f := i.Next()
        return f, i
 }
 
-// IterParams returns the first reeiver or input parameter in function type t
-// and an Iter value to continue iterating across the rest.
-func IterParams(t *Type) (*Type, Iter) {
-       if t.Etype != TFUNC {
-               Fatalf("IterParams: type %v does not have params", t)
-       }
-       i := Iter{a: t.Recv().Type, b: t.Params().Type}
-       f := i.Next()
-       return f, i
-}
-
-// Next returns the next field, method, or parameter, if any.
+// Next returns the next field or method, if any.
 func (i *Iter) Next() *Type {
-       if i.a == nil {
-               if i.b == nil {
-                       return nil
-               }
-               i.a, i.b = i.b, nil
+       if i.x == nil {
+               return nil
        }
-       t := i.a
+       t := i.x
        if t.Etype != TFIELD {
                Fatalf("Iter.Next: type %v is not a field", t)
        }
-       i.a = t.Down
+       i.x = t.Down
        return t
 }
 
@@ -233,6 +219,13 @@ func (t *Type) Recv() *Type    { return *t.RecvP() }
 func (t *Type) Params() *Type  { return *t.ParamsP() }
 func (t *Type) Results() *Type { return *t.ResultsP() }
 
+// recvParamsResults stores the accessor functions for a function Type's
+// receiver, parameters, and result parameters, in that order.
+// It can be used to iterate over all of a function's parameter lists.
+var recvParamsResults = [3]func(*Type) *Type{
+       (*Type).Recv, (*Type).Params, (*Type).Results,
+}
+
 func (t *Type) Size() int64 {
        dowidth(t)
        return t.Width