File tree Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Original file line number Diff line number Diff line change 7
7
"go/types"
8
8
"io"
9
9
"strings"
10
+
11
+ "golang.org/x/tools/go/types/typeutil"
10
12
)
11
13
12
14
var ErrInvalidRule = errors .New ("invalid rule format" )
@@ -41,9 +43,19 @@ func (rs *Ruleset) Match(fn *types.Func) bool {
41
43
return false
42
44
}
43
45
44
- func receiverTypeOf (recvType types.Type ) string {
45
- buf := & strings.Builder {}
46
+ var receiverTypeCache = typeutil.Map {}
47
+
48
+ func receiverTypeOf (recvType types.Type ) (repr string ) {
49
+ if val := receiverTypeCache .At (recvType ); val != nil {
50
+ repr , _ = val .(string )
51
+ return repr
52
+ }
53
+
54
+ defer func () {
55
+ receiverTypeCache .Set (recvType , repr )
56
+ }()
46
57
58
+ buf := & strings.Builder {}
47
59
var recvNamed * types.Named
48
60
switch recvType := recvType .(type ) {
49
61
case * types.Pointer :
You can’t perform that action at this time.
0 commit comments