Skip to content

Commit e468385

Browse files
committed
Remove ineffective calls in toUnstructured
1 parent 9f841bf commit e468385

File tree

1 file changed

+1
-19
lines changed

1 file changed

+1
-19
lines changed

staging/src/k8s.io/apimachinery/pkg/runtime/converter.go

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,6 @@ var (
7272
unmarshalerType = reflect.TypeOf(new(encodingjson.Unmarshaler)).Elem()
7373
mapStringInterfaceType = reflect.TypeOf(map[string]interface{}{})
7474
stringType = reflect.TypeOf(string(""))
75-
int64Type = reflect.TypeOf(int64(0))
76-
float64Type = reflect.TypeOf(float64(0))
77-
boolType = reflect.TypeOf(bool(false))
7875
fieldCache = newFieldsCache()
7976

8077
// DefaultUnstructuredConverter performs unstructured to Go typed object conversions.
@@ -571,40 +568,25 @@ func toUnstructured(sv, dv reflect.Value) error {
571568
return nil
572569
}
573570

574-
st, dt := sv.Type(), dv.Type()
571+
st := sv.Type()
575572
switch st.Kind() {
576573
case reflect.String:
577-
if dt.Kind() == reflect.Interface && dv.NumMethod() == 0 {
578-
dv.Set(reflect.New(stringType))
579-
}
580574
dv.Set(reflect.ValueOf(sv.String()))
581575
return nil
582576
case reflect.Bool:
583-
if dt.Kind() == reflect.Interface && dv.NumMethod() == 0 {
584-
dv.Set(reflect.New(boolType))
585-
}
586577
dv.Set(reflect.ValueOf(sv.Bool()))
587578
return nil
588579
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
589-
if dt.Kind() == reflect.Interface && dv.NumMethod() == 0 {
590-
dv.Set(reflect.New(int64Type))
591-
}
592580
dv.Set(reflect.ValueOf(sv.Int()))
593581
return nil
594582
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
595583
uVal := sv.Uint()
596584
if uVal > math.MaxInt64 {
597585
return fmt.Errorf("unsigned value %d does not fit into int64 (overflow)", uVal)
598586
}
599-
if dt.Kind() == reflect.Interface && dv.NumMethod() == 0 {
600-
dv.Set(reflect.New(int64Type))
601-
}
602587
dv.Set(reflect.ValueOf(int64(uVal)))
603588
return nil
604589
case reflect.Float32, reflect.Float64:
605-
if dt.Kind() == reflect.Interface && dv.NumMethod() == 0 {
606-
dv.Set(reflect.New(float64Type))
607-
}
608590
dv.Set(reflect.ValueOf(sv.Float()))
609591
return nil
610592
case reflect.Map:

0 commit comments

Comments
 (0)