mirror of
https://github.com/prymitive/karma
synced 2026-05-07 03:26:52 +00:00
Speed up filter matches by re-using global match object
Instead of compiling filter regexp on every filter match pre-compile it and use same instance
This commit is contained in:
@@ -96,8 +96,7 @@ func NewFilter(expression string) FilterT {
|
||||
// we have "filter=" part, lookup filter that matches
|
||||
for _, fc := range AllFilters {
|
||||
f := fc.Factory()
|
||||
labelRe := regexp.MustCompile("^(?:" + fc.Label + ")$")
|
||||
if !labelRe.MatchString(matched) {
|
||||
if !fc.LabelRe.MatchString(matched) {
|
||||
// filter name doesn't match, keep searching
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package filters
|
||||
|
||||
import "regexp"
|
||||
|
||||
const (
|
||||
equalOperator string = "="
|
||||
notEqualOperator string = "!="
|
||||
@@ -29,6 +31,7 @@ var matcherConfig = map[string]matcherT{
|
||||
|
||||
type filterConfig struct {
|
||||
Label string
|
||||
LabelRe *regexp.Regexp
|
||||
SupportedOperators []string
|
||||
Factory newFilterFactory
|
||||
Autocomplete autocompleteFactory
|
||||
@@ -39,36 +42,42 @@ type filterConfig struct {
|
||||
var AllFilters = []filterConfig{
|
||||
filterConfig{
|
||||
Label: "@status",
|
||||
LabelRe: regexp.MustCompile("^@status$"),
|
||||
SupportedOperators: []string{equalOperator, notEqualOperator},
|
||||
Factory: newstatusFilter,
|
||||
Autocomplete: statusAutocomplete,
|
||||
},
|
||||
filterConfig{
|
||||
Label: "@age",
|
||||
LabelRe: regexp.MustCompile("^@age$"),
|
||||
SupportedOperators: []string{lessThanOperator, moreThanOperator},
|
||||
Factory: newAgeFilter,
|
||||
Autocomplete: ageAutocomplete,
|
||||
},
|
||||
filterConfig{
|
||||
Label: "@silence_jira",
|
||||
LabelRe: regexp.MustCompile("^@silence_jira$"),
|
||||
SupportedOperators: []string{regexpOperator, negativeRegexOperator, equalOperator, notEqualOperator},
|
||||
Factory: newSilenceJiraFilter,
|
||||
Autocomplete: sinceJiraIDAutocomplete,
|
||||
},
|
||||
filterConfig{
|
||||
Label: "@silence_author",
|
||||
LabelRe: regexp.MustCompile("^@silence_author$"),
|
||||
SupportedOperators: []string{regexpOperator, negativeRegexOperator, equalOperator, notEqualOperator},
|
||||
Factory: newSilenceAuthorFilter,
|
||||
Autocomplete: sinceAuthorAutocomplete,
|
||||
},
|
||||
filterConfig{
|
||||
Label: "@limit",
|
||||
LabelRe: regexp.MustCompile("^@limit$"),
|
||||
SupportedOperators: []string{equalOperator},
|
||||
Factory: newLimitFilter,
|
||||
Autocomplete: limitAutocomplete,
|
||||
},
|
||||
filterConfig{
|
||||
Label: "[a-zA-Z_][a-zA-Z0-9_]*",
|
||||
LabelRe: regexp.MustCompile("^[a-zA-Z_][a-zA-Z0-9_]*$"),
|
||||
SupportedOperators: []string{regexpOperator, negativeRegexOperator, equalOperator, notEqualOperator, lessThanOperator, moreThanOperator},
|
||||
Factory: newLabelFilter,
|
||||
Autocomplete: labelAutocomplete,
|
||||
|
||||
Reference in New Issue
Block a user