From 3ed2ca3c4c4319f3f09de176b175145ac8b1b4d6 Mon Sep 17 00:00:00 2001 From: Marco Pracucci Date: Fri, 29 Sep 2023 15:14:37 +0200 Subject: [PATCH] Address offline feedback Signed-off-by: Marco Pracucci --- model/labels/regexp.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/model/labels/regexp.go b/model/labels/regexp.go index 7868967d98..420d35670a 100644 --- a/model/labels/regexp.go +++ b/model/labels/regexp.go @@ -528,20 +528,20 @@ func stringMatcherFromRegexpInternal(re *syntax.Regexp) StringMatcher { matches, matchesCaseSensitive := findSetMatchesInternal(re, "") - if len(matches) == 0 { + if len(matches) == 0 && len(re.Sub) == 2 { // We have not find fixed set matches. We look for other known cases that // we can optimize. switch { - // Literal as prefix. - case right == nil && len(re.Sub) == 2 && re.Sub[0].Op == syntax.OpLiteral: + // Prefix is literal. + case right == nil && re.Sub[0].Op == syntax.OpLiteral: right = stringMatcherFromRegexpInternal(re.Sub[1]) if right != nil { matches = []string{string(re.Sub[0].Rune)} matchesCaseSensitive = !isCaseInsensitive(re.Sub[0]) } - // Literal as suffix. - case left == nil && len(re.Sub) == 2 && re.Sub[1].Op == syntax.OpLiteral: + // Suffix is literal. + case left == nil && re.Sub[1].Op == syntax.OpLiteral: left = stringMatcherFromRegexpInternal(re.Sub[0]) if left != nil { matches = []string{string(re.Sub[1].Rune)}