forked from mirror/glob
prog
This commit is contained in:
parent
99cf82455b
commit
325689ef4a
|
@ -83,11 +83,11 @@ func (self BTree) Match(s string) bool {
|
||||||
|
|
||||||
// reusable segments list
|
// reusable segments list
|
||||||
// inputLen is the maximum size of output segments values
|
// inputLen is the maximum size of output segments values
|
||||||
// segments := acquireSegments(inputLen)
|
segments := acquireSegments(inputLen)
|
||||||
// defer func() {
|
defer func() {
|
||||||
// releaseSegments(segments)
|
releaseSegments(segments)
|
||||||
// }()
|
}()
|
||||||
var segments []int
|
// var segments []int
|
||||||
|
|
||||||
for offset < limit {
|
for offset < limit {
|
||||||
// search for matching part in substring
|
// search for matching part in substring
|
||||||
|
|
|
@ -63,7 +63,7 @@ func (f *fakeMatcher) Match(string) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
func (f *fakeMatcher) Index(s string, seg []int) (int, []int) {
|
func (f *fakeMatcher) Index(s string, seg []int) (int, []int) {
|
||||||
return 0, seg
|
return 0, append(seg, 1)
|
||||||
}
|
}
|
||||||
func (f *fakeMatcher) Len() int {
|
func (f *fakeMatcher) Len() int {
|
||||||
return f.len
|
return f.len
|
||||||
|
@ -78,7 +78,7 @@ func BenchmarkMatchBTree(b *testing.B) {
|
||||||
v := &fakeMatcher{2, "value_fake"}
|
v := &fakeMatcher{2, "value_fake"}
|
||||||
|
|
||||||
// must be <= len(l + r + v)
|
// must be <= len(l + r + v)
|
||||||
fixture := "abcdefghij"
|
fixture := "abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij"
|
||||||
|
|
||||||
bt := NewBTree(v, l, r)
|
bt := NewBTree(v, l, r)
|
||||||
|
|
||||||
|
|
|
@ -52,12 +52,18 @@ const (
|
||||||
func init() {
|
func init() {
|
||||||
for i := maxSegment; i >= minSegment; i >>= 1 {
|
for i := maxSegment; i >= minSegment; i >>= 1 {
|
||||||
func(i int) {
|
func(i int) {
|
||||||
segmentsPools[i-1] = sync.Pool{
|
pool := sync.Pool{
|
||||||
New: func() interface{} {
|
New: func() interface{} {
|
||||||
// fmt.Println("new", i)
|
// fmt.Printf("N%d;", i)
|
||||||
return make([]int, 0, i)
|
return make([]int, 0, i)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// for n := 0; n < 4; n++ {
|
||||||
|
// pool.Put(make([]int, 0, i))
|
||||||
|
// }
|
||||||
|
|
||||||
|
segmentsPools[i-1] = pool
|
||||||
}(i)
|
}(i)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -74,13 +80,17 @@ func getIdx(c int) int {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//var p = make([]int, 0, 128)
|
||||||
|
|
||||||
func acquireSegments(c int) []int {
|
func acquireSegments(c int) []int {
|
||||||
// fmt.Println("acquire", c)
|
// return p
|
||||||
|
// fmt.Printf("a%d;", 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("release", len(s))
|
// p = s
|
||||||
|
// fmt.Printf("r%d;", getIdx(cap(s)))
|
||||||
segmentsPools[getIdx(cap(s))].Put(s)
|
segmentsPools[getIdx(cap(s))].Put(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue