Skip to content

Commit 6e7f966

Browse files
committed
fix: parents map -> set struct optimization per review feedback
Signed-off-by: Jonathan Ogilvie <[email protected]>
1 parent cb82702 commit 6e7f966

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

gitops-engine/pkg/cache/cluster.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -555,32 +555,32 @@ func (c *clusterCache) removeFromParentUIDToChildren(parentUID types.UID, childK
555555
// updateParentUIDToChildren updates the parent-to-children index when a resource's owner refs change
556556
func (c *clusterCache) updateParentUIDToChildren(childKey kube.ResourceKey, oldResource *Resource, newResource *Resource) {
557557
// Build sets of old and new parent UIDs
558-
oldParents := make(map[types.UID]bool)
558+
oldParents := make(map[types.UID]struct{})
559559
if oldResource != nil {
560560
for _, ref := range oldResource.OwnerRefs {
561561
if ref.UID != "" {
562-
oldParents[ref.UID] = true
562+
oldParents[ref.UID] = struct{}{}
563563
}
564564
}
565565
}
566566

567-
newParents := make(map[types.UID]bool)
567+
newParents := make(map[types.UID]struct{})
568568
for _, ref := range newResource.OwnerRefs {
569569
if ref.UID != "" {
570-
newParents[ref.UID] = true
570+
newParents[ref.UID] = struct{}{}
571571
}
572572
}
573573

574574
// Remove from parents that are no longer in owner refs
575575
for oldUID := range oldParents {
576-
if !newParents[oldUID] {
576+
if _, exists := newParents[oldUID]; !exists {
577577
c.removeFromParentUIDToChildren(oldUID, childKey)
578578
}
579579
}
580580

581581
// Add to parents that are new in owner refs
582582
for newUID := range newParents {
583-
if !oldParents[newUID] {
583+
if _, exists := oldParents[newUID]; !exists {
584584
c.addToParentUIDToChildren(newUID, childKey)
585585
}
586586
}

0 commit comments

Comments
 (0)