Skip to content

Commit

Permalink
feat: reduced unnecessary creation of filters (#8118)
Browse files Browse the repository at this point in the history
Signed-off-by: Calum Murray <[email protected]>
  • Loading branch information
Cali0707 authored Aug 14, 2024
1 parent 71d5d5f commit 1123cfa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/eventfilter/subscriptionsapi/all_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ type allFilter struct {

// NewAllFilter returns an event filter which passes if all the contained filters pass
func NewAllFilter(filters ...eventfilter.Filter) eventfilter.Filter {
// just one filter, no need to create a new AllFilter
if len(filters) == 1 {
return filters[0]
}

filterCounts := make([]filterCount, len(filters))
for i, filter := range filters {
filterCounts[i] = filterCount{
Expand Down
5 changes: 5 additions & 0 deletions pkg/eventfilter/subscriptionsapi/any_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ type anyFilter struct {

// NewAnyFilter returns an event filter which passes if any of the contained filters passes.
func NewAnyFilter(filters ...eventfilter.Filter) eventfilter.Filter {
// just one filter, no need to create a new AnyFilter
if len(filters) == 1 {
return filters[0]
}

filterCounts := make([]filterCount, len(filters))
for i, filter := range filters {
filterCounts[i] = filterCount{
Expand Down

0 comments on commit 1123cfa

Please sign in to comment.