diff --git a/glob.go b/glob.go index b534aec..bc3623e 100644 --- a/glob.go +++ b/glob.go @@ -6,17 +6,19 @@ import ( ) const ( - Any = "*" - SuperAny = "**" - SingleAny = "?" + any = "*" + superAny = "**" + singleAny = "?" ) -var Chars = []string{Any, SuperAny, SingleAny} +var chars = []string{any, superAny, singleAny} +// Glob represents compiled glob pattern. type Glob interface { Match(string) bool } +// New creates Glob for given pattern and uses other given (if any) strings as delimiters. func New(pattern string, d ...string) Glob { chunks := parse(pattern, nil, strings.Join(d, "")) @@ -32,7 +34,7 @@ func parse(p string, m []Glob, d string) []Glob { return m } - i, c := firstIndexOfChars(p, Chars) + i, c := firstIndexOfChars(p, chars) if i == -1 { return append(m, raw{p}) } @@ -42,11 +44,11 @@ func parse(p string, m []Glob, d string) []Glob { } switch c { - case SuperAny: + case superAny: m = append(m, multiple{}) - case Any: + case any: m = append(m, multiple{d}) - case SingleAny: + case singleAny: m = append(m, single{d}) } diff --git a/readme.md b/readme.md index 66e4ec2..d2e7786 100644 --- a/readme.md +++ b/readme.md @@ -52,7 +52,7 @@ func main() { ## Performance In comparison with [go-glob](https://github.com/ryanuber/go-glob), it is ~2.7x faster (on my personal Mac), -because my glob is compiling patterns for multiple usages. If you will not use compiled `glob.Glob` object, +because my impl compiles patterns for future usage. If you will not use compiled `glob.Glob` object, and do `g := glob.New(pattern); g.Match(...)` every time, then your code will be about ~3x slower. Run `go test bench=.` from source root to see the benchmarks: