debug info

This commit is contained in:
gobwas 2016-02-02 22:34:10 +03:00
parent 61a66d485f
commit 6b71a60e74
3 changed files with 18 additions and 6 deletions

View File

@ -1,6 +1,8 @@
package glob package glob
import ( import (
"fmt"
"github.com/gobwas/glob/match"
"regexp" "regexp"
"testing" "testing"
) )
@ -150,6 +152,13 @@ func TestGlob(t *testing.T) {
} }
} }
func TestAllGlobMatch(t *testing.T) {
m, _ := Compile(pattern_all)
fmt.Println("HI", m.(match.Matcher).String())
m.Match(fixture_all_match)
}
func BenchmarkParseGlob(b *testing.B) { func BenchmarkParseGlob(b *testing.B) {
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
Compile(pattern_all) Compile(pattern_all)

View File

@ -77,10 +77,12 @@ func (self BTree) Match(s string) bool {
limit = inputLen limit = inputLen
} }
fmt.Println("ACQUIRE")
in := acquireSegments(inputLen)
for offset < limit { for offset < limit {
// search for matching part in substring // search for matching part in substring
in := acquireSegments(limit - offset) index, segments := self.Value.Index(s[offset:limit], in[:0])
index, segments := self.Value.Index(s[offset:limit], in)
if index == -1 { if index == -1 {
releaseSegments(in) releaseSegments(in)
return false return false
@ -120,12 +122,12 @@ func (self BTree) Match(s string) bool {
} }
} }
releaseSegments(in)
_, step := utf8.DecodeRuneInString(s[offset+index:]) _, step := utf8.DecodeRuneInString(s[offset+index:])
offset += index + step offset += index + step
} }
releaseSegments(in)
return false return false
} }

View File

@ -54,6 +54,7 @@ func init() {
func(i int) { func(i int) {
segmentsPools[i-1] = sync.Pool{ segmentsPools[i-1] = sync.Pool{
New: func() interface{} { New: func() interface{} {
fmt.Println("NEW", i)
return make([]int, 0, i) return make([]int, 0, i)
}, },
} }
@ -74,12 +75,12 @@ func getIdx(c int) int {
} }
func acquireSegments(c int) []int { func acquireSegments(c int) []int {
// fmt.Println("GET", getIdx(c)) fmt.Println("GET", getIdx(c))
return segmentsPools[getIdx(c)].Get().([]int)[:0] return segmentsPools[getIdx(c)].Get().([]int)[:0]
} }
func releaseSegments(s []int) { func releaseSegments(s []int) {
// fmt.Println("PUT", getIdx(cap(s))) fmt.Println("PUT", getIdx(cap(s)))
segmentsPools[getIdx(cap(s))].Put(s) segmentsPools[getIdx(cap(s))].Put(s)
} }