From: Dave Cheney Date: Wed, 30 Mar 2016 23:30:04 +0000 (+1100) Subject: cmd/compile/internal/gc: don't iterate over field list twice X-Git-Tag: go1.7beta1~1000 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=0373128318f0a64ea0c8e1a156d69d2cacbd2591;p=gostls13.git cmd/compile/internal/gc: don't iterate over field list twice In tostruct0 and tofunargs we take a list of nodes, transform them into a slice of Fields, set the fields on a type, then use the IterFields iterator to iterate over the list again to see if any of them are broken. As we know the slice of fielde-we just created it-we can combine these two interations into one pass over the fields. Change-Id: I8b04c90fb32fd6c3b1752cfc607128a634ee06c5 Reviewed-on: https://go-review.googlesource.com/21350 Reviewed-by: Matthew Dempsky Reviewed-by: Brad Fitzpatrick --- diff --git a/src/cmd/compile/internal/gc/dcl.go b/src/cmd/compile/internal/gc/dcl.go index f107a4e284..7adaa0ea2d 100644 --- a/src/cmd/compile/internal/gc/dcl.go +++ b/src/cmd/compile/internal/gc/dcl.go @@ -819,15 +819,13 @@ func tostruct0(t *Type, l []*Node) { var fields []*Field for _, n := range l { - fields = append(fields, structfield(n)) - } - t.SetFields(fields) - - for f, it := IterFields(t); f != nil && !t.Broke; f = it.Next() { + f := structfield(n) if f.Broke { t.Broke = true } + fields = append(fields, f) } + t.SetFields(fields) checkdupfields("field", t) @@ -849,17 +847,12 @@ func tofunargs(l []*Node) *Type { if n.Left != nil && n.Left.Class == PPARAM { n.Left.Name.Param.Field = f } - - fields = append(fields, f) - } - t.SetFields(fields) - - for f, it := IterFields(t); f != nil && !t.Broke; f = it.Next() { if f.Broke { t.Broke = true } + fields = append(fields, f) } - + t.SetFields(fields) return t }