From 06c135a5e1a61fcbf8f2d5320aa3e1bc5f3f3c29 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Wed, 4 Feb 2026 20:41:16 +0000 Subject: [PATCH] [REFACTOR] FastRegexp: simplify optimizeAlternatingLiterals Use `strings.SplitSeq` to step through alternates. Signed-off-by: Bryan Boreham --- model/labels/regexp.go | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/model/labels/regexp.go b/model/labels/regexp.go index 5f4f753419..5a8af8e514 100644 --- a/model/labels/regexp.go +++ b/model/labels/regexp.go @@ -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() }