diff --git a/match/btree.go b/match/btree.go index 5942371..74f3412 100644 --- a/match/btree.go +++ b/match/btree.go @@ -83,11 +83,11 @@ func (self BTree) Match(s string) bool { // reusable segments list // inputLen is the maximum size of output segments values - // segments := acquireSegments(inputLen) - // defer func() { - // releaseSegments(segments) - // }() - var segments []int + segments := acquireSegments(inputLen) + defer func() { + releaseSegments(segments) + }() + // var segments []int for offset < limit { // search for matching part in substring diff --git a/match/btree_test.go b/match/btree_test.go index 44831ca..fc68de1 100644 --- a/match/btree_test.go +++ b/match/btree_test.go @@ -63,7 +63,7 @@ func (f *fakeMatcher) Match(string) bool { return true } func (f *fakeMatcher) Index(s string, seg []int) (int, []int) { - return 0, seg + return 0, append(seg, 1) } func (f *fakeMatcher) Len() int { return f.len @@ -78,7 +78,7 @@ func BenchmarkMatchBTree(b *testing.B) { v := &fakeMatcher{2, "value_fake"} // must be <= len(l + r + v) - fixture := "abcdefghij" + fixture := "abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij" bt := NewBTree(v, l, r) diff --git a/match/match.go b/match/match.go index 1d3df20..20521c5 100644 --- a/match/match.go +++ b/match/match.go @@ -52,12 +52,18 @@ const ( func init() { for i := maxSegment; i >= minSegment; i >>= 1 { func(i int) { - segmentsPools[i-1] = sync.Pool{ + pool := sync.Pool{ New: func() interface{} { - // fmt.Println("new", i) + // fmt.Printf("N%d;", i) return make([]int, 0, i) }, } + + // for n := 0; n < 4; n++ { + // pool.Put(make([]int, 0, i)) + // } + + segmentsPools[i-1] = pool }(i) } } @@ -74,13 +80,17 @@ func getIdx(c int) int { } } +//var p = make([]int, 0, 128) + func acquireSegments(c int) []int { - // fmt.Println("acquire", c) + // return p + // fmt.Printf("a%d;", getIdx(c)) return segmentsPools[getIdx(c)].Get().([]int)[:0] } func releaseSegments(s []int) { - // fmt.Println("release", len(s)) + // p = s + // fmt.Printf("r%d;", getIdx(cap(s))) segmentsPools[getIdx(cap(s))].Put(s) }