MCPcopy Create free account
hub / github.com/despiteallobjections/amigo / MethodSet

Method MethodSet

types/methodsetcache.go:28–56  ·  view source on GitHub ↗

MethodSet returns the method set of type T. It is thread-safe. If cache is nil, this function is equivalent to types.NewMethodSet(T). Utility functions can thus expose an optional *MethodSetCache parameter to clients that care about performance.

(T Type)

Source from the content-addressed store, hash-verified

26// parameter to clients that care about performance.
27//
28func (cache *MethodSetCache) MethodSet(T Type) *MethodSet {
29 if cache == nil {
30 return NewMethodSet(T)
31 }
32 cache.mu.Lock()
33 defer cache.mu.Unlock()
34
35 switch T := T.(type) {
36 case *Named:
37 return cache.lookupNamed(T).value
38
39 case *Pointer:
40 if N, ok := T.Elem().(*Named); ok {
41 return cache.lookupNamed(N).pointer
42 }
43 }
44
45 // all other types
46 // (The map uses pointer equivalence, not type identity.)
47 mset := cache.others[T]
48 if mset == nil {
49 mset = NewMethodSet(T)
50 if cache.others == nil {
51 cache.others = make(map[Type]*MethodSet)
52 }
53 cache.others[T] = mset
54 }
55 return mset
56}
57
58func (cache *MethodSetCache) lookupNamed(named *Named) struct{ value, pointer *MethodSet } {
59 if cache.named == nil {

Callers 7

LookupMethodMethod · 0.80
needMethodsMethod · 0.80
IntuitiveMethodSetFunction · 0.80
programMethod · 0.80
initReflectFunction · 0.80

Calls 3

lookupNamedMethod · 0.95
NewMethodSetFunction · 0.85
ElemMethod · 0.65

Tested by

no test coverage detected