]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: eliminate NumFields wrapper functions
authorMatthew Dempsky <mdempsky@google.com>
Thu, 17 Mar 2016 20:26:08 +0000 (13:26 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Thu, 17 Mar 2016 20:43:18 +0000 (20:43 +0000)
Change-Id: I3c6035559288cfdc33857216f50241b81932c8a4
Reviewed-on: https://go-review.googlesource.com/20811
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/cmd/compile/internal/gc/bexport.go
src/cmd/compile/internal/gc/dcl.go
src/cmd/compile/internal/gc/sinit.go
src/cmd/compile/internal/gc/ssa.go
src/cmd/compile/internal/gc/subr.go
src/cmd/compile/internal/gc/type.go
src/cmd/compile/internal/gc/typecheck.go
src/cmd/compile/internal/gc/walk.go

index d6f3a51a44379a9a8adae46daf0e5e1f15e42489..7e5dbb0dd09e739b067802266b8053172a8f413e 100644 (file)
@@ -559,12 +559,12 @@ func (p *exporter) qualifiedName(sym *Sym) {
 }
 
 func (p *exporter) fieldList(t *Type) {
-       if p.trace && countfield(t) > 0 {
+       if p.trace && t.NumFields() > 0 {
                p.tracef("fields {>")
                defer p.tracef("<\n} ")
        }
 
-       p.int(countfield(t))
+       p.int(t.NumFields())
        for _, f := range t.Fields().Slice() {
                if p.trace {
                        p.tracef("\n")
@@ -588,12 +588,12 @@ func (p *exporter) note(n *string) {
 }
 
 func (p *exporter) methodList(t *Type) {
-       if p.trace && countfield(t) > 0 {
+       if p.trace && t.NumFields() > 0 {
                p.tracef("methods {>")
                defer p.tracef("<\n} ")
        }
 
-       p.int(countfield(t))
+       p.int(t.NumFields())
        for _, m := range t.Fields().Slice() {
                if p.trace {
                        p.tracef("\n")
@@ -650,7 +650,7 @@ func (p *exporter) paramList(params *Type, numbered bool) {
        // use negative length to indicate unnamed parameters
        // (look at the first parameter only since either all
        // names are present or all are absent)
-       n := countfield(params)
+       n := params.NumFields()
        if n > 0 && parName(params.Field(0), numbered) == "" {
                n = -n
        }
index 8b05cdb23ae5a2b30ba0364d0fbd3def98eba222..57698ce8398ecaf782eccebdfea0d6e0a4aa5621 100644 (file)
@@ -1030,7 +1030,7 @@ func isifacemethod(f *Type) bool {
                return false
        }
        t = t.Type
-       if t.Sym != nil || t.Etype != TSTRUCT || countfield(t) != 0 {
+       if t.Sym != nil || t.Etype != TSTRUCT || t.NumFields() != 0 {
                return false
        }
        return true
index ca5d35e87faa92a3b0d8b7201e2658bfba58552a..7f0b98c180009c7f1a2ba436a98c03d368bdf337 100644 (file)
@@ -1071,7 +1071,7 @@ func anylit(ctxt int, n *Node, var_ *Node, init *Nodes) {
                }
 
                // initialize of not completely specified
-               if var_.isSimpleName() || n.List.Len() < structcount(t) {
+               if var_.isSimpleName() || n.List.Len() < t.NumFields() {
                        a := Nod(OAS, var_, nil)
                        typecheck(&a, Etop)
                        walkexpr(&a, init)
index 1d3c1f6dffa80e9fb30b37933f256c7540d5bd24..84dc29c25b4729de58343110367df2925cdce7da 100644 (file)
@@ -2639,7 +2639,7 @@ func canSSAType(t *Type) bool {
                // introduced by the compiler for variadic functions.
                return false
        case TSTRUCT:
-               if countfield(t) > ssa.MaxStruct {
+               if t.NumFields() > ssa.MaxStruct {
                        return false
                }
                for _, t1 := range t.Fields().Slice() {
index 8d2d5008e3187a0860c99260bda0cf5486c6ddb3..c7cac054992ca5fedbd95f5a0f4fd554c30300fb 100644 (file)
@@ -592,7 +592,7 @@ func Isinter(t *Type) bool {
 }
 
 func isnilinter(t *Type) bool {
-       return Isinter(t) && countfield(t) == 0
+       return Isinter(t) && t.NumFields() == 0
 }
 
 func isideal(t *Type) bool {
@@ -2388,7 +2388,7 @@ func isdirectiface(t *Type) bool {
 
        case TSTRUCT:
                // Struct with 1 field of direct iface type can be direct.
-               return countfield(t) == 1 && isdirectiface(t.Field(0).Type)
+               return t.NumFields() == 1 && isdirectiface(t.Field(0).Type)
        }
 
        return false
index 624c506626018430a97fa19dd4ab6049897f2251..709506db075874de86a5323368781dea3f2eacee 100644 (file)
@@ -683,8 +683,3 @@ func (t *Type) NumElem() int64 {
 func (t *Type) IsMemory() bool { return false }
 func (t *Type) IsFlags() bool  { return false }
 func (t *Type) IsVoid() bool   { return false }
-
-// TODO(mdempsky): Replace all of these with direct calls to t.NumFields().
-func countfield(t *Type) int  { return t.NumFields() }
-func downcount(t *Type) int   { return t.NumFields() }
-func structcount(t *Type) int { return t.NumFields() }
index 1a28745f7489be301f89fd3df0e18bc7d91fa577..e857943103acbd858e60cacf3e2dea4faabeda79 100644 (file)
@@ -2597,8 +2597,8 @@ func typecheckaste(op Op, call *Node, isddd bool, tstruct *Type, nl Nodes, desc
                if n.Type != nil {
                        if n.Type.Etype == TSTRUCT && n.Type.Funarg {
                                if !hasddd(tstruct) {
-                                       n1 := downcount(tstruct)
-                                       n2 := downcount(n.Type)
+                                       n1 := tstruct.NumFields()
+                                       n2 := n.Type.NumFields()
                                        if n2 > n1 {
                                                goto toomany
                                        }
@@ -2646,7 +2646,7 @@ func typecheckaste(op Op, call *Node, isddd bool, tstruct *Type, nl Nodes, desc
                }
        }
 
-       n1 = downcount(tstruct)
+       n1 = tstruct.NumFields()
        n2 = nl.Len()
        if !hasddd(tstruct) {
                if n2 > n1 {
@@ -3347,7 +3347,7 @@ func typecheckas2(n *Node) {
                        if r.Type.Etype != TSTRUCT || !r.Type.Funarg {
                                break
                        }
-                       cr = structcount(r.Type)
+                       cr = r.Type.NumFields()
                        if cr != cl {
                                goto mismatch
                        }
index 3b3645784fe12dfc8b43aa04ebbe437748282273..e0e05c7a7357a8372a305db811dc30ae32007848 100644 (file)
@@ -1742,7 +1742,7 @@ func ascompatet(op Op, nl Nodes, nr *Type, fp int, init *Nodes) []*Node {
        }
 
        if i < nl.Len() || r != nil {
-               Yyerror("ascompatet: assignment count mismatch: %d = %d", nl.Len(), structcount(nr))
+               Yyerror("ascompatet: assignment count mismatch: %d = %d", nl.Len(), nr.NumFields())
        }
 
        if ullmanOverflow {
@@ -3225,7 +3225,7 @@ func walkcompare(np **Node, init *Nodes) {
                }
        }
 
-       if t.Etype == TSTRUCT && countfield(t) <= 4 {
+       if t.Etype == TSTRUCT && t.NumFields() <= 4 {
                // Struct of four or fewer fields.
                // Inline comparisons.
                var li *Node
@@ -3771,16 +3771,16 @@ func usemethod(n *Node) {
        //
        // TODO(crawshaw): improve precision of match by working out
        //                 how to check the method name.
-       if n := countfield(t.Params()); n != 1 {
+       if n := t.Params().NumFields(); n != 1 {
                return
        }
-       if n := countfield(t.Results()); n != 1 && n != 2 {
+       if n := t.Results().NumFields(); n != 1 && n != 2 {
                return
        }
        p0 := t.Params().Field(0)
        res0 := t.Results().Field(0)
        var res1 *Field
-       if countfield(t.Results()) == 2 {
+       if t.Results().NumFields() == 2 {
                res1 = t.Results().Field(1)
        }