From dc7e436949190dd81021722ef627b49471cc72c2 Mon Sep 17 00:00:00 2001 From: Back Yu Date: Sat, 19 Jan 2019 12:24:46 +0800 Subject: [PATCH] Improve the reflect of getFunc(...) --- runtime.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/runtime.go b/runtime.go index a5e3b7320..51954d52d 100644 --- a/runtime.go +++ b/runtime.go @@ -83,7 +83,7 @@ func extract(val interface{}, i interface{}) (interface{}, bool) { return nil, false } -func getFunc(val interface{}, i interface{}) (interface{}, bool) { +func getFunc(val interface{}, name string) (interface{}, bool) { v := reflect.ValueOf(val) d := v if v.Kind() == reflect.Ptr { @@ -92,20 +92,18 @@ func getFunc(val interface{}, i interface{}) (interface{}, bool) { switch d.Kind() { case reflect.Map: - value := d.MapIndex(reflect.ValueOf(i)) + value := d.MapIndex(reflect.ValueOf(name)) if value.IsValid() && value.CanInterface() { return value.Interface(), true } // A map may have method too. if v.NumMethod() > 0 { - name := reflect.ValueOf(i).String() method := v.MethodByName(name) if method.IsValid() && method.CanInterface() { return method.Interface(), true } } case reflect.Struct: - name := reflect.ValueOf(i).String() method := v.MethodByName(name) if method.IsValid() && method.CanInterface() { return method.Interface(), true