Address offline feedback

Signed-off-by: Marco Pracucci <marco@pracucci.com>
This commit is contained in:
Marco Pracucci 2023-09-29 15:14:37 +02:00
parent 5ae9c194ce
commit 3ed2ca3c4c
No known key found for this signature in database
GPG key ID: 74C1BD403D2DF9B5

View file

@ -528,20 +528,20 @@ func stringMatcherFromRegexpInternal(re *syntax.Regexp) StringMatcher {
matches, matchesCaseSensitive := findSetMatchesInternal(re, "") 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 have not find fixed set matches. We look for other known cases that
// we can optimize. // we can optimize.
switch { switch {
// Literal as prefix. // Prefix is literal.
case right == nil && len(re.Sub) == 2 && re.Sub[0].Op == syntax.OpLiteral: case right == nil && re.Sub[0].Op == syntax.OpLiteral:
right = stringMatcherFromRegexpInternal(re.Sub[1]) right = stringMatcherFromRegexpInternal(re.Sub[1])
if right != nil { if right != nil {
matches = []string{string(re.Sub[0].Rune)} matches = []string{string(re.Sub[0].Rune)}
matchesCaseSensitive = !isCaseInsensitive(re.Sub[0]) matchesCaseSensitive = !isCaseInsensitive(re.Sub[0])
} }
// Literal as suffix. // Suffix is literal.
case left == nil && len(re.Sub) == 2 && re.Sub[1].Op == syntax.OpLiteral: case left == nil && re.Sub[1].Op == syntax.OpLiteral:
left = stringMatcherFromRegexpInternal(re.Sub[0]) left = stringMatcherFromRegexpInternal(re.Sub[0])
if left != nil { if left != nil {
matches = []string{string(re.Sub[1].Rune)} matches = []string{string(re.Sub[1].Rune)}