mirror of
https://github.com/prometheus/prometheus.git
synced 2026-06-08 16:12:16 -04:00
[REFACTOR] FastRegexp: simplify optimizeAlternatingLiterals
Use `strings.SplitSeq` to step through alternates. Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
This commit is contained in:
parent
f0f40b970d
commit
06c135a5e1
1 changed files with 1 additions and 11 deletions
|
|
@ -347,11 +347,7 @@ func optimizeAlternatingLiterals(s string) (StringMatcher, []string) {
|
|||
|
||||
multiMatcher := newEqualMultiStringMatcher(true, estimatedAlternates, 0, 0)
|
||||
|
||||
for end := strings.IndexByte(s, '|'); end > -1; end = strings.IndexByte(s, '|') {
|
||||
// Split the string into the next literal and the remainder
|
||||
subMatch := s[:end]
|
||||
s = s[end+1:]
|
||||
|
||||
for subMatch := range strings.SplitSeq(s, "|") {
|
||||
// break if any of the submatches are not literals
|
||||
if regexp.QuoteMeta(subMatch) != subMatch {
|
||||
return nil, nil
|
||||
|
|
@ -360,12 +356,6 @@ func optimizeAlternatingLiterals(s string) (StringMatcher, []string) {
|
|||
multiMatcher.add(subMatch)
|
||||
}
|
||||
|
||||
// break if the remainder is not a literal
|
||||
if regexp.QuoteMeta(s) != s {
|
||||
return nil, nil
|
||||
}
|
||||
multiMatcher.add(s)
|
||||
|
||||
return multiMatcher, multiMatcher.setMatches()
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue