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:
parent
70deaa33eb
commit
e6e9e1d2f9
@ -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]
|
||||
|
Loading…
Reference in New Issue
Block a user