Skip to content

Commit b291a05

Browse files
committed
perf: Speed up the wildcard function
Avoid unnecessary conversion to rune slice to alleviate the pressure on the heap allocator.
1 parent 613e417 commit b291a05

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

pkg/util/wildcard/wildcard.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,27 +27,27 @@ func Match(pattern, name string) (matched bool) {
2727
if pattern == "*" {
2828
return true
2929
}
30-
// Does extended wildcard '*' and '?' match.
31-
return deepMatchRune([]rune(name), []rune(pattern), false)
30+
// Does extended wildcard '*' and '?' match?
31+
return deepMatchRune(name, pattern, false)
3232
}
3333

34-
func deepMatchRune(str, pattern []rune, simple bool) bool {
34+
func deepMatchRune(s, pattern string, simple bool) bool {
3535
for len(pattern) > 0 {
3636
switch pattern[0] {
3737
default:
38-
if len(str) == 0 || str[0] != pattern[0] {
38+
if len(s) == 0 || s[0] != pattern[0] {
3939
return false
4040
}
4141
case '?':
42-
if len(str) == 0 && !simple {
42+
if len(s) == 0 && !simple {
4343
return false
4444
}
4545
case '*':
46-
return deepMatchRune(str, pattern[1:], simple) ||
47-
(len(str) > 0 && deepMatchRune(str[1:], pattern, simple))
46+
return deepMatchRune(s, pattern[1:], simple) ||
47+
(len(s) > 0 && deepMatchRune(s[1:], pattern, simple))
4848
}
49-
str = str[1:]
49+
s = s[1:]
5050
pattern = pattern[1:]
5151
}
52-
return len(str) == 0 && len(pattern) == 0
52+
return len(s) == 0 && len(pattern) == 0
5353
}

0 commit comments

Comments
 (0)