forked from mirror/glob
test for nil slice
This commit is contained in:
parent
9c0c7cba85
commit
99cf82455b
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
},
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue