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
|
index := -1
|
||||||
|
|
||||||
// create reusable segments
|
// create reusable segments
|
||||||
seg := acquireSegments(len(s))
|
// seg := acquireSegments(len(s))
|
||||||
|
// defer func() {
|
||||||
|
// releaseSegments(seg)
|
||||||
|
// }()
|
||||||
|
var seg []int
|
||||||
|
|
||||||
for _, m := range self.Matchers {
|
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 {
|
if idx == -1 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -49,8 +54,6 @@ func (self AnyOf) Index(s string, segments []int) (int, []int) {
|
||||||
segments = appendMerge(segments, seg)
|
segments = appendMerge(segments, seg)
|
||||||
}
|
}
|
||||||
|
|
||||||
releaseSegments(seg)
|
|
||||||
|
|
||||||
if index == -1 {
|
if index == -1 {
|
||||||
return -1, nil
|
return -1, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,14 +83,16 @@ 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
|
||||||
|
|
||||||
for offset < limit {
|
for offset < limit {
|
||||||
// search for matching part in substring
|
// 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 {
|
if index == -1 {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,19 +31,24 @@ func (self EveryOf) Index(s string, out []int) (int, []int) {
|
||||||
|
|
||||||
// make `in` with cap as len(s),
|
// make `in` with cap as len(s),
|
||||||
// cause it is the maximum size of output segments values
|
// cause it is the maximum size of output segments values
|
||||||
seg := acquireSegments(len(s))
|
// seg := acquireSegments(len(s))
|
||||||
next := acquireSegments(len(s))
|
// next := acquireSegments(len(s))
|
||||||
current := acquireSegments(len(s))
|
// current := acquireSegments(len(s))
|
||||||
|
// defer func() {
|
||||||
defer func() {
|
// releaseSegments(seg)
|
||||||
releaseSegments(seg)
|
// releaseSegments(next)
|
||||||
releaseSegments(next)
|
// releaseSegments(current)
|
||||||
releaseSegments(current)
|
// }()
|
||||||
}()
|
var (
|
||||||
|
seg []int
|
||||||
|
next []int
|
||||||
|
current []int
|
||||||
|
)
|
||||||
|
|
||||||
sub := s
|
sub := s
|
||||||
for i, m := range self.Matchers {
|
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 {
|
if idx == -1 {
|
||||||
return -1, nil
|
return -1, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,7 +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)
|
// fmt.Println("new", i)
|
||||||
return make([]int, 0, i)
|
return make([]int, 0, i)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue