From a9558ae24899923a21720d8b2c8c2580b825c1e6 Mon Sep 17 00:00:00 2001 From: Dzmitry Pasiukevich Date: Thu, 14 May 2020 18:20:13 +0300 Subject: [PATCH] Simplify cast of string to rune slice in wildcard matching (#9577) --- pkg/wildcard/match.go | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/pkg/wildcard/match.go b/pkg/wildcard/match.go index a26b2f2b7..358d21e04 100644 --- a/pkg/wildcard/match.go +++ b/pkg/wildcard/match.go @@ -26,16 +26,8 @@ func MatchSimple(pattern, name string) bool { if pattern == "*" { return true } - rname := make([]rune, 0, len(name)) - rpattern := make([]rune, 0, len(pattern)) - for _, r := range name { - rname = append(rname, r) - } - for _, r := range pattern { - rpattern = append(rpattern, r) - } - simple := true // Does only wildcard '*' match. - return deepMatchRune(rname, rpattern, simple) + // Does only wildcard '*' match. + return deepMatchRune([]rune(name), []rune(pattern), true) } // Match - finds whether the text matches/satisfies the pattern string. @@ -49,16 +41,8 @@ func Match(pattern, name string) (matched bool) { if pattern == "*" { return true } - rname := make([]rune, 0, len(name)) - rpattern := make([]rune, 0, len(pattern)) - for _, r := range name { - rname = append(rname, r) - } - for _, r := range pattern { - rpattern = append(rpattern, r) - } - simple := false // Does extended wildcard '*' and '?' match. - return deepMatchRune(rname, rpattern, simple) + // Does extended wildcard '*' and '?' match. + return deepMatchRune([]rune(name), []rune(pattern), false) } func deepMatchRune(str, pattern []rune, simple bool) bool {