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
diff --git a/sdk/update.go b/sdk/update.go
index a14ab15..e14347f 100644
--- a/sdk/update.go
+++ b/sdk/update.go
@@ -1283,10 +1283,6 @@
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 @@
// 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)