[REFACTOR] FastRegexp: simplify optimizeAlternatingLiterals

Use `strings.SplitSeq` to step through alternates.

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
This commit is contained in:
Bryan Boreham 2026-02-04 20:41:16 +00:00
parent f0f40b970d
commit 06c135a5e1

View file

@ -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()
}