MCPcopy
hub / github.com/grafana/tempo / NewRegexp

Function NewRegexp

pkg/regexp/regexp.go:23–49  ·  view source on GitHub ↗
(regexps []string, shouldMatch bool)

Source from the content-addressed store, hash-verified

21}
22
23func NewRegexp(regexps []string, shouldMatch bool) (*Regexp, error) {
24 matchers := make([]*labels.FastRegexMatcher, 0, len(regexps))
25
26 for _, r := range regexps {
27 m, err := labels.NewFastRegexMatcher(r)
28 if err != nil {
29 return nil, err
30 }
31 matchers = append(matchers, m)
32 }
33
34 // only memoize if there's a unoptimized matcher
35 // TODO: should we limit memoization to N values?
36 var matches map[string]bool
37 for _, m := range matchers {
38 if shouldMemoize(m) {
39 matches = make(map[string]bool)
40 break
41 }
42 }
43
44 return &Regexp{
45 matchers: matchers,
46 matches: matches,
47 shouldMatch: shouldMatch,
48 }, nil
49}
50
51func (r *Regexp) Match(b []byte) bool {
52 return r.MatchString(unsafe.String(unsafe.SliceData(b), len(b)))

Callers 4

newRegexPredicateFunction · 0.92
executeMethod · 0.92
binOpExecuteScalarFunction · 0.92
TestRegexpMatchFunction · 0.85

Calls 1

shouldMemoizeFunction · 0.85

Tested by 1

TestRegexpMatchFunction · 0.68