mirror of https://github.com/gobwas/glob.git
progress
This commit is contained in:
parent
51a65fcc7d
commit
88fcc08f39
14
compiler.go
14
compiler.go
|
@ -11,7 +11,7 @@ func optimize(matcher match.Matcher) match.Matcher {
|
||||||
switch m := matcher.(type) {
|
switch m := matcher.(type) {
|
||||||
|
|
||||||
case match.Any:
|
case match.Any:
|
||||||
if m.Separators == "" {
|
if len(m.Separators) == 0 {
|
||||||
return match.Super{}
|
return match.Super{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,15 +135,15 @@ func glueAsEvery(matchers []match.Matcher) match.Matcher {
|
||||||
hasSuper bool
|
hasSuper bool
|
||||||
hasSingle bool
|
hasSingle bool
|
||||||
min int
|
min int
|
||||||
separator string
|
separator []rune
|
||||||
)
|
)
|
||||||
|
|
||||||
for i, matcher := range matchers {
|
for i, matcher := range matchers {
|
||||||
var sep string
|
var sep []rune
|
||||||
switch m := matcher.(type) {
|
|
||||||
|
|
||||||
|
switch m := matcher.(type) {
|
||||||
case match.Super:
|
case match.Super:
|
||||||
sep = ""
|
sep = []rune{}
|
||||||
hasSuper = true
|
hasSuper = true
|
||||||
|
|
||||||
case match.Any:
|
case match.Any:
|
||||||
|
@ -486,7 +486,7 @@ func doAnyOf(n *nodeAnyOf, s string) (match.Matcher, error) {
|
||||||
return match.AnyOf{matchers}, nil
|
return match.AnyOf{matchers}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func do(leaf node, s string) (m match.Matcher, err error) {
|
func do(leaf node, s []rune) (m match.Matcher, err error) {
|
||||||
switch n := leaf.(type) {
|
switch n := leaf.(type) {
|
||||||
|
|
||||||
case *nodeAnyOf:
|
case *nodeAnyOf:
|
||||||
|
@ -659,7 +659,7 @@ func do2(node node, s string) ([]match.Matcher, error) {
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func compile(ast *nodePattern, s string) (Glob, error) {
|
func compile(ast *nodePattern, s []rune) (Glob, error) {
|
||||||
// ms, err := do2(ast, s)
|
// ms, err := do2(ast, s)
|
||||||
// if err != nil {
|
// if err != nil {
|
||||||
// return nil, err
|
// return nil, err
|
||||||
|
|
4
glob.go
4
glob.go
|
@ -33,13 +33,13 @@ type Glob interface {
|
||||||
// pattern { `,` pattern }
|
// pattern { `,` pattern }
|
||||||
// comma-separated (without spaces) patterns
|
// comma-separated (without spaces) patterns
|
||||||
//
|
//
|
||||||
func Compile(pattern string, separators ...string) (Glob, error) {
|
func Compile(pattern string, separators ...rune) (Glob, error) {
|
||||||
ast, err := parse(newLexer(pattern))
|
ast, err := parse(newLexer(pattern))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
matcher, err := compile(ast, strings.Join(separators, ""))
|
matcher, err := compile(ast, separators)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type Any struct {
|
type Any struct {
|
||||||
Separators string
|
Separators []rune
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self Any) Match(s string) bool {
|
func (self Any) Match(s string) bool {
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
|
|
||||||
// single represents ?
|
// single represents ?
|
||||||
type Single struct {
|
type Single struct {
|
||||||
Separators string
|
Separators []rune
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self Single) Match(s string) bool {
|
func (self Single) Match(s string) bool {
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
benchmark | old ns/op | new ns/op | delta
|
||||||
|
-----------------------------------------------|-----------|-------------|-----------
|
||||||
|
BenchmarkAllGlobMatch-4 512 711 +38.87%
|
||||||
|
BenchmarkMultipleGlobMatch-4 121 417 +244.63%
|
||||||
|
BenchmarkAlternativesGlobMatch-4 166 300 +80.72%
|
||||||
|
BenchmarkAlternativesSuffixFirstGlobMatch-4 23.5 292 +1142.55%
|
||||||
|
BenchmarkAlternativesSuffixSecondGlobMatch-4 29.8 355 +1091.28%
|
||||||
|
BenchmarkAlternativesCombineLiteGlobMatch-4 161 250 +55.28%
|
||||||
|
BenchmarkAlternativesCombineHardGlobMatch-4 325 334 +2.77%
|
||||||
|
BenchmarkPlainGlobMatch-4 7.20 154 +2038.89%
|
||||||
|
BenchmarkPrefixGlobMatch-4 8.75 113 +1191.43%
|
||||||
|
BenchmarkSuffixGlobMatch-4 9.07 115 +1167.92%
|
||||||
|
BenchmarkPrefixSuffixGlobMatch-4 15.1 125 +727.81%
|
||||||
|
BenchmarkIndexAny-4 887 255 -71.25%
|
||||||
|
BenchmarkIndexContains-4 492 247 -49.80%
|
||||||
|
BenchmarkIndexList-4 151 51.1 -66.16%
|
||||||
|
BenchmarkIndexMax-4 442 92.4 -79.10%
|
||||||
|
BenchmarkIndexMin-4 516 161 -68.80%
|
||||||
|
BenchmarkIndexNothing-4 452 92.8 -79.47%
|
||||||
|
BenchmarkIndexPrefixSuffix-4 84.3 57.2 -32.15%
|
||||||
|
BenchmarkIndexPrefix-4 85.1 55.9 -34.31%
|
||||||
|
BenchmarkIndexRange-4 170 60.6 -64.35%
|
||||||
|
BenchmarkRowIndex-4 172 94.0 -45.35%
|
||||||
|
BenchmarkIndexSingle-4 61.0 35.8 -41.31%
|
||||||
|
BenchmarkIndexSuffix-4 84.8 55.7 -34.32%
|
||||||
|
BenchmarkIndexSuper-4 461 192 -58.35%
|
||||||
|
BenchmarkIndexText-4 84.6 54.4 -35.70%
|
Loading…
Reference in New Issue