mirror of
https://github.com/prometheus/prometheus.git
synced 2025-02-21 03:16:00 -08:00
Review feedback
Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>
This commit is contained in:
parent
f32ec95722
commit
9733377257
|
@ -113,6 +113,7 @@ func (m *Matcher) Inverse() (*Matcher, error) {
|
|||
|
||||
// SetMatches returns a set of equality matchers for the current regex matchers if possible.
|
||||
// For examples the regexp `a(b|f)` will returns "ab" and "af".
|
||||
// Returns nil if we can't replace the regexp by only equality matchers.
|
||||
func (m *Matcher) SetMatches() []string {
|
||||
if m.re == nil {
|
||||
return nil
|
||||
|
|
|
@ -56,7 +56,7 @@ func NewFastRegexMatcher(v string) (*FastRegexMatcher, error) {
|
|||
// findSetMatches extract equality matches from a regexp.
|
||||
// Returns nil if we can't replace the regexp by only equality matchers.
|
||||
func findSetMatches(re *syntax.Regexp, base string) []string {
|
||||
// Matches are not case sensitive, if we find a case insensitive regexp.
|
||||
// Matches are case sensitive, if we find a case insensitive regexp.
|
||||
// We have to abort.
|
||||
if isCaseInsensitive(re) {
|
||||
return nil
|
||||
|
@ -69,25 +69,19 @@ func findSetMatches(re *syntax.Regexp, base string) []string {
|
|||
return []string{base}
|
||||
}
|
||||
case syntax.OpAlternate:
|
||||
found := findSetMatchesFromAlternate(re, base)
|
||||
if found != nil {
|
||||
return found
|
||||
}
|
||||
return findSetMatchesFromAlternate(re, base)
|
||||
case syntax.OpCapture:
|
||||
clearCapture(re)
|
||||
return findSetMatches(re, base)
|
||||
case syntax.OpConcat:
|
||||
found := findSetMatchesFromConcat(re, base)
|
||||
if found != nil {
|
||||
return found
|
||||
}
|
||||
return findSetMatchesFromConcat(re, base)
|
||||
case syntax.OpCharClass:
|
||||
if len(re.Rune) == 1 {
|
||||
return []string{base + string(re.Rune)}
|
||||
}
|
||||
var matches []string
|
||||
var totalSet int
|
||||
for i := 0; i < len(re.Rune); i = i + 2 {
|
||||
for i := 0; i+1 < len(re.Rune); i = i + 2 {
|
||||
totalSet += int(re.Rune[i+1]-re.Rune[i]) + 1
|
||||
}
|
||||
// limits the total characters that can be used to create matches.
|
||||
|
@ -96,7 +90,7 @@ func findSetMatches(re *syntax.Regexp, base string) []string {
|
|||
if totalSet > maxSetMatches {
|
||||
return nil
|
||||
}
|
||||
for i := 0; i < len(re.Rune); i = i + 2 {
|
||||
for i := 0; i+1 < len(re.Rune); i = i + 2 {
|
||||
lo, hi := re.Rune[i], re.Rune[i+1]
|
||||
for c := lo; c <= hi; c++ {
|
||||
matches = append(matches, base+string(c))
|
||||
|
|
Loading…
Reference in a new issue