Skip to content

Commit a920600

Browse files
authored
fix/search: measure regexp literals in runes (#1149)
The trigram optimizer operates on rune trigrams, but its eligibility check measured UTF-8 bytes. This sent short non-ASCII literals through an inconsistent planning path and could produce surprising composite trees. Use the parsed rune count so the optimizer and substring planner apply the same threshold.
1 parent c4a225a commit a920600

2 files changed

Lines changed: 4 additions & 1 deletion

File tree

index/eval.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ func (d *indexData) regexpToMatchTreeRecursive(r *syntax.Regexp, minTextSize int
625625
switch r.Op {
626626
case syntax.OpLiteral:
627627
s := string(r.Rune)
628-
if len(s) >= minTextSize {
628+
if len(r.Rune) >= minTextSize {
629629
ignoreCase := syntax.FoldCase == (r.Flags & syntax.FoldCase)
630630
mt, err := d.newSubstringMatchTree(&query.Substring{Pattern: s, FileName: fileName, CaseSensitive: !ignoreCase && caseSensitive})
631631
return mt, true, !strings.Contains(s, "\n"), err

index/eval_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ func TestRegexpParse(t *testing.T) {
9090
cases := []testcase{
9191
{"(foo|)bar", substrMT("bar"), false, false},
9292
{"(foo|)", &bruteForceMatchTree{}, false, false},
93+
{"éa", &bruteForceMatchTree{}, false, false},
94+
{"éab", substrMT("éab"), true, false},
95+
{"(éa|êb)", &bruteForceMatchTree{}, false, false},
9396
{"(foo|bar)baz.*bla", &andMatchTree{[]matchTree{
9497
&orMatchTree{[]matchTree{
9598
substrMT("foo"),

0 commit comments

Comments
 (0)