improve the performance when converting struct that implements UnmarshalValue

This commit is contained in:
john
2020-07-13 23:51:36 +08:00
parent c770e4779a
commit e1c0a92e60

View File

@ -61,12 +61,6 @@ func doStruct(params interface{}, pointer interface{}, recursive bool, mapping .
}
}()
// paramsMap is the map[string]interface{} type variable for params.
paramsMap := MapDeep(params)
if paramsMap == nil {
return gerror.Newf("invalid params: %v", params)
}
// UnmarshalValue.
// Assign value with interface UnmarshalValue.
// Note that only pointer can implement interface UnmarshalValue.
@ -74,6 +68,12 @@ func doStruct(params interface{}, pointer interface{}, recursive bool, mapping .
return v.UnmarshalValue(params)
}
// paramsMap is the map[string]interface{} type variable for params.
paramsMap := MapDeep(params)
if paramsMap == nil {
return gerror.Newf("invalid params: %v", params)
}
// Using reflect to do the converting,
// it also supports type of reflect.Value for <pointer>(always in internal usage).
elem, ok := pointer.(reflect.Value)