summaryrefslogtreecommitdiffstats
path: root/src/pattern.go
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2017-07-18 03:10:49 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2017-07-18 03:14:33 +0900
commitbbe10f4f7745000c121b629ff68e81bba5a497f6 (patch)
treef166d6e6d649763db438407ddc7a749d237df11e /src/pattern.go
parent5e72709613b816531c1e0aed6a710257e08bb5d8 (diff)
Consolidate Result and rank structs
By not storing item index twice, we can cut down the size of Result struct and now it makes more sense to store and pass Results by values. Benchmarks show no degradation of performance by additional pointer indirection for looking up index.
Diffstat (limited to 'src/pattern.go')
-rw-r--r--src/pattern.go16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/pattern.go b/src/pattern.go
index 07ed9cd8..97ee8fd6 100644
--- a/src/pattern.go
+++ b/src/pattern.go
@@ -243,7 +243,7 @@ func (p *Pattern) CacheKey() string {
}
// Match returns the list of matches Items in the given Chunk
-func (p *Pattern) Match(chunk *Chunk, slab *util.Slab) []*Result {
+func (p *Pattern) Match(chunk *Chunk, slab *util.Slab) []Result {
// ChunkCache: Exact match
cacheKey := p.CacheKey()
if p.cacheable {
@@ -263,19 +263,19 @@ func (p *Pattern) Match(chunk *Chunk, slab *util.Slab) []*Result {
return matches
}
-func (p *Pattern) matchChunk(chunk *Chunk, space []*Result, slab *util.Slab) []*Result {
- matches := []*Result{}
+func (p *Pattern) matchChunk(chunk *Chunk, space []Result, slab *util.Slab) []Result {
+ matches := []Result{}
if space == nil {
for idx := range *chunk {
if match, _, _ := p.MatchItem(&(*chunk)[idx], false, slab); match != nil {
- matches = append(matches, match)
+ matches = append(matches, *match)
}
}
} else {
for _, result := range space {
if match, _, _ := p.MatchItem(result.item, false, slab); match != nil {
- matches = append(matches, match)
+ matches = append(matches, *match)
}
}
}
@@ -286,14 +286,16 @@ func (p *Pattern) matchChunk(chunk *Chunk, space []*Result, slab *util.Slab) []*
func (p *Pattern) MatchItem(item *Item, withPos bool, slab *util.Slab) (*Result, []Offset, *[]int) {
if p.extended {
if offsets, bonus, pos := p.extendedMatch(item, withPos, slab); len(offsets) == len(p.termSets) {
- return buildResult(item, offsets, bonus), offsets, pos
+ result := buildResult(item, offsets, bonus)
+ return &result, offsets, pos
}
return nil, nil, nil
}
offset, bonus, pos := p.basicMatch(item, withPos, slab)
if sidx := offset[0]; sidx >= 0 {
offsets := []Offset{offset}
- return buildResult(item, offsets, bonus), offsets, pos
+ result := buildResult(item, offsets, bonus)
+ return &result, offsets, pos
}
return nil, nil, nil
}