mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-09 20:17: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
|
return nil, err
|
||||||
}
|
}
|
||||||
list := make([]runtime.Object, items.Len())
|
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 {
|
for i := range list {
|
||||||
raw := items.Index(i)
|
raw := items.Index(i)
|
||||||
switch {
|
switch {
|
||||||
case raw.Type() == rawExtensionObjectType:
|
case isRawExtension:
|
||||||
item := raw.Interface().(runtime.RawExtension)
|
item := raw.Interface().(runtime.RawExtension)
|
||||||
switch {
|
switch {
|
||||||
case item.Object != nil:
|
case item.Object != nil:
|
||||||
@ -237,7 +243,7 @@ func extractList(obj runtime.Object, allocNew bool) ([]runtime.Object, error) {
|
|||||||
default:
|
default:
|
||||||
list[i] = nil
|
list[i] = nil
|
||||||
}
|
}
|
||||||
case raw.Type().Implements(objectType):
|
case implementsObject:
|
||||||
list[i] = raw.Interface().(runtime.Object)
|
list[i] = raw.Interface().(runtime.Object)
|
||||||
case allocNew:
|
case allocNew:
|
||||||
// shallow copy to avoid retaining a reference to the original list item
|
// shallow copy to avoid retaining a reference to the original list item
|
||||||
|
Loading…
Reference in New Issue
Block a user