Skip to content

Commit

Permalink
Look up struct fields by name.
Browse files Browse the repository at this point in the history
Reduces cost of querying in the most common case.

Refs #586
  • Loading branch information
echlebek committed Nov 23, 2017
1 parent b561945 commit 5a16dbe
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions types/dynamic/dynamic.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 5a16dbe

Please sign in to comment.