Skip to content

Commit

Permalink
Improved suffix benchmark performance (#7312)
Browse files Browse the repository at this point in the history
Signed-off-by: Calum Murray <cmurray@redhat.com>
  • Loading branch information
Cali0707 authored Sep 28, 2023
1 parent 44aa15e commit 88fe195
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions pkg/eventfilter/subscriptionsapi/suffix_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@ func (filter *suffixFilter) Filter(ctx context.Context, event cloudevents.Event)
if filter == nil {
return eventfilter.NoFilter
}
for attribute, value := range filter.filters {
if attribute == "" || value == "" {
return eventfilter.NoFilter
}
}
logger := logging.FromContext(ctx)
logger.Debugw("Performing a suffix match ", zap.Any("filters", filter.filters), zap.Any("event", event))
for k, v := range filter.filters {
Expand All @@ -64,7 +59,11 @@ func (filter *suffixFilter) Filter(ctx context.Context, event cloudevents.Event)
zap.Any("event", event))
return eventfilter.FailFilter
}
if !strings.HasSuffix(fmt.Sprintf("%v", value), v) {
var s string
if s, ok = value.(string); !ok {
s = fmt.Sprintf("%v", value)
}
if !strings.HasSuffix(s, v) {
return eventfilter.FailFilter
}
}
Expand Down

0 comments on commit 88fe195

Please sign in to comment.