This commit is contained in:
gobwas 2016-02-22 23:34:16 +03:00
parent ea3a6f712d
commit 88b0fce4f5
5 changed files with 12 additions and 12 deletions

View File

@ -83,15 +83,15 @@ 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)
}()
// segments := make([]int, 0, 4)
for offset < limit {
// search for matching part in substring
index, segments := self.Value.Index(s[offset:limit], nil)
index, segments := self.Value.Index(s[offset:limit], segments[:0])
if index == -1 {
return false
}

View File

@ -35,7 +35,7 @@ func (self Range) Index(s string, segments []int) (int, []int) {
}
}
return -1, nil
return -1, segments
}
func (self Range) String() string {

View File

@ -54,7 +54,7 @@ func (self Row) Len() (l int) {
func (self Row) Index(s string, segments []int) (int, []int) {
if !self.lenOk(s) {
return -1, nil
return -1, segments
}
for i := range s {
@ -70,7 +70,7 @@ func (self Row) Index(s string, segments []int) (int, []int) {
}
}
return -1, nil
return -1, segments
}
func (self Row) String() string {

View File

@ -20,8 +20,8 @@ func toPowerOfTwo(v int) int {
}
const (
minSegment = 32
minSegmentMinusOne = 31
minSegment = 4
minSegmentMinusOne = 3
maxSegment = 1024
maxSegmentMinusOne = 1023
)

View File

@ -32,7 +32,7 @@ func (self Text) Len() int {
func (self Text) Index(s string, segments []int) (int, []int) {
index := strings.Index(s, self.Str)
if index == -1 {
return -1, nil
return -1, segments
}
return index, append(segments, self.BytesLength)