1
0
mirror of https://github.com/golang/go synced 2024-11-25 09:57:57 -07:00

reflect/type.go: add special case judgement before scan T's and V's methods

This change can avoid redundant linear scanning when the number of T's methods is less than the number of V's methods, which  can enhance the efficiency while judging whether a type implements a interface.
This commit is contained in:
marsyrc 2021-04-26 14:47:35 +08:00 committed by GitHub
parent 70deaa33eb
commit e6e9e1d2f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1498,6 +1498,9 @@ func implements(T, V *rtype) bool {
// See also ../runtime/iface.go.
if V.Kind() == Interface {
v := (*interfaceType)(unsafe.Pointer(V))
if len(v.methods) < len(t.methods) {
return false
}
i := 0
for j := 0; j < len(v.methods); j++ {
tm := &t.methods[i]