Use reflect.Zero(type) to get value to clear field

Previously, the common value extraction code used an empty structure
to get the value to use to clear a field whose value is common. This
change removed the structure and used reflect.Zero(..) to get the
value instead.

Bug: 142935992
Test: m nothing
Change-Id: Ibd5103dacb86e7754a786356c0d15ffbde7f98bf
This commit is contained in:
Paul Duffin 2020-03-20 20:45:04 +00:00
parent 6a7e953e62
commit 7b5f1a616b
1 changed files with 1 additions and 5 deletions

View File

@ -1283,10 +1283,6 @@ foundStruct:
func (e *commonValueExtractor) extractCommonProperties(commonProperties interface{}, inputPropertiesSlice interface{}) {
commonPropertiesValue := reflect.ValueOf(commonProperties)
commonStructValue := commonPropertiesValue.Elem()
propertiesStructType := commonStructValue.Type()
// Create an empty structure from which default values for the field can be copied.
emptyStructValue := reflect.New(propertiesStructType).Elem()
for _, fieldGetter := range e.fieldGetters {
// Check to see if all the structures have the same value for the field. The commonValue
@ -1315,7 +1311,7 @@ func (e *commonValueExtractor) extractCommonProperties(commonProperties interfac
// If the fields all have a common value then store it in the common struct field
// and set the input struct's field to the empty value.
if commonValue != nil {
emptyValue := fieldGetter(emptyStructValue)
emptyValue := reflect.Zero(commonValue.Type())
fieldGetter(commonStructValue).Set(*commonValue)
for i := 0; i < sliceValue.Len(); i++ {
itemValue := sliceValue.Index(i)