Commit dbed1c63 authored by Matthew Dempsky's avatar Matthew Dempsky

cmd/compile: eliminate NumFields wrapper functions

Change-Id: I3c6035559288cfdc33857216f50241b81932c8a4
Reviewed-on: https://go-review.googlesource.com/20811
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 15ed37d7
...@@ -559,12 +559,12 @@ func (p *exporter) qualifiedName(sym *Sym) { ...@@ -559,12 +559,12 @@ func (p *exporter) qualifiedName(sym *Sym) {
} }
func (p *exporter) fieldList(t *Type) { func (p *exporter) fieldList(t *Type) {
if p.trace && countfield(t) > 0 { if p.trace && t.NumFields() > 0 {
p.tracef("fields {>") p.tracef("fields {>")
defer p.tracef("<\n} ") defer p.tracef("<\n} ")
} }
p.int(countfield(t)) p.int(t.NumFields())
for _, f := range t.Fields().Slice() { for _, f := range t.Fields().Slice() {
if p.trace { if p.trace {
p.tracef("\n") p.tracef("\n")
...@@ -588,12 +588,12 @@ func (p *exporter) note(n *string) { ...@@ -588,12 +588,12 @@ func (p *exporter) note(n *string) {
} }
func (p *exporter) methodList(t *Type) { func (p *exporter) methodList(t *Type) {
if p.trace && countfield(t) > 0 { if p.trace && t.NumFields() > 0 {
p.tracef("methods {>") p.tracef("methods {>")
defer p.tracef("<\n} ") defer p.tracef("<\n} ")
} }
p.int(countfield(t)) p.int(t.NumFields())
for _, m := range t.Fields().Slice() { for _, m := range t.Fields().Slice() {
if p.trace { if p.trace {
p.tracef("\n") p.tracef("\n")
...@@ -650,7 +650,7 @@ func (p *exporter) paramList(params *Type, numbered bool) { ...@@ -650,7 +650,7 @@ func (p *exporter) paramList(params *Type, numbered bool) {
// use negative length to indicate unnamed parameters // use negative length to indicate unnamed parameters
// (look at the first parameter only since either all // (look at the first parameter only since either all
// names are present or all are absent) // names are present or all are absent)
n := countfield(params) n := params.NumFields()
if n > 0 && parName(params.Field(0), numbered) == "" { if n > 0 && parName(params.Field(0), numbered) == "" {
n = -n n = -n
} }
......
...@@ -1030,7 +1030,7 @@ func isifacemethod(f *Type) bool { ...@@ -1030,7 +1030,7 @@ func isifacemethod(f *Type) bool {
return false return false
} }
t = t.Type 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 false
} }
return true return true
......
...@@ -1071,7 +1071,7 @@ func anylit(ctxt int, n *Node, var_ *Node, init *Nodes) { ...@@ -1071,7 +1071,7 @@ func anylit(ctxt int, n *Node, var_ *Node, init *Nodes) {
} }
// initialize of not completely specified // 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) a := Nod(OAS, var_, nil)
typecheck(&a, Etop) typecheck(&a, Etop)
walkexpr(&a, init) walkexpr(&a, init)
......
...@@ -2639,7 +2639,7 @@ func canSSAType(t *Type) bool { ...@@ -2639,7 +2639,7 @@ func canSSAType(t *Type) bool {
// introduced by the compiler for variadic functions. // introduced by the compiler for variadic functions.
return false return false
case TSTRUCT: case TSTRUCT:
if countfield(t) > ssa.MaxStruct { if t.NumFields() > ssa.MaxStruct {
return false return false
} }
for _, t1 := range t.Fields().Slice() { for _, t1 := range t.Fields().Slice() {
......
...@@ -592,7 +592,7 @@ func Isinter(t *Type) bool { ...@@ -592,7 +592,7 @@ func Isinter(t *Type) bool {
} }
func isnilinter(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 { func isideal(t *Type) bool {
...@@ -2388,7 +2388,7 @@ func isdirectiface(t *Type) bool { ...@@ -2388,7 +2388,7 @@ func isdirectiface(t *Type) bool {
case TSTRUCT: case TSTRUCT:
// Struct with 1 field of direct iface type can be direct. // 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 return false
......
...@@ -683,8 +683,3 @@ func (t *Type) NumElem() int64 { ...@@ -683,8 +683,3 @@ func (t *Type) NumElem() int64 {
func (t *Type) IsMemory() bool { return false } func (t *Type) IsMemory() bool { return false }
func (t *Type) IsFlags() bool { return false } func (t *Type) IsFlags() bool { return false }
func (t *Type) IsVoid() 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() }
...@@ -2597,8 +2597,8 @@ func typecheckaste(op Op, call *Node, isddd bool, tstruct *Type, nl Nodes, desc ...@@ -2597,8 +2597,8 @@ func typecheckaste(op Op, call *Node, isddd bool, tstruct *Type, nl Nodes, desc
if n.Type != nil { if n.Type != nil {
if n.Type.Etype == TSTRUCT && n.Type.Funarg { if n.Type.Etype == TSTRUCT && n.Type.Funarg {
if !hasddd(tstruct) { if !hasddd(tstruct) {
n1 := downcount(tstruct) n1 := tstruct.NumFields()
n2 := downcount(n.Type) n2 := n.Type.NumFields()
if n2 > n1 { if n2 > n1 {
goto toomany goto toomany
} }
...@@ -2646,7 +2646,7 @@ func typecheckaste(op Op, call *Node, isddd bool, tstruct *Type, nl Nodes, desc ...@@ -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() n2 = nl.Len()
if !hasddd(tstruct) { if !hasddd(tstruct) {
if n2 > n1 { if n2 > n1 {
...@@ -3347,7 +3347,7 @@ func typecheckas2(n *Node) { ...@@ -3347,7 +3347,7 @@ func typecheckas2(n *Node) {
if r.Type.Etype != TSTRUCT || !r.Type.Funarg { if r.Type.Etype != TSTRUCT || !r.Type.Funarg {
break break
} }
cr = structcount(r.Type) cr = r.Type.NumFields()
if cr != cl { if cr != cl {
goto mismatch goto mismatch
} }
......
...@@ -1742,7 +1742,7 @@ func ascompatet(op Op, nl Nodes, nr *Type, fp int, init *Nodes) []*Node { ...@@ -1742,7 +1742,7 @@ func ascompatet(op Op, nl Nodes, nr *Type, fp int, init *Nodes) []*Node {
} }
if i < nl.Len() || r != nil { 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 { if ullmanOverflow {
...@@ -3225,7 +3225,7 @@ func walkcompare(np **Node, init *Nodes) { ...@@ -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. // Struct of four or fewer fields.
// Inline comparisons. // Inline comparisons.
var li *Node var li *Node
...@@ -3771,16 +3771,16 @@ func usemethod(n *Node) { ...@@ -3771,16 +3771,16 @@ func usemethod(n *Node) {
// //
// TODO(crawshaw): improve precision of match by working out // TODO(crawshaw): improve precision of match by working out
// how to check the method name. // how to check the method name.
if n := countfield(t.Params()); n != 1 { if n := t.Params().NumFields(); n != 1 {
return return
} }
if n := countfield(t.Results()); n != 1 && n != 2 { if n := t.Results().NumFields(); n != 1 && n != 2 {
return return
} }
p0 := t.Params().Field(0) p0 := t.Params().Field(0)
res0 := t.Results().Field(0) res0 := t.Results().Field(0)
var res1 *Field var res1 *Field
if countfield(t.Results()) == 2 { if t.Results().NumFields() == 2 {
res1 = t.Results().Field(1) res1 = t.Results().Field(1)
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment