From 8cc3f246b74f06d46eff82a1915d2585a70b7beb Mon Sep 17 00:00:00 2001 From: Eric Chlebek Date: Wed, 22 Nov 2017 18:15:05 -0800 Subject: [PATCH] Look up struct fields by name. Reduces cost of querying in the most common case. Refs #586 --- types/dynamic/dynamic.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/types/dynamic/dynamic.go b/types/dynamic/dynamic.go index 9d8070dbc1..03b994a384 100644 --- a/types/dynamic/dynamic.go +++ b/types/dynamic/dynamic.go @@ -34,10 +34,9 @@ func GetField(v Attributer, name string) (interface{}, error) { if kind := strukt.Kind(); kind != reflect.Struct { return nil, fmt.Errorf("invalid type (want struct): %v", kind) } - fields := getFields(strukt) - field, ok := fields[name] - if ok { - return field.Value.Interface(), nil + field := strukt.FieldByName(name) + if field.IsValid() { + return field.Interface(), nil } } // If we get here, we are dealing with extended attributes.