Skip to content

Commit 188cecf

Browse files
committed
feat(nestedArray): reduce complexity on valuePath.Get
1 parent abddd3e commit 188cecf

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

pkg/customresourcestate/registry_factory.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -578,25 +578,23 @@ func (p valuePath) Get(obj interface{}) interface{} {
578578
return nil
579579
}
580580

581-
if slice, ok := obj.([]interface{}); ok && op.part == "[*]" {
582-
// wildcard: garder tous les éléments
581+
if slice, ok := obj.([]interface{}); ok {
583582
var all []interface{}
584583
for _, el := range slice {
584+
// non-wildcard: apply operation
585+
if op.part != "[*]" {
586+
el = op.op(el)
587+
}
588+
589+
// wildcard: keep all elements
585590
all = append(all, el)
586591
}
587592
obj = all
588593

589-
} else if slice, ok := obj.([]interface{}); ok && op.part != "[*]" {
590-
var all []interface{}
591-
for _, el := range slice {
592-
all = append(all, op.op(el))
593-
}
594-
obj = all
595594
} else {
596595
obj = op.op(obj)
597596
}
598597

599-
//obj = op.op(obj)
600598
}
601599
return obj
602600
}

0 commit comments

Comments
 (0)