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.
|
// 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".
|
// 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 {
|
func (m *Matcher) SetMatches() []string {
|
||||||
if m.re == nil {
|
if m.re == nil {
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -56,7 +56,7 @@ func NewFastRegexMatcher(v string) (*FastRegexMatcher, error) {
|
||||||
// findSetMatches extract equality matches from a regexp.
|
// findSetMatches extract equality matches from a regexp.
|
||||||
// Returns nil if we can't replace the regexp by only equality matchers.
|
// Returns nil if we can't replace the regexp by only equality matchers.
|
||||||
func findSetMatches(re *syntax.Regexp, base string) []string {
|
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.
|
// We have to abort.
|
||||||
if isCaseInsensitive(re) {
|
if isCaseInsensitive(re) {
|
||||||
return nil
|
return nil
|
||||||
|
@ -69,25 +69,19 @@ func findSetMatches(re *syntax.Regexp, base string) []string {
|
||||||
return []string{base}
|
return []string{base}
|
||||||
}
|
}
|
||||||
case syntax.OpAlternate:
|
case syntax.OpAlternate:
|
||||||
found := findSetMatchesFromAlternate(re, base)
|
return findSetMatchesFromAlternate(re, base)
|
||||||
if found != nil {
|
|
||||||
return found
|
|
||||||
}
|
|
||||||
case syntax.OpCapture:
|
case syntax.OpCapture:
|
||||||
clearCapture(re)
|
clearCapture(re)
|
||||||
return findSetMatches(re, base)
|
return findSetMatches(re, base)
|
||||||
case syntax.OpConcat:
|
case syntax.OpConcat:
|
||||||
found := findSetMatchesFromConcat(re, base)
|
return findSetMatchesFromConcat(re, base)
|
||||||
if found != nil {
|
|
||||||
return found
|
|
||||||
}
|
|
||||||
case syntax.OpCharClass:
|
case syntax.OpCharClass:
|
||||||
if len(re.Rune) == 1 {
|
if len(re.Rune) == 1 {
|
||||||
return []string{base + string(re.Rune)}
|
return []string{base + string(re.Rune)}
|
||||||
}
|
}
|
||||||
var matches []string
|
var matches []string
|
||||||
var totalSet int
|
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
|
totalSet += int(re.Rune[i+1]-re.Rune[i]) + 1
|
||||||
}
|
}
|
||||||
// limits the total characters that can be used to create matches.
|
// 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 {
|
if totalSet > maxSetMatches {
|
||||||
return nil
|
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]
|
lo, hi := re.Rune[i], re.Rune[i+1]
|
||||||
for c := lo; c <= hi; c++ {
|
for c := lo; c <= hi; c++ {
|
||||||
matches = append(matches, base+string(c))
|
matches = append(matches, base+string(c))
|
||||||
|
|
Loading…
Reference in a new issue