avoid one allocation when binding structs
This commit is contained in:
committed by
Michał Matczuk
parent
3a3f0a8f1d
commit
439bce4bdc
11
queryx.go
11
queryx.go
@@ -134,21 +134,22 @@ func bindStructArgs(names []string, arg0 interface{}, arg1 map[string]interface{
|
|||||||
v = v.Elem()
|
v = v.Elem()
|
||||||
}
|
}
|
||||||
|
|
||||||
fields := m.TraversalsByName(v.Type(), names)
|
err := m.TraversalsByNameFunc(v.Type(), names, func(i int, t []int) error {
|
||||||
for i, t := range fields {
|
|
||||||
if len(t) != 0 {
|
if len(t) != 0 {
|
||||||
val := reflectx.FieldByIndexesReadOnly(v, t)
|
val := reflectx.FieldByIndexesReadOnly(v, t)
|
||||||
arglist = append(arglist, val.Interface())
|
arglist = append(arglist, val.Interface())
|
||||||
} else {
|
} else {
|
||||||
val, ok := arg1[names[i]]
|
val, ok := arg1[names[i]]
|
||||||
if !ok {
|
if !ok {
|
||||||
return arglist, fmt.Errorf("could not find name %q in %#v and %#v", names[i], arg0, arg1)
|
return fmt.Errorf("could not find name %q in %#v and %#v", names[i], arg0, arg1)
|
||||||
}
|
}
|
||||||
arglist = append(arglist, val)
|
arglist = append(arglist, val)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return arglist, nil
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
return arglist, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// BindMap binds query named parameters using map.
|
// BindMap binds query named parameters using map.
|
||||||
|
|||||||
Reference in New Issue
Block a user