From 88fcc08f394959ea87ed94a990e8420294220b03 Mon Sep 17 00:00:00 2001 From: gobwas Date: Tue, 2 Feb 2016 14:57:42 +0300 Subject: [PATCH] progress --- compiler.go | 14 +++++++------- glob.go | 4 ++-- match/any.go | 2 +- match/single.go | 2 +- todo.txt | 27 +++++++++++++++++++++++++++ 5 files changed, 38 insertions(+), 11 deletions(-) create mode 100644 todo.txt diff --git a/compiler.go b/compiler.go index 0a38c8e..d7bcd8d 100644 --- a/compiler.go +++ b/compiler.go @@ -11,7 +11,7 @@ func optimize(matcher match.Matcher) match.Matcher { switch m := matcher.(type) { case match.Any: - if m.Separators == "" { + if len(m.Separators) == 0 { return match.Super{} } @@ -135,15 +135,15 @@ func glueAsEvery(matchers []match.Matcher) match.Matcher { hasSuper bool hasSingle bool min int - separator string + separator []rune ) for i, matcher := range matchers { - var sep string - switch m := matcher.(type) { + var sep []rune + switch m := matcher.(type) { case match.Super: - sep = "" + sep = []rune{} hasSuper = true case match.Any: @@ -486,7 +486,7 @@ func doAnyOf(n *nodeAnyOf, s string) (match.Matcher, error) { 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) { case *nodeAnyOf: @@ -659,7 +659,7 @@ func do2(node node, s string) ([]match.Matcher, error) { return result, nil } -func compile(ast *nodePattern, s string) (Glob, error) { +func compile(ast *nodePattern, s []rune) (Glob, error) { // ms, err := do2(ast, s) // if err != nil { // return nil, err diff --git a/glob.go b/glob.go index 8b97961..dee2ef6 100644 --- a/glob.go +++ b/glob.go @@ -33,13 +33,13 @@ type Glob interface { // pattern { `,` pattern } // 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)) if err != nil { return nil, err } - matcher, err := compile(ast, strings.Join(separators, "")) + matcher, err := compile(ast, separators) if err != nil { return nil, err } diff --git a/match/any.go b/match/any.go index 6470c62..b00db7e 100644 --- a/match/any.go +++ b/match/any.go @@ -7,7 +7,7 @@ import ( ) type Any struct { - Separators string + Separators []rune } func (self Any) Match(s string) bool { diff --git a/match/single.go b/match/single.go index 5ad3391..f9cf018 100644 --- a/match/single.go +++ b/match/single.go @@ -8,7 +8,7 @@ import ( // single represents ? type Single struct { - Separators string + Separators []rune } func (self Single) Match(s string) bool { diff --git a/todo.txt b/todo.txt new file mode 100644 index 0000000..02bfc16 --- /dev/null +++ b/todo.txt @@ -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%