Skip to content

Commit e7eed1a

Browse files
authored
Merge pull request kubernetes#86512 from yutedz/to-unstruct
Remove ineffective calls in toUnstructured
2 parents 29005d0 + e468385 commit e7eed1a

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.
@@ -572,40 +569,25 @@ func toUnstructured(sv, dv reflect.Value) error {
572569
return nil
573570
}
574571

575-
st, dt := sv.Type(), dv.Type()
572+
st := sv.Type()
576573
switch st.Kind() {
577574
case reflect.String:
578-
if dt.Kind() == reflect.Interface && dv.NumMethod() == 0 {
579-
dv.Set(reflect.New(stringType))
580-
}
581575
dv.Set(reflect.ValueOf(sv.String()))
582576
return nil
583577
case reflect.Bool:
584-
if dt.Kind() == reflect.Interface && dv.NumMethod() == 0 {
585-
dv.Set(reflect.New(boolType))
586-
}
587578
dv.Set(reflect.ValueOf(sv.Bool()))
588579
return nil
589580
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
590-
if dt.Kind() == reflect.Interface && dv.NumMethod() == 0 {
591-
dv.Set(reflect.New(int64Type))
592-
}
593581
dv.Set(reflect.ValueOf(sv.Int()))
594582
return nil
595583
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
596584
uVal := sv.Uint()
597585
if uVal > math.MaxInt64 {
598586
return fmt.Errorf("unsigned value %d does not fit into int64 (overflow)", uVal)
599587
}
600-
if dt.Kind() == reflect.Interface && dv.NumMethod() == 0 {
601-
dv.Set(reflect.New(int64Type))
602-
}
603588
dv.Set(reflect.ValueOf(int64(uVal)))
604589
return nil
605590
case reflect.Float32, reflect.Float64:
606-
if dt.Kind() == reflect.Interface && dv.NumMethod() == 0 {
607-
dv.Set(reflect.New(float64Type))
608-
}
609591
dv.Set(reflect.ValueOf(sv.Float()))
610592
return nil
611593
case reflect.Map:

0 commit comments

Comments
 (0)