From 7b5f1a616b221ced913ea854e5c21d3e45acb41f Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Fri, 20 Mar 2020 20:45:04 +0000 Subject: [PATCH] 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 --- sdk/update.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/sdk/update.go b/sdk/update.go index a14ab15b4..e14347f32 100644 --- a/sdk/update.go +++ b/sdk/update.go @@ -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)