Skip to content
This repository has been archived by the owner on Sep 1, 2018. It is now read-only.

Commit

Permalink
Remove isFuncType and ifaceOf helper funcs
Browse files Browse the repository at this point in the history
They're incredibly simple now, so inline their only uses.
  • Loading branch information
mvdan committed Mar 28, 2017
1 parent bd42ca7 commit d9ef8e3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 19 deletions.
16 changes: 4 additions & 12 deletions cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,13 @@ import (
)

type pkgTypes struct {
ifaces map[string]string
funcs map[string]bool
}

func (p *pkgTypes) isFuncType(t string) bool {
return p.funcs[t]
}

func (p *pkgTypes) ifaceOf(t string) string {
return p.ifaces[t]
ifaces map[string]string
funcSigns map[string]bool
}

func (p *pkgTypes) getTypes(pkg *types.Package) {
p.ifaces = make(map[string]string)
p.funcs = make(map[string]bool)
p.funcSigns = make(map[string]bool)
addTypes := func(impPath string, ifs map[string]string, funs map[string]bool, top bool) {
fullName := func(name string) string {
if !top {
Expand All @@ -39,7 +31,7 @@ func (p *pkgTypes) getTypes(pkg *types.Package) {
}
for ftype := range funs {
// ignore non-exported func signatures too
p.funcs[ftype] = true
p.funcSigns[ftype] = true
}
}
for _, imp := range pkg.Imports() {
Expand Down
10 changes: 3 additions & 7 deletions check.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (v *visitor) interfaceMatching(param *types.Var, usage *varUsage) (string,
called := make(map[string]string, len(usage.calls))
allCalls(usage, called, ftypes)
s := funcMapString(called)
return v.ifaceOf(s), s
return v.ifaces[s], s
}

type varUsage struct {
Expand Down Expand Up @@ -239,11 +239,6 @@ func (v *visitor) comparedWith(e, with ast.Expr) {
}
}

func (v *visitor) implementsIface(sign *types.Signature) bool {
s := signString(sign)
return v.isFuncType(s)
}

func (v *visitor) Visit(node ast.Node) ast.Visitor {
var fd *funcDecl
switch x := node.(type) {
Expand All @@ -253,7 +248,8 @@ func (v *visitor) Visit(node ast.Node) ast.Visitor {
sign: v.Defs[x.Name].Type().(*types.Signature),
astType: x.Type,
}
if v.implementsIface(fd.sign) {
if v.funcSigns[signString(fd.sign)] {
// implements interface
return nil
}
case *ast.SelectorExpr:
Expand Down

0 comments on commit d9ef8e3

Please sign in to comment.