From 99cf82455be01dc1451eda2ec0b9ba861f9ae948 Mon Sep 17 00:00:00 2001 From: gobwas Date: Mon, 22 Feb 2016 19:43:52 +0300 Subject: [PATCH] test for nil slice --- match/any_of.go | 11 +++++++---- match/btree.go | 12 +++++++----- match/every_of.go | 25 +++++++++++++++---------- match/match.go | 2 +- 4 files changed, 30 insertions(+), 20 deletions(-) diff --git a/match/any_of.go b/match/any_of.go index af472da..fac9c99 100644 --- a/match/any_of.go +++ b/match/any_of.go @@ -27,10 +27,15 @@ func (self AnyOf) Index(s string, segments []int) (int, []int) { index := -1 // create reusable segments - seg := acquireSegments(len(s)) + // seg := acquireSegments(len(s)) + // defer func() { + // releaseSegments(seg) + // }() + var seg []int for _, m := range self.Matchers { - idx, seg := m.Index(s, seg[:0]) + var idx int + idx, seg = m.Index(s, seg[:0]) if idx == -1 { continue } @@ -49,8 +54,6 @@ func (self AnyOf) Index(s string, segments []int) (int, []int) { segments = appendMerge(segments, seg) } - releaseSegments(seg) - if index == -1 { return -1, nil } diff --git a/match/btree.go b/match/btree.go index d536987..5942371 100644 --- a/match/btree.go +++ b/match/btree.go @@ -83,14 +83,16 @@ 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) - }() + // segments := acquireSegments(inputLen) + // defer func() { + // releaseSegments(segments) + // }() + var segments []int for offset < limit { // search for matching part in substring - index, segments := self.Value.Index(s[offset:limit], segments[:0]) + var index int + index, segments = self.Value.Index(s[offset:limit], segments[:0]) if index == -1 { return false } diff --git a/match/every_of.go b/match/every_of.go index d833f15..ada1dd4 100644 --- a/match/every_of.go +++ b/match/every_of.go @@ -31,19 +31,24 @@ func (self EveryOf) Index(s string, out []int) (int, []int) { // make `in` with cap as len(s), // cause it is the maximum size of output segments values - seg := acquireSegments(len(s)) - next := acquireSegments(len(s)) - current := acquireSegments(len(s)) - - defer func() { - releaseSegments(seg) - releaseSegments(next) - releaseSegments(current) - }() + // seg := acquireSegments(len(s)) + // next := acquireSegments(len(s)) + // current := acquireSegments(len(s)) + // defer func() { + // releaseSegments(seg) + // releaseSegments(next) + // releaseSegments(current) + // }() + var ( + seg []int + next []int + current []int + ) sub := s for i, m := range self.Matchers { - idx, seg := m.Index(sub, seg[:0]) + var idx int + idx, seg = m.Index(sub, seg[:0]) if idx == -1 { return -1, nil } diff --git a/match/match.go b/match/match.go index 019fa79..1d3df20 100644 --- a/match/match.go +++ b/match/match.go @@ -54,7 +54,7 @@ func init() { func(i int) { segmentsPools[i-1] = sync.Pool{ New: func() interface{} { - fmt.Println("new", i) + // fmt.Println("new", i) return make([]int, 0, i) }, }