mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-09 03:57:41 +00:00
Optimize reflect checks further, save item type information
This commit is contained in:
parent
12e3d9fcc4
commit
bf116e8594
@ -223,10 +223,16 @@ func extractList(obj runtime.Object, allocNew bool) ([]runtime.Object, error) {
|
||||
return nil, err
|
||||
}
|
||||
list := make([]runtime.Object, items.Len())
|
||||
if len(list) == 0 {
|
||||
return list, nil
|
||||
}
|
||||
elemType := items.Type().Elem()
|
||||
isRawExtension := elemType == rawExtensionObjectType
|
||||
implementsObject := elemType.Implements(objectType)
|
||||
for i := range list {
|
||||
raw := items.Index(i)
|
||||
switch {
|
||||
case raw.Type() == rawExtensionObjectType:
|
||||
case isRawExtension:
|
||||
item := raw.Interface().(runtime.RawExtension)
|
||||
switch {
|
||||
case item.Object != nil:
|
||||
@ -237,7 +243,7 @@ func extractList(obj runtime.Object, allocNew bool) ([]runtime.Object, error) {
|
||||
default:
|
||||
list[i] = nil
|
||||
}
|
||||
case raw.Type().Implements(objectType):
|
||||
case implementsObject:
|
||||
list[i] = raw.Interface().(runtime.Object)
|
||||
case allocNew:
|
||||
// shallow copy to avoid retaining a reference to the original list item
|
||||
|
Loading…
Reference in New Issue
Block a user