Skip to content

Commit

Permalink
perf: ResAccumulator: Use map for resmap intersection
Browse files Browse the repository at this point in the history
  • Loading branch information
chlunde committed Oct 30, 2023
1 parent 4b86764 commit 26f499d
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions api/internal/accumulator/resaccumulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,13 @@ func (ra *ResAccumulator) FixBackReferences() (err error) {
// Intersection drops the resources which "other" does not have.
func (ra *ResAccumulator) Intersection(other resmap.ResMap) error {
otherIds := other.AllIds()
seen := make(map[resid.ResId]struct{}, len(otherIds))
for _, id := range otherIds {
seen[id] = struct{}{}
}
for _, curId := range ra.resMap.AllIds() {
toDelete := true
for _, otherId := range otherIds {
if otherId == curId {
toDelete = false
break
}
}
if toDelete {
_, inOtherSet := seen[curId]
if !inOtherSet {
err := ra.resMap.Remove(curId)
if err != nil {
return err
Expand Down

0 comments on commit 26f499d

Please sign in to comment.