feat(wildcard): fast-path some cases (#1747)

* feat(wildcard): fast-path some cases
This commit is contained in:
Kyle Sanderson 2024-10-06 05:29:18 -07:00 committed by GitHub
parent 737184a985
commit caccaf3e09
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 64 additions and 2 deletions

View file

@ -52,11 +52,26 @@ func TestMatch(t *testing.T) {
text: "tv",
matched: true,
},
{
pattern: "t?",
text: "tv",
matched: true,
},
{
pattern: "?",
text: "z",
matched: true,
},
{
pattern: "*EPUB*",
text: "Translated (Group) / EPUB",
matched: true,
},
{
pattern: "*EP?B*",
text: "Translated (Group) / EPUB",
matched: true,
},
{
pattern: "*shift*",
text: "Good show shift S02 2160p ATVP WEB-DL DDP 5.1 Atmos DV HEVC-GROUP",
@ -110,6 +125,8 @@ func TestMatchSimple(t *testing.T) {
{"t?st", "test", false},
{"t?st", "tast", false},
{"test", "test", true},
{"*te?t*", "test", false},
{"*test*", "test", true},
{"test", "toast", false},
{"", "non-empty", false},
{"*", "", true},
@ -160,6 +177,7 @@ func TestMatchSlice(t *testing.T) {
}{
{[]string{"*", "test", "t?st"}, "test", true},
{[]string{"te?t", "t?st", "random"}, "tost", true},
{[]string{"te?t", "t??e?", "random"}, "toser", true},
{[]string{"*st", "n?st", "l*st"}, "list", true},
{[]string{"?", "??", "???"}, "t", true},
{[]string{"a", "b", "c"}, "d", false},
@ -190,3 +208,11 @@ func TestMatchSlice(t *testing.T) {
}
}
}
func Benchmark_Regex(b *testing.B) {
for i := 0; i < b.N; i++ {
b.StartTimer()
TestMatchSlice(nil)
b.StopTimer()
}
}