-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcontext.go
43 lines (35 loc) · 920 Bytes
/
context.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package reflectx
import (
"fmt"
"reflect"
"github.com/goplus/reflectx/abi"
)
var (
// disable unable allocate warning
DisableAllocateWarning bool
)
var Default *Context = NewContext()
type Context struct {
embedLookupCache map[reflect.Type]reflect.Type
structLookupCache map[string][]reflect.Type
interfceLookupCache map[string]reflect.Type
methodIndexList map[abi.MethodProvider][]int
nAllocateError int
}
func NewContext() *Context {
ctx := &Context{}
ctx.embedLookupCache = make(map[reflect.Type]reflect.Type)
ctx.structLookupCache = make(map[string][]reflect.Type)
ctx.interfceLookupCache = make(map[string]reflect.Type)
ctx.methodIndexList = make(map[abi.MethodProvider][]int)
return ctx
}
type AllocError struct {
Typ reflect.Type
Cap int
Req int
}
func (p *AllocError) Error() string {
return fmt.Sprintf("cannot alloc method %q, cap:%v req:%v",
p.Typ, p.Cap, p.Req)
}