internal/runtime: cache rtypeList

This commit is contained in:
visualfc
2024-12-20 20:44:39 +08:00
parent c1588d70cd
commit 1d3c98372a
3 changed files with 136 additions and 3 deletions

View File

@@ -203,6 +203,9 @@ func setUncommon(ret *Type, methods []Method) {
// Func returns a function type.
func Func(in, out []*Type, variadic bool) *FuncType {
if t := rtypeList.findFunc(in, out, variadic); t != nil {
return t
}
ret := &FuncType{
Type: Type{
Size_: 2 * unsafe.Sizeof(uintptr(0)),
@@ -219,6 +222,7 @@ func Func(in, out []*Type, variadic bool) *FuncType {
ret.TFlag |= abi.TFlagVariadic
}
ret.Str_ = funcStr(ret)
rtypeList.addType(&ret.Type)
return ret
}
@@ -266,6 +270,9 @@ func InitNamedInterface(ret *InterfaceType, methods []Imethod) {
}
func Interface(pkgPath string, methods []Imethod) *InterfaceType {
if t := rtypeList.findInterface(pkgPath, methods); t != nil {
return t
}
ret := &abi.InterfaceType{
Type: Type{
Size_: unsafe.Sizeof(eface{}),
@@ -284,6 +291,7 @@ func Interface(pkgPath string, methods []Imethod) *InterfaceType {
ret.Equal = interequal
}
ret.Str_ = interfaceStr(ret)
rtypeList.addType(&ret.Type)
return ret
}